https://github.com/stephangeorg/iso-countries-lookup
Find country codes by country names in multiple languages.
https://github.com/stephangeorg/iso-countries-lookup
Last synced: about 1 year ago
JSON representation
Find country codes by country names in multiple languages.
- Host: GitHub
- URL: https://github.com/stephangeorg/iso-countries-lookup
- Owner: StephanGeorg
- License: mit
- Created: 2019-05-11T20:01:54.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-14T19:51:12.000Z (over 2 years ago)
- Last Synced: 2025-04-21T15:10:03.596Z (about 1 year ago)
- Language: JavaScript
- Size: 703 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iso-countries-lookup [](https://badge.fury.io/js/iso-countries-lookup)
Find country codes (ISO 3166-1 alpha-2) by country names in multiple languages with basic fault tolerance for inputs.
Returns the ISO 3166-1 alpha-2 country code for a given country name. Supports [multiple languages](https://www.npmjs.com/package/i18n-iso-countries#supported-languages-iso-639-1) based on [i18n-iso-countries](https://github.com/michaelwittig/node-i18n-iso-countries)
and also alternative names based on [world countries data](https://github.com/mledoze/countries).
## Installation
```
npm i iso-countries-lookup
```
## Usage
```javascript
import countryCodeLookup from 'iso-countries-lookup';
```
```
countryCodeLookup(input, [options]);
```
```javascript
// Finding ISO Code from official names (fastest)
countryCodeLookup('Germany'); // 'DE'
countryCodeLookup('United States of America'); // 'US'
countryCodeLookup('اليونان'); // 'GR'
countryCodeLookup('罗马尼亚'); // 'RO'
countryCodeLookup('Côte d\'Ivoire'); // 'CI'
// Findinding ISO codes from alternative names
countryCodeLookup('Bundesrepublik Deutschland'); // 'DE'
countryCodeLookup('United states'); // US
countryCodeLookup('Iran'); // 'IR'
countryCodeLookup('Cote dIvoire'); // 'CI'
// Finding ISO codes from dirty strings
countryCodeLookup(', Румыния - '); // Return RO
countryCodeLookup(' , DEU') // DE
countryCodeLookup('uk') // UK
// Finding ISO codes from Numeric
countryCodeLookup(184) // CK
countryCodeLookup('004') // AF
// Finding ISO codes from Numeric
countryCodeLookup(184, { numeric: false }) // undefined
countryCodeLookup('004', { numeric: false }) // undefined
```
## Options
Parameter | Default | Description
------------------- | ------------------- | -------------
numeric | true | ISO 3166-1 numeric values in input
## Returns
The [ISO 3166-1 alpha-2 code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of a country or `undefined`.