Complete API documentation for the iso-3166 library.
- Country Functions
- Subdivision Functions
- Currency Functions
- Dial Code Functions
- Geography Functions
- Membership Functions
- Types
Lookup country by ISO 3166-1 alpha-2 code.
Parameters:
code- 2-letter country code (case-insensitive)
Returns: Country object or null if not found
Example:
import { country } from 'iso-3166';
country.whereAlpha2('US');
// { name: 'United States', alpha2: 'US', alpha3: 'USA', numeric: '840' }
country.whereAlpha2('us'); // case-insensitive
// { name: 'United States', ... }
country.whereAlpha2('XX');
// nullLookup country by ISO 3166-1 alpha-3 code.
Parameters:
code- 3-letter country code (case-insensitive)
Returns: Country object or null if not found
Example:
country.whereAlpha3('USA');
// { name: 'United States', alpha2: 'US', alpha3: 'USA', numeric: '840' }
country.whereAlpha3('XXX');
// nullLookup country by ISO 3166-1 numeric code.
Parameters:
code- Numeric country code (string or number)
Returns: Country object or null if not found
Example:
country.whereNumeric('840');
// { name: 'United States', ... }
country.whereNumeric(840);
// { name: 'United States', ... }
country.whereNumeric(4); // Handles missing leading zeros
// { name: 'Afghanistan', alpha2: 'AF', ... }Lookup country by name (case-insensitive).
Parameters:
name- Country name
Returns: Country object or null if not found
Example:
country.whereName('United States');
// { name: 'United States', alpha2: 'US', ... }
country.whereName('SWEDEN'); // case-insensitive
// { name: 'Sweden', alpha2: 'SE', ... }Get all countries.
Returns: Array of all Country objects, sorted by alpha-2 code
Example:
const countries = country.all();
// [{ name: 'Afghanistan', alpha2: 'AF', ... }, ...]Get country with all its subdivisions.
Parameters:
code- Country code (alpha-2 or alpha-3)
Returns: Country with subdivisions or null if not found
Example:
country.withSubdivisions('US');
// {
// name: 'United States',
// alpha2: 'US',
// alpha3: 'USA',
// numeric: '840',
// subdivisions: {
// 'US-CA': { name: 'California', type: 'State' },
// 'US-TX': { name: 'Texas', type: 'State' },
// ...
// }
// }Convert alpha-2 code to alpha-3.
country.alpha2ToAlpha3('US'); // 'USA'
country.alpha2ToAlpha3('SE'); // 'SWE'
country.alpha2ToAlpha3('XX'); // nullConvert alpha-3 code to alpha-2.
country.alpha3ToAlpha2('USA'); // 'US'
country.alpha3ToAlpha2('XXX'); // nullConvert alpha-2 code to numeric.
country.alpha2ToNumeric('US'); // '840'Convert alpha-3 code to numeric.
country.alpha3ToNumeric('USA'); // '840'Convert numeric code to alpha-2.
country.numericToAlpha2('840'); // 'US'
country.numericToAlpha2(840); // 'US'Convert numeric code to alpha-3.
country.numericToAlpha3('840'); // 'USA'
country.numericToAlpha3(840); // 'USA'Get country name from any code format.
country.toName('US'); // 'United States'
country.toName('USA'); // 'United States'
country.toName(840); // 'United States'
country.toName('XX'); // nullConvert between any two country code formats.
country.convert('US', 'alpha2', 'alpha3'); // 'USA'
country.convert('USA', 'alpha3', 'numeric'); // '840'
country.convert('840', 'numeric', 'alpha2'); // 'US'Check if string is a valid alpha-2 code.
country.isAlpha2('US'); // true
country.isAlpha2('USA'); // false
country.isAlpha2('XX'); // falseCheck if string is a valid alpha-3 code.
country.isAlpha3('USA'); // true
country.isAlpha3('US'); // false
country.isAlpha3('XXX'); // falseCheck if value is a valid numeric code.
country.isNumeric('840'); // true
country.isNumeric(840); // true
country.isNumeric('999'); // falseCheck if string is a valid country name.
country.isCountryName('United States'); // true
country.isCountryName('Narnia'); // falseCheck if value is any valid country identifier.
country.isValid('US'); // true
country.isValid('USA'); // true
country.isValid(840); // true
country.isValid('United States'); // true
country.isValid('XX'); // falseDetect the format of a country code.
country.detectFormat('US'); // 'alpha2'
country.detectFormat('USA'); // 'alpha3'
country.detectFormat('840'); // 'numeric'
country.detectFormat('United States'); // 'name'
country.detectFormat('XX'); // nullLookup subdivision by full ISO 3166-2 code.
Parameters:
code- Full subdivision code (e.g., "US-CA")
Returns: Subdivision object or null if not found
Example:
import { subdivision } from 'iso-3166';
subdivision.whereCode('US-CA');
// {
// code: 'US-CA',
// name: 'California',
// type: 'State',
// countryCode: 'US',
// countryName: 'United States',
// regionCode: 'CA'
// }
subdivision.whereCode('USA-CA'); // Works with alpha-3 country codes
// { code: 'US-CA', name: 'California', ... }
subdivision.whereCode('US-California'); // Works with subdivision names
// { code: 'US-CA', name: 'California', ... }Lookup subdivision by country code and region code.
subdivision.where('US', 'CA');
// { code: 'US-CA', name: 'California', ... }
subdivision.where('USA', 'CA'); // Works with alpha-3
// { code: 'US-CA', name: 'California', ... }Lookup subdivision by country code and subdivision name.
subdivision.whereName('US', 'California');
// { code: 'US-CA', name: 'California', ... }
subdivision.whereName('US', 'california'); // case-insensitive
// { code: 'US-CA', name: 'California', ... }Get all subdivisions for a country.
const states = subdivision.forCountry('US');
// [{ code: 'US-AL', name: 'Alabama', ... }, { code: 'US-AK', name: 'Alaska', ... }, ...]
subdivision.forCountry('XX'); // []Get all subdivisions from all countries.
const allSubs = subdivision.all();
// Returns 5000+ subdivisions sorted by codeCheck if a country has subdivisions registered.
subdivision.hasSubdivisions('US'); // true
subdivision.hasSubdivisions('USA'); // true
subdivision.hasSubdivisions('XX'); // falseExtract region code from full subdivision code.
subdivision.toRegionCode('US-CA'); // 'CA'
subdivision.toRegionCode('GB-EAW'); // 'EAW'
subdivision.toRegionCode('invalid'); // nullBuild full subdivision code from country and region.
subdivision.toFullCode('US', 'CA'); // 'US-CA'
subdivision.toFullCode('USA', 'CA'); // 'US-CA' (normalizes alpha-3)
subdivision.toFullCode('US', 'XX'); // null (invalid region)Get subdivision name from full code.
subdivision.toName('US-CA'); // 'California'
subdivision.toName('XX-YY'); // nullGet subdivision name from country and region code.
subdivision.toNameFrom('US', 'CA'); // 'California'
subdivision.toNameFrom('USA', 'CA'); // 'California'Extract country code from full subdivision code.
subdivision.toCountryCode('US-CA'); // 'US'
subdivision.toCountryCode('USA-CA'); // 'US' (normalizes)
subdivision.toCountryCode('invalid'); // nullCheck if string is a valid full subdivision code.
subdivision.isValidCode('US-CA'); // true
subdivision.isValidCode('XX-YY'); // falseCheck if region code is valid for a country.
subdivision.isValidRegion('US', 'CA'); // true
subdivision.isValidRegion('US', 'XX'); // falseCheck if subdivision name exists in a country.
subdivision.isValidName('US', 'California'); // true
subdivision.isValidName('US', 'Narnia'); // falseImport: import { currency } from '@koshmoney/countries/currency';
Get full currency information for a country.
currency.getCurrency('US');
// { code: 'USD', symbol: '$', name: 'US Dollar' }
currency.getCurrency('JP');
// { code: 'JPY', symbol: '¥', name: 'Japanese Yen' }
currency.getCurrency('XX');
// nullGet currency code for a country.
currency.getCurrencyCode('US'); // 'USD'
currency.getCurrencyCode('DE'); // 'EUR'
currency.getCurrencyCode('XX'); // nullGet currency symbol for a country.
currency.getCurrencySymbol('US'); // '$'
currency.getCurrencySymbol('GB'); // '£'
currency.getCurrencySymbol('IN'); // '₹'Get currency name for a country.
currency.getCurrencyName('US'); // 'US Dollar'
currency.getCurrencyName('JP'); // 'Japanese Yen'Get all countries using a specific currency.
currency.getCountriesByCurrency('EUR');
// ['AD', 'AT', 'BE', 'CY', 'DE', 'EE', 'ES', 'FI', 'FR', ...]
currency.getCountriesByCurrency('USD');
// ['AS', 'EC', 'FM', 'GU', 'IO', 'MH', 'MP', 'PR', 'PW', 'TC', 'UM', 'US', 'VG', 'VI']Import: import { dialCode } from '@koshmoney/countries/dialCode';
Powered by libphonenumber-js
Get international dialing code for a country.
dialCode.getDialCode('US'); // '+1'
dialCode.getDialCode('GB'); // '+44'
dialCode.getDialCode('FR'); // '+33'
dialCode.getDialCode('XX'); // nullGet all dial codes for a country (array for consistency).
dialCode.getDialCodes('US'); // ['+1']
dialCode.getDialCodes('GB'); // ['+44']Get full dial code information.
dialCode.getDialCodeInfo('US');
// { dialCode: '+1', countryCode: 'US' }
dialCode.getDialCodeInfo('XX');
// nullCheck if country code is supported for phone operations.
dialCode.isValidPhoneCountry('US'); // true
dialCode.isValidPhoneCountry('XX'); // falseGet all supported country codes.
dialCode.getSupportedCountries();
// ['AC', 'AD', 'AE', 'AF', ...]Import: import { geography } from '@koshmoney/countries/geography';
Based on UN M49 geographic regions classification.
Get continent for a country.
geography.getContinent('US'); // 'North America'
geography.getContinent('JP'); // 'Asia'
geography.getContinent('DE'); // 'Europe'
geography.getContinent('AU'); // 'Oceania'
geography.getContinent('XX'); // nullGet UN M49 subregion for a country.
geography.getRegion('US'); // 'Northern America'
geography.getRegion('JP'); // 'Eastern Asia'
geography.getRegion('DE'); // 'Western Europe'
geography.getRegion('BR'); // 'South America'Get full geography information.
geography.getGeography('FR');
// { continent: 'Europe', region: 'Western Europe' }
geography.getGeography('XX');
// nullGet all countries in a continent.
geography.getCountriesByContinent('Europe');
// ['AD', 'AL', 'AT', 'AX', 'BA', 'BE', ...]
geography.getCountriesByContinent('Antarctica');
// ['AQ', 'BV', 'GS', 'HM', 'TF']Get all countries in a region.
geography.getCountriesByRegion('Eastern Asia');
// ['CN', 'HK', 'JP', 'KP', 'KR', 'MO', 'MN', 'TW']
geography.getCountriesByRegion('Northern America');
// ['BM', 'CA', 'GL', 'PM', 'US']Get all continents.
geography.getContinents();
// ['Africa', 'Antarctica', 'Asia', 'Europe', 'North America', 'Oceania', 'South America']Get all regions.
geography.getRegions();
// ['Northern Africa', 'Sub-Saharan Africa', 'Antarctica', 'Central Asia', ...]Import: import { membership } from '@koshmoney/countries/membership';
Check if country is an EU member (27 countries).
membership.isEU('FR'); // true
membership.isEU('CH'); // false (Switzerland)
membership.isEU('GB'); // false (post-Brexit)Check if country is in SEPA zone (36 countries).
membership.isSEPA('FR'); // true
membership.isSEPA('CH'); // true (Switzerland is SEPA)
membership.isSEPA('GB'); // true (UK remains in SEPA)Check if country is in EEA (30 countries).
membership.isEEA('NO'); // true (Norway)
membership.isEEA('CH'); // false (Switzerland not in EEA)Check if country uses the Euro (20 countries).
membership.isEurozone('DE'); // true
membership.isEurozone('SE'); // false (Sweden uses SEK)Check if country is in Schengen Area (27 countries).
membership.isSchengen('FR'); // true
membership.isSchengen('IE'); // false (Ireland not in Schengen)Get all membership statuses for a country.
membership.getMemberships('FR');
// { EU: true, SEPA: true, EEA: true, Eurozone: true, Schengen: true }
membership.getMemberships('CH');
// { EU: false, SEPA: true, EEA: false, Eurozone: false, Schengen: true }
membership.getMemberships('GB');
// { EU: false, SEPA: true, EEA: false, Eurozone: false, Schengen: false }Get all member countries of a specific group.
membership.getMembers('EU');
// ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK']
membership.getMembers('Eurozone');
// ['AT', 'BE', 'CY', 'DE', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PT', 'SI', 'SK']interface Country {
/** Full country name (e.g., "United States") */
name: string;
/** ISO 3166-1 alpha-2 code (e.g., "US") */
alpha2: string;
/** ISO 3166-1 alpha-3 code (e.g., "USA") */
alpha3: string;
/** ISO 3166-1 numeric code (e.g., "840") */
numeric: string;
}interface Subdivision {
/** Full ISO 3166-2 code (e.g., "US-CA") */
code: string;
/** Subdivision name (e.g., "California") */
name: string;
/** Subdivision type (e.g., "State", "Province", "County") */
type: string;
/** Country alpha-2 code (e.g., "US") */
countryCode: string;
/** Country name (e.g., "United States") */
countryName: string;
/** Region code without country prefix (e.g., "CA") */
regionCode: string;
}interface SubdivisionInfo {
/** Subdivision name */
name: string;
/** Subdivision type */
type: string;
}interface CountryWithSubdivisions extends Country {
/** All subdivisions indexed by full code */
subdivisions: Record<string, SubdivisionInfo>;
}type CountryCodeFormat = 'alpha2' | 'alpha3' | 'numeric';interface CurrencyInfo {
/** Currency code (e.g., "USD") */
code: string;
/** Currency symbol (e.g., "$") */
symbol: string;
/** Currency name (e.g., "US Dollar") */
name: string;
}interface DialCodeInfo {
/** Dial code with + prefix (e.g., "+1") */
dialCode: string;
/** Country alpha-2 code (e.g., "US") */
countryCode: string;
}interface GeographyInfo {
/** Continent name */
continent: Continent;
/** UN M49 region name */
region: Region;
}type Continent =
| 'Africa'
| 'Antarctica'
| 'Asia'
| 'Europe'
| 'North America'
| 'Oceania'
| 'South America';type Region =
| 'Northern Africa'
| 'Sub-Saharan Africa'
| 'Antarctica'
| 'Central Asia'
| 'Eastern Asia'
| 'South-eastern Asia'
| 'Southern Asia'
| 'Western Asia'
| 'Eastern Europe'
| 'Northern Europe'
| 'Southern Europe'
| 'Western Europe'
| 'Caribbean'
| 'Central America'
| 'Northern America'
| 'South America'
| 'Australia and New Zealand'
| 'Melanesia'
| 'Micronesia'
| 'Polynesia';interface MembershipInfo {
/** EU member state */
EU: boolean;
/** SEPA zone member */
SEPA: boolean;
/** EEA member */
EEA: boolean;
/** Eurozone member (uses Euro) */
Eurozone: boolean;
/** Schengen Area member */
Schengen: boolean;
}type MembershipType = 'EU' | 'SEPA' | 'EEA' | 'Eurozone' | 'Schengen';