Reference · Cities: lookups and loading (the tiers load on demand; the size counts every tier)
cityByIdfunction
One city, by its id: a Wikidata item ("Q90") or "ne:<number>", in either case; an id that was merged into another city answers with the city it became. The capitals, 1m and 100k tiers are loaded one at a time until the city is found; a smaller city is looked up in a small index of which country each is in, and only that country's file is fetched. An id that is nobody's loads the three tiers and the index, never every country.
Import it
import { cityById } from "@johnmorrisdotca/kuni/cities";
Definition
function cityById(id: string): Promise<City | null>
Parameters
| Name | Type | Description |
|---|---|---|
id | string | The city's id. |
Returns
Promise<City | null>
The city, frozen; null where no tier has it.
Examples
import { cityById } from "@johnmorrisdotca/kuni/cities";
const paris = await cityById("Q90");
console.log(paris?.name.en); // "Paris"
console.log(paris?.continent); // "EU"
console.log(await cityById("Q0")); // nullParis
EU
nullWhat it prints (run when this page was built)