countryencoder
v0.1.7
Published
Map country names to ISO 3166-1-alpha-2 country codes and back
Downloads
2
Maintainers
Readme
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 countryencoder
Tests
npm test
## API Overview
- countryencoder.getCode()
- countryencoder.getName()
- countryencoder.getAllCodes()
- countryencoder.getAllNames()
countryencoder.getCode(English:String)
Get a country code for a country name. Case-insensitive.
Usage
import * as countryencoder from "countryencoder"
// Returns 'CH'
countryencoder.getCode('Switzerland')
// Returns 'BB'
countryencoder.getCode('BarbaDOS')
countryencoder.getName(Two-letter:String)
Get a country name for a country code. Case-insensitive.
Examples:
// Returns 'TONGA'
countryencoder.getName('TO')
// Returns 'RÉUNION'
countryencoder.getName('re')
countryencoder.getAllCodes()
Get a country name for a country code. Case-insensitive.
Example:
// Returns an array ["AD", ... "ZW"]
countryencoder.getAllCodes();
countryencoder.getAllNames()
Get a country name for a country code. Case-insensitive.
Example:
// Returns an array ["AFGHANISTAN", ... "ZIMBABWE", "ÅLAND ISLANDS"]
countryencoder.getAllNames();
License
MIT