Data about countries - like their ISO codes and currencies
There are lots of little bits of data that you often need relating to countries, and I couldn't find any easy to use source of it. So I compiled it all here.
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.
The data currently provided for each country is:
nameThe english name for the country
alpha2The ISO 3166-1 alpha 2 code
alpha3The ISO 3166-1 alpha 3 code
status: The ISO status of the entry: either 'assigned' or 'reserved'.
currenciesAn array of ISO 4217 currency codes with the primary one first
languagesAn array of ISO 639-2 codes for languages (may not be complete).
countryCallingCodesAn array of the international call prefixes for this country.
iocThe International Olympic Committee country code
Countries are ofter grouped into regions. The list of regions is by no means exhaustive, pull requests very welcome for additions.
countriesAn array of
alpha2codes for the countries in this region.
It is not that useful to just have the currency code(s) for a country, so included is currency data too:
nameThe english name for the currency
codeThe ISO 4217 code
numberThe ISO 4217 number
decimalsThe number of decimal digits conventionally shown
A list of languages provided by ISO 639-2;
nameThe english name for the language
alpha2The two letter ISO 639-1 code for the language (may be blank).
alpha3The three letter terminological ISO 639-2 code for the language (may be blank).
bibliograpicThe three letter bibliographic ISO 639-2 code for the language (may be blank).
To make finding easier there are utility methods that can search the countries and currencies. See examples below.
npm install country-data
var countries = require'country-data'countriescurrencies = require'country-data'currenciesregions = require'country-data'regionslanguages = require'country-data'languages;// .all gives you an array of all entriesconsole.log countriesall ;console.log currenciesall ;// countries are found using alpha2 or alpha3 (both uppercase)console.log countriesBEname ; // 'Belgium'console.log countriesFRAcurrencies ; // ['EUR']// currencies are accessed by their code (uppercase)console.log currenciesUSDname ; // 'United States dollar'// regions are accessed using a camel case nameconsole.log regionseuropecountries
var lookup = require'country-data'lookup;// Match a value (grab first from array)var france = lookupcountriesname: 'France'0;// Or match one of several possible values.var eurozone_countries = lookupcountriescurrencies: 'EUR';
It is very simple for now - feel free to contribute more helpful accessors.
More data for each country is most welcome. Obvious things that it might be nice to add are:
- Top level domains
- Wikipedia links
- Coordinates (centroid, bounding box, etc)
- International dialling codes
- Languages spoken - most common first
- currency symbols
- other currency that it is pegged to
The final format is JSON, but it is easier to work with CSV. Hence in the
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:
# Clone the repo (or better your fork of it)git clonecd country-data# install the dependenciesnpm install .# Edit the countries.csvopen data/countries.csv# Convert the raw data (CSV or JS files) to JSONmake# Run the testsmocha# If all is ok commit and pushgit add .git commitgit push# Then send a pull request with your changes. Ideally use several small commits,# and reference a source that backs up the change.
The currency data was copied from the Wikipedia ISO 4217 page.
The country calling codes came from the Wikipedia country calling codes page.