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

Data about countries - like their ISO codes and currencies


Version published
Weekly downloads
71K
decreased by-12.56%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Countries

The data currently provided for each country is:

  • name The english name for the country
  • alpha2 The ISO 3166-1 alpha 2 code
  • alpha3 The ISO 3166-1 alpha 3 code
  • currencies An array of ISO 4217 currency codes with the primary one first

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](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

Installing

npm install country-data

Example usage

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

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

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

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

Adding data

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 dialing codes

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.

These are the steps required

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

# install the dependencies
npm install .

# Edit the countries.csv
open countries.csv

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

# 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

Sources

The currency data was copied from the Wikipedia ISO 4217 page.

Keywords

FAQs

Package last updated on 05 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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