Two-letter country code (e.g. "US", "GB")
The matching country record, or undefined if the code is unknown
findCountryByIso2("US")?.name // "United States"
findCountryByIso2("US")?.currency?.code // "USD"
findCountryByIso2("ZZ") // undefined
export function findCountryByIso2(iso2: string): CountryRecord | undefined {
if (!Object.hasOwn(COUNTRY_DATA, iso2)) {
return undefined;
}
const [name, currency] = COUNTRY_DATA[iso2];
return { name, currency: currency ? { code: currency } : undefined };
}
Looks up a country record by its two-letter ISO 3166-1 alpha-2 code. Codes are case-sensitive and upper-case, as in COUNTRY_DATA.