Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

country-data

OpenBookPrices269.6kMIT0.0.31TypeScript support: definitely-typed

Data about countries - like their ISO codes and currencies

data, country

readme

Country Data

Build Status

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.

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

The data currently provided for each country is:

Status notes

The status can be one of 'assigned', 'reserved', 'user assigned' or 'deleted'.

Assigned means that the code is properly in the ISO 3166 standard. Reserved means that the code is being prevented from being used. Deleted means that it has been deleted. User Assigned means that for some use cases it is required. Deleted means that it used to be in the standard but is now not.

See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for full details, especially the "User-assigned code elements" and "Reserved code elements" sections.

Regions

Countries are ofter grouped into regions. The list of regions is by no means exhaustive, pull requests very welcome for additions.

  • countries An array of alpha2 codes for the countries in this region.

Currencies

It is not that useful to just have the currency code(s) for a country, so included is currency data too:

  • name The english name for the currency
  • code The ISO 4217 code
  • number The ISO 4217 number
  • 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 for the symbol database.

Languages

A list of languages provided by ISO 639-2;

  • name The english name for the language
  • alpha2 The two letter ISO 639-1 code for the language (may be blank).
  • alpha3 The three letter terminological ISO 639-2 code for the language (may be blank).
  • bibliograpic The three letter bibliographic ISO 639-2 code for the language (may be blank).

Lookup

To make finding easier there are utility methods that can search the countries and currencies. See examples below.

Installing

npm install country-data

Example usage

var countries        = require('country-data').countries,
    currencies       = require('country-data').currencies,
    regions          = require('country-data').regions,
    languages        = require('country-data').languages,
    callingCountries = require('country-data').callingCountries;

// .all gives you an array of all entries
console.log( countries.all );
console.log( currencies.all );

// countries are found using alpha2 or alpha3 (both uppercase)
console.log( countries.BE.name );        // 'Belgium'
console.log( countries.FRA.currencies ); // ['EUR']

// callingCountries is like countries but only has entries with dialing codes.

// currencies are accessed by their code (uppercase)
console.log( currencies.USD.name ); // 'United States dollar'

// regions are accessed using a camel case name
console.log( regions.europe.countries )
var lookup = require('country-data').lookup;

// Match a value (grab first from array)
var france = lookup.countries({name: 'France'})[0];

// Or match one of several possible values.
var eurozone_countries = lookup.countries({currencies: 'EUR'});

It is very simple for now - feel free to contribute more helpful accessors.

Possible future additions

More data for each country is most welcome. Obvious things that it might be nice to add are:

Countries

  • Wikipedia links
  • Coordinates (centroid, bounding box, etc)

Currencies

  • other currency that it is pegged to

Using with webpack

As this code loads the data from JSON files you need to add the JSON loader to webpack:

npm install json-loader --save-dev

and then include in your webpack.config.js:

// ...
   loaders: [
      // other loaders
      { test: /\.json$/, loader: 'json' },
  ],
// ...

Other similar bits of code

  • libphonenumber "Google's common Java, C++ and Javascript library for parsing, formatting, storing and validating international phone numbers."

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:

# Clone the repo (or better your fork of it)
git clone https://github.com/OpenBookPrices/country-data.git
cd country-data

# install the dependencies
npm install .

# Edit the countries.csv
open data/countries.csv

# Convert the raw data (CSV or JS files) to JSON
make

# Run the tests
mocha

# If all is ok commit and push
git add .
git commit
git push

# 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 page.

The country calling codes came from the Wikipedia country calling codes page.

changelog

Changes

v0.0.31

  • fixed deleted countries appearing in countries[alpha2] instead of the current active country - thanks @silverwind

v0.0.30

  • Added emoji flags for countries - thanks @livedo

v0.0.29

  • Added or corrected Olympic codes for Kosovo, Federated States of Micronesia and British Virgin Islands - thanks @giedrius-timinskis

v0.0.28

  • Added notes on getting this package to work with webpack - thanks @luxflux and others in issue #57
  • Added missing IOC code for South Sudan (SSD) - thanks @marchah

v0.0.27

  • Fixed Trinidad and Tobago IOC code (was TRI, now TTO) - thanks @mrmckeb

v0.0.26

  • Fixed typo and added tests to prevent it happening again (#56) - thanks @dbellavista

v0.0.25

  • Added previously deleted countries as "deleted" (thanks @mattvadrise in pull request #53)
  • Changed name of "Sao Tome and Principe" (thanks @Laboratory)

v0.0.24

  • Added Kosovo as a "user assigned" entry (thanks @doapp-ryanp)

v0.0.23

  • Change license from AGPL3 to MIT (thanks @aduis)

v0.0.22

  • changed "Taiwan, Province Of China" to just "Taiwan" - thanks @azai-yahoo

v0.0.21

  • Added callingCountries - thanks @chemerisuk
  • Updated docs to remove things that have been implemented from future additions list

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

  • Added Malay as a language for Malaysia (thanks to @lpsBetty)
  • Removed redundant calling code +521 from Mexico (thanks to @spmarin)

v0.0.18

  • updated several languages, country names and added many regions - thanks to @iancrowther

v0.0.17

  • changed Latvian and Lithuanian currencies to EUR - thanks @gytisgreitai

v0.0.16

  • minor bug fix - thanks @alanshaw

v0.0.15

  • List all calling codes in an expected order - thanks @alanshaw

v0.0.14

  • Added languages - many thanks to Moritz Lawitschka (@lawitschka) for doing the initial work.

v0.0.13

  • @carlosleopoldo added 521 calling code to Mexico

v0.0.12

  • @bebrow contributed lookup()

v0.0.11

  • Corrected Georgia calling code (thanks niftylettuce)

v0.0.10

  • Corrected Grenada calling code (thanks niftylettuce)

v0.0.9

  • Added country-data.regions
  • Added South Sudan
  • Added proper accents to São Tomé and Príncipe

v0.0.8

  • Added IOC country codes (thanks fnogatz)

v0.0.7

  • Corrected several calling codes (GB, GA, GF, GG)

v0.0.6

  • Added link to libphonenumber
  • Repo name change - to OpenBookPrices from LinkToBooks

v0.0.5

  • in currencies make the decimals an integer

v0.0.4

  • added country ISO status
  • added country calling codes

v0.0.3

  • got rid of the countries.alpha2. style accessors.

v0.0.2

  • added currencies

v0.0.1

  • Initial release