Socket
Socket
Sign inDemoInstall

country-data

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-data - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

4

CHANGES.md
# Changes
## v0.0.3
* got rid of the `countries.alpha2.` style accessors.
## v0.0.2

@@ -4,0 +8,0 @@

24

index.js

@@ -1,26 +0,20 @@

var data_countries = require('./data/countries.json'),
data_currencies = require('./data/currencies.json'),
var countriesAll = require('./data/countries.json'),
currenciesAll = require('./data/currencies.json'),
_ = require('underscore');
exports.data = {
countries: data_countries,
currencies: data_currencies,
};
exports.countries = {
alpha2: {},
alpha3: {},
all: countriesAll,
};
_.each(data_countries, function (country) {
exports.countries.alpha2[country.alpha2] = country;
exports.countries.alpha3[country.alpha3] = country;
_.each(countriesAll, function (country) {
exports.countries[country.alpha2] = country;
exports.countries[country.alpha3] = country;
});
exports.currencies = {
code: {},
all: currenciesAll,
};
_.each(data_currencies, function (currency) {
exports.currencies.code[currency.code] = currency;
_.each(currenciesAll, function (currency) {
exports.currencies[currency.code] = currency;
});
{
"name": "country-data",
"version": "0.0.2",
"version": "0.0.3",
"description": "Data about countries - like their ISO codes and currencies",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/LinkToBooks/country-data",

@@ -8,2 +8,9 @@ # Country Data

## Work in Progress
This code base may change a bit until it hits `0.1.x` - feel free to use it, but be sure to check between upgrades.
I suspect that many of the `currencies` entries on the countries may be wrong. Help checking them would be appreciated.
## Countries

@@ -18,2 +25,3 @@

## Currencies

@@ -23,6 +31,6 @@

* `name` The english name for the currency
* `code` The [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) code
* `number` The [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) number
* `decimals` The number of decimal digits conventionally shown
* `name` The english name for the currency
* `code` The [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) code
* `number` The [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) number
* `decimals` The number of decimal digits conventionally shown

@@ -43,8 +51,12 @@

// countries are found using alpha2 or alpha3
console.log( countries.alpha2.BE.name ); // 'Belgium'
console.log( countries.alpha3.FRA.currencies ); // ['EUR']
// .all gives you an array of all entries
console.log( countries.all );
console.log( currencies.all );
// currencies are accessed by their code
console.log( currencies.code.USD.name ); // 'United States dollar'
// countries are found using alpha2 or alpha3 (both uppercase)
console.log( countries.BE.name ); // 'Belgium'
console.log( countries.FRA.currencies ); // ['EUR']
// currencies are accessed by their code (uppercase)
console.log( currencies.USD.name ); // 'United States dollar'
```

@@ -55,3 +67,3 @@

## Adding data
## Possible future additions

@@ -61,14 +73,24 @@ More data for each country is most welcome. Obvious things that it might be nice

### Countries
* Top level domains
* Wikipedia links
* Coordinates (centroid, bounding box, etc)
* International dialing codes
* International dialling codes
* Languages spoken - most common first
### Currencies
The data is finally stored as JSON, but this is not always easy to manipulate.
For this it is easier to edit the CSV files (using spreadsheet software) and
then use the scripts in the data directory to convert the CSV to JSON. Please
don't edit the JSON directly, but do it via the CSV.
* currency symbols
* other currency that it is [pegged](http://en.wikipedia.org/wiki/Fixed_exchange_rate) to
These are the steps required
## How to contribute
The final format is JSON, but it is easier to work with CSV. Hence in the `data`
folder there are CSV files and scripts that convert them to JSON. Please don't
edit the JSON directly, but do it via the CSV.
These are the steps required:
``` bash

@@ -86,3 +108,4 @@ # Clone the repo (or better your fork of it)

# Convert the CSV to JSON
node data/country_csv_to_json.js > data/countries.json
node data/country_csv_to_json.js > data/countries.json
node data/currency_csv_to_json.js > data/currencies.json

@@ -97,7 +120,9 @@ # Run the tests

# Then send a pull request with your changes
# Then send a pull request with your changes. Ideally use several small commits,
# and reference a source that backs up the change.
```
## Sources
The currency data was copied from the [Wikipedia ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) page.
var countries = require('..').countries,
currencies = require('..').currencies,
countryData = require('..').data.countries,
assert = require('assert'),

@@ -9,6 +8,12 @@ _ = require('underscore');

describe('all', function () {
it('should be array', function () {
assert( _.isArray(countries.all) );
});
});
describe('alpha2', function () {
it('should find USA', function () {
assert.equal( countries.alpha2.BE.name, 'Belgium');
assert.equal( countries.alpha2.US.name, 'United States');
assert.equal( countries.BE.name, 'Belgium');
assert.equal( countries.US.name, 'United States');
});

@@ -19,4 +24,4 @@ });

it('should find France', function () {
assert.equal( countries.alpha3.FRA.name, 'France');
assert.deepEqual( countries.alpha3.FRA.currencies, ['EUR']);
assert.equal( countries.FRA.name, 'France');
assert.deepEqual( countries.FRA.currencies, ['EUR']);
});

@@ -26,7 +31,7 @@ });

describe('check currencies for each country', function () {
_.each( countryData, function (country) {
_.each( countries.all, function (country) {
describe(country.alpha2, function () {
_.each( country.currencies, function (currency) {
it(currency, function () {
assert( currencies.code[currency] );
assert( currencies[currency] );
});

@@ -33,0 +38,0 @@ });

var currencies = require('..').currencies,
assert = require('assert');
assert = require('assert'),
_ = require('underscore');
describe('currencies', function () {
describe('all', function () {
it('should be array', function () {
assert( _.isArray(currencies.all) );
});
});
describe('code', function () {
it('should find USD', function () {
assert.equal( currencies.code.USD.name, 'United States dollar');
assert.equal( currencies.USD.name, 'United States dollar');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc