UNPKG

kenya-locations

Version:

A comprehensive and intuitive TypeScript package for working with Kenyan administrative divisions (counties, sub-counties, constituencies, and wards)

88 lines (87 loc) 2.2 kB
var f = Object.defineProperty; var w = (t, o, e) => o in t ? f(t, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[o] = e; var s = (t, o, e) => w(t, typeof o != "symbol" ? o + "" : o, e); import { l as r, a as y } from "./area-DZRgJy_F.js"; import { c as m } from "./counties-CIvO8NBl.js"; import { L as g } from "./LocationErrors-oHe-kZTW.js"; import { b as c, a as u } from "./maps-Bqmru5Ek.js"; const i = c(r, (t) => t.name.toLowerCase()), l = c(m, (t) => t.name.toLowerCase()), L = u(r, (t) => t.county), p = u(y, (t) => t.locality); class n { constructor(o) { s(this, "_data"); this._data = o; } /** Get the locality name */ get name() { return this._data.name; } /** Get the county this locality belongs to */ get county() { return this._data.county; } /** Get all data for the locality */ get data() { return { ...this._data }; } /** * Get all areas in this locality */ areas() { return p.get(this._data.name) ?? []; } /** * Get an area by name * @param name Name of the area * @throws LocationNotFoundError if not found */ area(o) { const e = this.areas().find( (a) => a.name.toLowerCase() === o.toLowerCase() ); if (e) return e; throw new g("Area", o); } /** * Get the county this locality belongs to */ getCounty() { return l.get(this._data.county.toLowerCase()); } } function N() { return r; } function b(t) { const o = i.get(t.toLowerCase()); return o ? new n(o) : void 0; } function A(t) { return L.get(t) ?? []; } function B(t) { const o = i.get(t.toLowerCase()); if (o) return l.get(o.county.toLowerCase()); } function T(t) { return r.filter((o) => o.name.toLowerCase() === t.toLowerCase()).map((o) => new n(o)); } function k(t, o) { if (o) { const a = (L.get(o) ?? []).find( (d) => d.name.toLowerCase() === t.toLowerCase() ); return a ? new n(a) : void 0; } const e = i.get(t.toLowerCase()); return e ? new n(e) : void 0; } export { n as LocalityWrapper, B as getCountyOfLocality, N as getLocalities, T as getLocalitiesByName, A as getLocalitiesInCounty, b as getLocalityByName, k as locality };