GithubHelp home page GithubHelp logo

tes / country-data Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openbookprices/country-data

0.0 66.0 0.0 387 KB

Country related data such as ISO codes, currencies etc

License: GNU Affero General Public License v3.0

Makefile 0.74% JavaScript 99.26%

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:

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

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;

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

// 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

  • 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/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.

country-data's People

Contributors

alanshaw avatar bebraw avatar carlosleopoldo avatar evdb avatar fnogatz avatar iancrowther avatar niftylettuce avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.