Reference · Cities: lookups and loading (the tiers load on demand; the size counts every tier)
citySetfunction
Joins lists of cities (a tier's list, or several) into one set with the lookups built once. A city that is in more than one list is kept once, the first.
Import it
import { citySet } from "@johnmorrisdotca/kuni/cities";
Definition
function citySet(...lists: readonly (readonly City[])[]): CitySet
Parameters
| Name | Type | Description |
|---|---|---|
...lists | readonly (readonly City[])[] | Lists of cities, such as |
Returns
CitySet
The set, with byId, inCountry, inSubdivision, nearest and within; nothing in it can be changed.
Examples
import { citySet } from "@johnmorrisdotca/kuni/cities";
import { capitalCities } from "@johnmorrisdotca/kuni/cities/capitals";
const capitals = citySet(capitalCities());
console.log(capitals.byId("Q1490")?.country); // "JP"
console.log(capitals.inCountry("fr").some((one) => one.name.en === "Paris")); // true
console.log(capitals.nearest({ lat: 48.85, lon: 2.35 })?.city.name.en); // "Paris"
console.log(capitals.byId("Q0")); // nullJP
true
Paris
nullWhat it prints (run when this page was built)