Reference · Countries and lookup tools
countryfunction
One country by its code.
Import it
import { country } from "@johnmorrisdotca/kuni";
Definition
function country(code: string): Country | null
Parameters
| Name | Type | Description |
|---|---|---|
code | string | Alpha-2 ("JP", "jp"), alpha-3 ("JPN") or numeric ("392"). |
Returns
Country | null
The country, frozen; null for anything that is not one of the 250 codes.
Examples
import { country } from "@johnmorrisdotca/kuni";
console.log(country("JP")?.name.en); // "Japan"
console.log(country("jpn")?.alpha2); // "JP"
console.log(country("392")?.name.ja); // "日本"
console.log(country("JP")?.capital); // { "en": "Tokyo", "ja": "東京" }
console.log(country("XX")); // nullJapan
JP
日本
{ en: 'Tokyo', ja: '東京' }
nullWhat it prints (run when this page was built)