ISO 3166-1:2020 country and codes lookup. The supported country code types are alpha-2, alpha-3 and num-3.
Install using npm
npm install iso3166-lookup
Using ISO 3166-1:2020 Codes lookup package into your code (import / require)
import iso3166Lookup from "iso3166-lookup";
OR
const iso3166Lookup = require('iso3166-lookup');
Get all countries
console.log(iso3166Lookup.getAllCountries());
/** Returns:
[
{
alpha2: "AD",
alpha3: "AND",
country: "Andorra",
num3: "020",
},
{
alpha2: "AE",
alpha3: "ARE",
country: "United Arab Emirates",
num3: "784",
},...
]
*/
Get all Country Names
console.log(iso3166Lookup.getAllCountryNames());
/** Returns:
[
"Andorra", "United Arab Emirates",...
]
*/
Get all Alpha-2 Codes
console.log(iso3166Lookup.getAllAlpha2());
/** Returns:
[
"AD", "AE",...
]
*/
Get all Alpha-3 Codes
console.log(iso3166Lookup.getAllAlpha3());
/** Returns:
[
"AND", "ARE",...
]
*/
Find country details by country name
console.log(iso3166Lookup.findCountry('India'));
/** Returns:
{
country: 'India',
alpha2: 'IN',
alpha3: 'IND',
numeric: '356'
}
*/
Find country details by ISO 3166-1 Alpha-2
console.log(iso3166Lookup.findAlpha2('in'));
/** Returns:
{
country: 'India',
alpha2: 'IN',
alpha3: 'IND',
numeric: '356'
}
*/
Find country details by ISO 3166-1 Alpha-3
console.log(iso3166Lookup.findAlpha3('ind'));
/** Returns:
{
country: 'India',
alpha2: 'IN',
alpha3: 'IND',
numeric: '356'
}
*/
Find country details by ISO 3166-1 Num-3 (Numeric)
console.log(iso3166Lookup.findNum3(356));
/** Returns:
{
country: 'India',
alpha2: 'IN',
alpha3: 'IND',
numeric: '356'
}
*/
Specify Return/Output types for find functions
You can optionally pass second param to find functions (viz. - findCountry, findAlpha2, findAlpha3, findNum3) to specify desired output format. By default functions will return country object if the parameter is not supplied. You can specify any value from the following: "obj", "name", "alpha2", "alpha3", "num3".
For example you can specify "name" to recieve output Country name as string or can specify "obj" to get Country object in return.
console.log(iso3166Lookup.findCountry("india")); // will return country object for India
console.log(iso3166Lookup.findCountry("india", "obj")); // will return country object for India
console.log(iso3166Lookup.findAlpha2("in", "name")); // will return "India"
console.log(iso3166Lookup.findAlpha3("ind", "alpha2")); // will return "IN"
console.log(iso3166Lookup.findNum3(356, "alpha3")); // will return "IND"
console.log(iso3166Lookup.findCountry("india", "num3")); // will return "356"
You can check following links for more information:
- ISO 3166 Country Codes
- ISO 3166-1:2020 Part 1: Country code
- ISO:3166-1
- ISO:639
Copyright (c) 2022 Omkar Tapale