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 based on i18n-iso-countries and also alternative names based on world countries data.
npm i iso-countries-lookup
import countryCodeLookup from 'iso-countries-lookup';
// 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
The ISO 3166-1 alpha-2 code of a country or undefined
.