Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
ISO 3166 Country Name / Code Mapper in Javascript
JavaScript
branch: master

Merge pull request #1 from hitherejoe/fix_readme_example

Closes #1 - Corrected code example to retrieve country name using country code - Good catch, thanks!
latest commit e45e612957
Hannes Gassert authored

README.md

ISO 3166 Country Name / Code Mapper in Javascript

Uses the data in http://www.iso.org/iso/country_names_and_code_elements_txt to map from country codes to country names and vice versa. Also provides lists of all names and codes.

 Installation

npm install countrynames

Tests

npm test

 API Overview

exports.getCode(English:String)

Get a country code for a country name. Case-insensitive.

Examples:

// Returns 'CH'
countrynames.getCode('Switzerland')
// Returns 'BB'
countrynames.getCode('BarbaDOS')

exports.getName(Two-letter:String)

Get a country name for a country code. Case-insensitive.

Examples:

// Returns 'TONGA'
countrynames.getName('TO')
// Returns 'RÉUNION'
countrynames.getName('re')

exports.getAllCodes()

Get a country name for a country code. Case-insensitive.

Example:

// Returns an array ["AD", ... "ZW"]
countrynames.getAllCodes();

exports.getAllNames()

Get a country name for a country code. Case-insensitive.

Example:

// Returns an array ["AFGHANISTAN", ... "ZIMBABWE", "ÅLAND ISLANDS"]
countrynames.getAllCodes();

License

MIT

Something went wrong with that request. Please try again.