countrynames

Map country names to ISO 3166-1-alpha-2 country codes and back

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
countrynames
0.1.111 years ago11 years agoMinified + gzip package size for countrynames in KB

Readme

ISO 3166 Country Name / Code Mapper in Javascript
Uses the data in http://www.iso.org/iso/countrynamesandcodeelementstxt to map from country codes to country names and vice versa. Also provides lists of all names and codes.

Overview

- exports.getCode()
- exports.getName() - exports.getAllCodes() - exports.getAllNames()

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.getCode('TO')
// Returns 'RÉUNION'
countrynames.getCode('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();