Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hannesgassert/countrynames
ISO 3166 Country Name / Code Mapper in Javascript
https://github.com/hannesgassert/countrynames
Last synced: 17 days ago
JSON representation
ISO 3166 Country Name / Code Mapper in Javascript
- Host: GitHub
- URL: https://github.com/hannesgassert/countrynames
- Owner: hannesgassert
- Created: 2013-02-15T17:07:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-10-04T09:00:50.000Z (about 6 years ago)
- Last Synced: 2024-05-22T22:34:02.696Z (6 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 41
- Watchers: 3
- Forks: 15
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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 countrynames
```## Tests
```
npm test
```## API Overview
- [exports.getCode()](#exportsgetcodeenglishstring)
- [exports.getName()](#exportsgetnametwoletterstring)
- [exports.getAllCodes()](#exportsgetallcodes)
- [exports.getAllNames()](#exportsgetallnames)## exports.getCode(English:String)
Get a country code for a country name. Case-insensitive.
Examples:
```js
// 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:
```js
// Returns 'TONGA'
countrynames.getName('TO')
// Returns 'RÉUNION'
countrynames.getName('re')
```## exports.getAllCodes()
Get a country name for a country code. Case-insensitive.
Example:
```js
// Returns an array ["AD", ... "ZW"]
countrynames.getAllCodes();
```## exports.getAllNames()
Get a country name for a country code. Case-insensitive.
Example:
```js
// Returns an array ["AFGHANISTAN", ... "ZIMBABWE", "ÅLAND ISLANDS"]
countrynames.getAllNames();
```## License
MIT