Reference · Countries and lookup tools
countryByNamefunction
A country from what somebody typed: its name or short name in English or Japanese ("Germany", ドイツ, どいつ), its own name ("Deutschland"), a name it is also known by ("Holland", "UK", 米国), or a code. Case, accents, width, kana and punctuation do not matter.
Import it
import { countryByName } from "@johnmorrisdotca/kuni";
Definition
function countryByName(text: string): Country | null
Parameters
| Name | Type | Description |
|---|---|---|
text | string | What was typed. |
Returns
Country | null
The country, frozen; null when nothing matches, never a near miss.
Examples
import { countryByName } from "@johnmorrisdotca/kuni";
console.log(countryByName("ドイツ")?.alpha2); // "DE"
console.log(countryByName("Holland")?.name.ja); // "オランダ"
console.log(countryByName("USA")?.alpha2); // "US"
console.log(countryByName("cote d'ivoire")?.alpha2); // "CI"
console.log(countryByName("Narnia")); // nullDE
オランダ
US
CI
nullWhat it prints (run when this page was built)