Giter VIP home page Giter VIP logo

country-data's Introduction

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:

  • name The english name for the country
  • alpha2 The ISO 3166-1 alpha 2 code
  • alpha3 The ISO 3166-1 alpha 3 code
  • status: The ISO status of the entry: either 'assigned' or 'reserved'.
  • currencies An array of ISO 4217 currency codes with the primary one first
  • countryCallingCodes An array of the international call prefixes for this country.

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

Installing

npm install country-data

Example usage

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

// .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']

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

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

  • Top level domains
  • Wikipedia links
  • Coordinates (centroid, bounding box, etc)
  • International dialling codes
  • Languages spoken - most common first

Currencies

  • currency symbols
  • other currency that it is pegged to

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/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
node data/currency_csv_to_json.js > data/currencies.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. 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.

country-data's People

Contributors

evdb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.