Reference · Places: countries of a continent, and search (the size counts every tier)
searchPlacesfunction
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 it
import { searchPlaces } from "@johnmorrisdotca/kuni/places";
Definition
function searchPlaces(text: string, options?: SearchPlacesOptions): Promise<PlaceHit[]>
Parameters
| Name | Type | Description |
|---|---|---|
text | string | What somebody typed; empty or all punctuation finds nothing. |
options (optional) | SearchPlacesOptions | The language of the labels, how many, and which cities to look in. |
Returns
Promise<PlaceHit[]>
The hits, countries and cities mixed, best first.
Examples
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); // 0city
true
日本
0What it prints (run when this page was built)