countryByName関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
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 { countryByName } from "@johnmorrisdotca/kuni";
定義
function countryByName(text: string): Country | null
引数
| 名前 | 型 | 説明 |
|---|---|---|
text | string | What was typed. |
戻り値
Country | null
The country, frozen; null when nothing matches, never a near miss.
例
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
null出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。