Map country names to ISO 3166-1-alpha-2 country codes and back
npm install countrynamesUses 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.
## Overview
- exports.getCode()
- exports.getName()
- exports.getAllCodes()
- exports.getAllNames()
Get a country code for a country name. Case-insensitive.
Examples:
``js`
// Returns 'CH'
countrynames.getCode('Switzerland')
// Returns 'BB'
countrynames.getCode('BarbaDOS')
Get a country name for a country code. Case-insensitive.
Examples:
`js`
// Returns 'TONGA'
countrynames.getCode('TO')
// Returns 'RÉUNION'
countrynames.getCode('re')
Get a country name for a country code. Case-insensitive.
Example:
`js`
// Returns an array ["AD", ... "ZW"]
countrynames.getAllCodes();
Get a country name for a country code. Case-insensitive.
Example:
`js``
// Returns an array ["AFGHANISTAN", ... "ZIMBABWE", "ÅLAND ISLANDS"]
countrynames.getAllCodes();