本文へ移動

Kuni国

国、コード、名前、行政区画を調べ、必要なときに国のデータを読み込み、標準の国のカードを表示できます。

「国(くに)」は、国を表す日本語です。 名前について(英語)

目次

リファレンス · 場所:大陸の国と検索(サイズはすべての段階を含みます)

searchPlaces関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

What a person typed, found among countries and cities, best first. Names are compared folded (case, accents, width and kana set aside, as fold does) over the English, Japanese and native names, and over a country's reading in kana; a city's Japanese name is found as it is written (パリ, 東京), since no source gives a city's reading. A match is ranked: the whole name, then the start of the name, then the start of a word in it, then anywhere in it; among equal matches the more populous place comes first. Only the tiers asked for are loaded (by default the capitals and the cities of 100,000 or more); with country, that country's cities, every tier, and no countries.

インポート

import { searchPlaces } from "@johnmorrisdotca/kuni/places";

定義

function searchPlaces(text: string, options?: SearchPlacesOptions): Promise<PlaceHit[]>

引数

名前型説明
textstring

What somebody typed; empty or all punctuation finds nothing.

options (省略可)SearchPlacesOptions

The language of the labels, how many, and which cities to look in.

戻り値

Promise<PlaceHit[]>

The hits, countries and cities mixed, best first.

例

import { searchPlaces } from "@johnmorrisdotca/kuni/places";

const found = await searchPlaces("paris");
console.log(found[0].kind);                                 // "city"
console.log(found.some((one) => one.kind === "city" && one.city.country === "FR")); // true
console.log((await searchPlaces("にほん", { lang: "ja" }))[0].label); // "日本"
console.log((await searchPlaces("  ")).length);             // 0
city
true
日本
0

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/kuni 1.19.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。