country-data
Advanced tools
Comparing version 0.0.19 to 0.0.20
# Changes | ||
## v0.0.20 | ||
* Fix to some language references - thanks @jussi-kalliokoski | ||
* Added csv normalizing utility - so csv diffs should be easy in future | ||
* Fix to East Timor and continent groupings - thanks #iancrowther | ||
* Added currency symbols - thanks @CjS77 | ||
## v0.0.19 | ||
@@ -8,3 +15,2 @@ | ||
## v0.0.18 | ||
@@ -11,0 +17,0 @@ |
@@ -9,30 +9,41 @@ 'use strict'; | ||
var canonicalJSON = require('canonical-json'); | ||
var csvFile = path.join( __dirname, 'countries.csv' ); | ||
var countries = []; | ||
var fs = require('fs'); | ||
var output = []; | ||
// read in the CSV | ||
csv() | ||
.from.path(csvFile, { columns: true }) | ||
.on('record', function (row) { | ||
countries.push(row); | ||
}) | ||
.on('end', function () { | ||
var csvFile = path.join( __dirname, 'countries.csv' ); | ||
var input = fs.createReadStream(csvFile); | ||
// sort by alpha2 | ||
countries = _.sortBy(countries, function (i) { return i.alpha2;} ); | ||
// strip out fields that are not ready yet | ||
_.each(countries, function (country) { | ||
delete country.ccTLD; | ||
}); | ||
var parser = csv.parse({"columns": true}); | ||
// change the appropriate fields to be an array | ||
_.each(['currencies', 'countryCallingCodes', 'languages'], function(key) { | ||
_.each(countries, function (country) { | ||
country[key] = country[key] ? country[key].split(',') : []; | ||
}); | ||
parser.on('readable', function () { | ||
var record = null; | ||
while(record = parser.read()){ | ||
output.push(record); | ||
} | ||
}); | ||
parser.on('finish', function(){ | ||
// sort by alpha2 | ||
output = _.sortBy(output, function (i) { return i.alpha2;} ); | ||
// strip out fields that are not ready yet | ||
_.each(output, function (country) { | ||
delete country.ccTLD; | ||
}); | ||
// change the appropriate fields to be an array | ||
_.each(['currencies', 'countryCallingCodes', 'languages'], function(key) { | ||
_.each(output, function (country) { | ||
country[key] = country[key] ? country[key].split(',') : []; | ||
}); | ||
}); | ||
// print out results to stdout | ||
console.log( canonicalJSON( countries, null, 2 )); | ||
}); | ||
// print out results to stdout | ||
console.log( canonicalJSON( output, null, 2 )); | ||
}); | ||
input.pipe(parser); |
@@ -0,30 +1,39 @@ | ||
'use strict'; | ||
// Take the csv and convert to json and tidy it up so that it is consistent. | ||
var csv = require('csv') | ||
_ = require('underscore'), | ||
canonicalJSON = require('canonical-json'), | ||
path = require('path'); | ||
var path = require('path'); | ||
var _ = require('underscore'); | ||
var csv = require('csv'); | ||
var canonicalJSON = require('canonical-json'); | ||
var fs = require('fs'); | ||
var output = []; | ||
// read in the CSV | ||
var csvFile = path.join( __dirname, 'currencies.csv' ); | ||
var currencies = []; | ||
var input = fs.createReadStream(csvFile); | ||
// read in the CSV | ||
csv() | ||
.from.path(csvFile, { columns: true }) | ||
.on('record', function (row) { | ||
var parser = csv.parse({"columns": true}); | ||
parser.on('readable', function () { | ||
var record = null; | ||
while(record = parser.read()){ | ||
// convert decimals to and number | ||
row.decimals = parseInt(row.decimals); | ||
record.decimals = parseInt(record.decimals); | ||
output.push(record); | ||
} | ||
}); | ||
currencies.push(row); | ||
}) | ||
.on('end', function () { | ||
parser.on('finish', function(){ | ||
// sort by code | ||
currencies = _.sortBy(currencies, function (i) { return i.code;} ); | ||
// sort by code | ||
output = _.sortBy(output, function (i) { return i.code;} ); | ||
// print out results to stdout | ||
console.log( canonicalJSON( currencies, null, 2 )); | ||
// print out results to stdout | ||
console.log( canonicalJSON( output, null, 2 )); | ||
}); | ||
}); | ||
input.pipe(parser); |
@@ -9,18 +9,30 @@ 'use strict'; | ||
var canonicalJSON = require('canonical-json'); | ||
var csvFile = path.join( __dirname, 'languages.csv' ); | ||
var languages = []; | ||
var fs = require('fs'); | ||
var output = []; | ||
// read in the CSV | ||
csv() | ||
.from.path(csvFile, { columns: true }) | ||
.on('record', function (row) { | ||
languages.push(row); | ||
}) | ||
.on('end', function () { | ||
var csvFile = path.join( __dirname, 'languages.csv' ); | ||
var input = fs.createReadStream(csvFile); | ||
// sort by alpha3 | ||
languages = _.sortBy(languages, function (i) { return i.alpha3;} ); | ||
// print out results to stdout | ||
console.log( canonicalJSON( languages, null, 2 )); | ||
}); | ||
var parser = csv.parse({"columns": true}); | ||
parser.on('readable', function () { | ||
var record = null; | ||
while(record = parser.read()){ | ||
output.push(record); | ||
} | ||
}); | ||
parser.on('finish', function(){ | ||
// sort by alpha3 | ||
output = _.sortBy(output, function (i) { return i.alpha3;} ); | ||
// print out results to stdout | ||
console.log( canonicalJSON( output, null, 2 )); | ||
}); | ||
input.pipe(parser); |
@@ -1,7 +0,7 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _ = require("underscore"); | ||
var regions = {}; | ||
regions.centralAsia = { | ||
name: 'Central Asia', | ||
countries: [ | ||
@@ -18,2 +18,3 @@ // source is http://en.wikipedia.org/wiki/Central_Asia | ||
regions.southernAsia = { | ||
name: 'Southern Asia', | ||
countries: [ | ||
@@ -35,2 +36,3 @@ // source is http://en.wikipedia.org/wiki/South_Asia | ||
regions.southeastAsia = { | ||
name: 'Southeast Asia', | ||
countries: [ | ||
@@ -55,2 +57,3 @@ // source is http://en.wikipedia.org/wiki/Southeast_Asia | ||
regions.eastAsia = { | ||
name: 'East Asia', | ||
countries: [ | ||
@@ -70,2 +73,3 @@ // source is http://en.wikipedia.org/wiki/East_Asia | ||
regions.westernAsia = { | ||
name: 'Western Asia', | ||
countries: [ | ||
@@ -92,16 +96,4 @@ // source is http://en.wikipedia.org/wiki/Western_Asia | ||
regions.asia = { | ||
'asia': { | ||
countries: _.flatten([ | ||
regions.centralAsia.countries, | ||
regions.southernAsia.countries, | ||
regions.southeastAsia.countries, | ||
regions.eastAsia.countries, | ||
regions.westernAsia.countries, | ||
]) | ||
.sort() | ||
} | ||
}; | ||
regions.centralAfrica = { | ||
name: 'Central Aftrica', | ||
countries: [ | ||
@@ -122,2 +114,3 @@ // source is http://en.wikipedia.org/wiki/Central_Africa | ||
regions.northAfrica = { | ||
name: 'North Africa', | ||
countries: [ | ||
@@ -136,2 +129,3 @@ // source is http://en.wikipedia.org/wiki/North_Africa | ||
regions.southernAfrica = { | ||
name: 'Southern Africa', | ||
countries: [ | ||
@@ -148,2 +142,3 @@ // source is http://en.wikipedia.org/wiki/Southern_Africa | ||
regions.eastAfrica = { | ||
name: 'East Africa', | ||
countries: [ | ||
@@ -175,2 +170,3 @@ // source is http://en.wikipedia.org/wiki/East_Africa | ||
regions.westAfrica = { | ||
name: 'West Africa', | ||
countries: [ | ||
@@ -198,16 +194,4 @@ // source is http://en.wikipedia.org/wiki/West_Africa | ||
regions.africa = { | ||
'africa': { | ||
countries: _.flatten([ | ||
regions.centralAfrica.countries, | ||
regions.northAfrica.countries, | ||
regions.southernAfrica.countries, | ||
regions.eastAfrica.countries, | ||
regions.westAfrica.countries | ||
]) | ||
.sort() | ||
} | ||
}; | ||
regions.centralAmerica = { | ||
name: 'Central America', | ||
countries: [ | ||
@@ -226,2 +210,3 @@ // source is http://en.wikipedia.org/wiki/Central_America | ||
regions.northernAmerica = { | ||
name: 'Northern America', | ||
countries: [ | ||
@@ -239,2 +224,3 @@ // source is http://en.wikipedia.org/wiki/Northern_America | ||
regions.caribbean = { | ||
name: 'Caribbean', | ||
countries: [ | ||
@@ -273,49 +259,37 @@ // source is http://en.wikipedia.org/wiki/Caribbean | ||
regions.northAmerica = { | ||
'northAmerica': { | ||
countries: _.flatten([ | ||
regions.centralAmerica.countries, | ||
regions.northernAmerica.countries, | ||
regions.caribbean.countries | ||
]) | ||
.sort() | ||
} | ||
}; | ||
regions.southAmerica = { | ||
'southAmerica': { | ||
countries: [ | ||
// source is http://en.wikipedia.org/wiki/South_America | ||
'AR', // Argentina | ||
'BO', // Bolivia | ||
'BR', // Brazil | ||
// 'CL', // Chile | ||
'CO', // Colombia | ||
'EC', // Ecuador | ||
'FK', // Falkland Islands | ||
'GF', // French Guiana | ||
'GY', // Guyana | ||
'PY', // Paraguay | ||
'PE', // Peru | ||
'SR', // Suriname | ||
'UY', // Uruguay | ||
'VE', // Venezuela | ||
].sort() | ||
} | ||
name: 'South America', | ||
countries: [ | ||
// source is http://en.wikipedia.org/wiki/South_America | ||
'AR', // Argentina | ||
'BO', // Bolivia | ||
'BR', // Brazil | ||
'CL', // Chile | ||
'CO', // Colombia | ||
'EC', // Ecuador | ||
'FK', // Falkland Islands | ||
'GF', // French Guiana | ||
'GY', // Guyana | ||
'PY', // Paraguay | ||
'PE', // Peru | ||
'SR', // Suriname | ||
'UY', // Uruguay | ||
'VE', // Venezuela | ||
] | ||
} | ||
regions.antartica = { | ||
'antartica': { | ||
countries: [ | ||
// source is http://en.wikipedia.org/wiki/Antarctica | ||
'AQ', // Antarctica | ||
'BV', // Bouvet Island | ||
'TF', // French Southern Territories | ||
'HM', // Heard Island and McDonald Islands | ||
'GS', // South Georgia and the South Sandwich Islands | ||
].sort() | ||
} | ||
name: 'Antartica', | ||
countries: [ | ||
// source is http://en.wikipedia.org/wiki/Antarctica | ||
'AQ', // Antarctica | ||
'BV', // Bouvet Island | ||
'TF', // French Southern Territories | ||
'HM', // Heard Island and McDonald Islands | ||
'GS', // South Georgia and the South Sandwich Islands | ||
] | ||
} | ||
regions.northernEurope = { | ||
name: 'Northern Europe', | ||
countries: [ | ||
@@ -343,2 +317,3 @@ // source is http://en.wikipedia.org/wiki/Northern_Europe | ||
regions.southernEurope = { | ||
name: 'Southern Europe', | ||
countries: [ | ||
@@ -367,2 +342,3 @@ // source is http://en.wikipedia.org/wiki/Southern_Europe | ||
regions.easternEurope = { | ||
name: 'Eastern Europe', | ||
countries: [ | ||
@@ -385,2 +361,3 @@ // source is http://en.wikipedia.org/wiki/Eastern_Europe | ||
regions.westernEurope = { | ||
name: 'Western Europe', | ||
countries: [ | ||
@@ -399,16 +376,5 @@ // source is http://en.wikipedia.org/wiki/Western_Europe | ||
}; | ||
regions.europe = { | ||
'europe': { | ||
countries: _.flatten([ | ||
regions.northernEurope.countries, | ||
regions.southernEurope.countries, | ||
regions.easternEurope.countries, | ||
regions.westernEurope.countries, | ||
]) | ||
.sort() | ||
} | ||
} | ||
regions.australia = { | ||
name: 'Australia', | ||
countries: [ | ||
@@ -423,2 +389,3 @@ // source is http://en.wikipedia.org/wiki/Oceania | ||
regions.melanesia = { | ||
name: 'Melanesia', | ||
countries: [ | ||
@@ -435,2 +402,3 @@ // source is http://en.wikipedia.org/wiki/Oceania | ||
regions.micronesia = { | ||
name: 'Micronesia', | ||
countries: [ | ||
@@ -450,2 +418,3 @@ // source is http://en.wikipedia.org/wiki/Oceania | ||
regions.polynesia = { | ||
name: 'Polynesia', | ||
countries: [ | ||
@@ -455,3 +424,2 @@ // source is http://en.wikipedia.org/wiki/Oceania | ||
'CK', // Cook Islands | ||
'CL', // Easter Island (Chile) | ||
'PF', // French Polynesia | ||
@@ -468,14 +436,2 @@ 'NU', // Niue | ||
regions.oceania = { | ||
'oceania': { | ||
countries: _.flatten([ | ||
regions.australia.countries, | ||
regions.melanesia.countries, | ||
regions.micronesia.countries, | ||
regions.polynesia.countries, | ||
]) | ||
.sort() | ||
} | ||
}; | ||
module.exports = regions; |
15
index.js
'use strict'; | ||
var _ = require('underscore'); | ||
var continents = require('./data/continents'); | ||
var regions = require('./data/regions'); | ||
@@ -10,2 +11,7 @@ var countriesAll = require('./data/countries.json'); | ||
var getSymbol = require('currency-symbol-map') | ||
exports.continents = continents; | ||
exports.regions = regions; | ||
exports.countries = { | ||
@@ -25,2 +31,9 @@ all: countriesAll, | ||
_.each(currenciesAll, function (currency) { | ||
//If the symbol isn't available, default to the currency code | ||
var symbol = getSymbol(currency.code); | ||
if (symbol == '?') { | ||
symbol = currency.code; | ||
} | ||
currency.symbol = symbol; | ||
exports.currencies[currency.code] = currency; | ||
@@ -42,4 +55,2 @@ }); | ||
exports.regions = regions; | ||
exports.lookup = lookup({ | ||
@@ -46,0 +57,0 @@ countries: countriesAll, |
{ | ||
"name": "country-data", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Data about countries - like their ISO codes and currencies", | ||
@@ -24,10 +24,11 @@ "homepage": "https://github.com/OpenBookPrices/country-data", | ||
"devDependencies": { | ||
"canonical-json": "0.0.1", | ||
"csv": "~0.2.9", | ||
"mocha": "~1.9.0", | ||
"chai": "~1.8.1" | ||
"canonical-json": "~0.0.4", | ||
"csv": "~0.4", | ||
"mocha": "~2.2", | ||
"chai": ">1.8.1" | ||
}, | ||
"dependencies": { | ||
"underscore": "~1.4.4" | ||
"underscore": ">1.4.4", | ||
"currency-symbol-map": "~2" | ||
} | ||
} |
@@ -42,2 +42,5 @@ # Country Data | ||
* `decimals` The number of decimal digits conventionally shown | ||
* `symbol` The currency symbol for the currency (e.g. ¥, $ etc.). Some symbols are not available, in which case | ||
`symbol` contains the ISO 4217 code. Credit to [bengourley/currency-symbol-map](https://github.com/bengourley/currency-symbol-map) | ||
for the symbol database. | ||
@@ -44,0 +47,0 @@ ## Languages |
@@ -21,6 +21,23 @@ var currencies = require('..').currencies, | ||
it("decimals should be numbers", function () { | ||
assert(_.isNumber(currencies.USD.decimals)); | ||
assert(_.isNumber(currencies.USD.decimals)); | ||
}); | ||
}); | ||
describe('symbols', function () { | ||
it('should find $', function () { | ||
assert.equal( currencies.USD.symbol, '$'); | ||
}); | ||
it('should find ¥', function () { | ||
assert.equal( currencies.JPY.symbol, '¥'); | ||
}); | ||
it('should find R', function () { | ||
assert.equal( currencies.ZAR.symbol, 'R'); | ||
}); | ||
it('should find AED (has no symbol)', function () { | ||
assert.equal( currencies.AED.symbol, 'AED'); | ||
}); | ||
}); | ||
}); |
@@ -51,7 +51,5 @@ 'use strict'; | ||
_.each(regions, function (region, name) { | ||
if (!region.countries) { | ||
_.each(region[name].countries, function (country) { | ||
countriesAssigned.push(country); | ||
}); | ||
} | ||
_.each(region.countries, function (country) { | ||
countriesAssigned.push(country); | ||
}); | ||
}); | ||
@@ -58,0 +56,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
238077
31
9625
167
2
4
+ Addedcurrency-symbol-map@~2
+ Addedcurrency-symbol-map@2.2.0(transitive)
+ Addedunderscore@1.13.7(transitive)
- Removedunderscore@1.4.4(transitive)
Updatedunderscore@>1.4.4