Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.
Branch: master
Clone or download
Latest commit 80bde20 Nov 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts Adding the conversion script Oct 15, 2016
test Adding overwrite functionality Nov 13, 2018
.gitignore Adding test coverage Nov 12, 2018
.travis.yml Adding test coverage Nov 12, 2018
LICENSE License change, from BSD to MIT Oct 15, 2016
README.md Adding overwrite functionality Nov 13, 2018
country-list.js Adding overwrite functionality Nov 13, 2018
data.json
package.json 2.1.0 Nov 13, 2018

README.md

country-list

Build Status Coverage Status

Maps ISO 3166-1-alpha-2 codes to English country names and vice versa.

Uses data from https://datahub.io/core/country-list (formerly http://data.okfn.org/data/country-list)

js-standard-style

Looking for Version 1

You can find version 1.* of country-list here.

Example

const { getCode, getName } = require('country-list');

console.log(getName('IS')); // Iceland
console.log(getCode('Iceland')); // IS
console.log(getCode('Nowhere-to-be-found-land')); // undefined

And how to change the name of a country

const { overwrite, getName } = require('country-list');
overwrite([{
  code: 'TW',
  name: 'Taiwan'
}])

console.log(getName('TW')); // Taiwan

Methods

Usage:

const countryList = require('country-list');

All input is case-insensitive.

overwrite(countries)

Expects an array of country objects containing code and name properties.

[{
  code: 'TW',
  name: 'Taiwan'
}]

getName(code)

Expects a two-digit country code.
Returns the name for that country.
If not found, it returns undefined.

getCode(name)

Expects the English country name.
Returns the code for that country.
If not found, it returns undefined.

getNames()

Returns an array of all country names.

getCodes()

Returns an array of all country codes.

getNameList()

Returns a key-value object of all countries using the name as key.

getCodeList()

Returns a key-value object of all countries using the code as key.

getData()

Returns an array of all country information, in the same format as it gets imported.

Install

npm install country-list

Related Projects

License

MIT