UNPKG

kenya-locations

Version:

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

99 lines (98 loc) 2.75 kB
var p = Object.defineProperty; var h = (t, e, n) => e in t ? p(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; var m = (t, e, n) => h(t, typeof e != "symbol" ? e + "" : e, n); import { c as u } from "./constituencies-CpiSuj07.js"; import { w as s } from "./wards-CGdGn1Pj.js"; import { c as C } from "./counties-CIvO8NBl.js"; import { a as w } from "./LocationErrors-oHe-kZTW.js"; import { b as o, a as L } from "./maps-Bqmru5Ek.js"; const d = o(u, (t) => t.code), y = o( u, (t) => t.name.toLowerCase() ), c = o(C, (t) => t.name.toLowerCase()), _ = o(s, (t) => t.name.toLowerCase()), M = o(s, (t) => t.code), i = L(s, (t) => t.constituency); class f { constructor(e) { m(this, "_data"); this._data = e; } /** Get the constituency code */ get code() { return this._data.code; } /** Get the constituency name */ get name() { return this._data.name; } /** Get the county this constituency belongs to */ get county() { return this._data.county; } /** Get all data for the constituency */ get data() { return { ...this._data }; } /** * Get all wards in this constituency */ wards() { return i.get(this._data.name) ?? []; } /** * Get a ward in this constituency by name or code */ ward(e) { const n = M.get(e); if ((n == null ? void 0 : n.constituency) === this._data.name) return n; const a = _.get(e.toLowerCase()); if ((a == null ? void 0 : a.constituency) === this._data.name) return a; const r = s.filter( (g) => g.constituency === this._data.name && g.name.toLowerCase() === e.toLowerCase() ); if (r.length === 0) throw new w( `Ward '${e}' not found in constituency '${this._data.name}'` ); if (r.length > 1) throw new w( `Multiple wards named '${e}' found in constituency '${this._data.name}'. Use specific ward code instead.` ); return r[0]; } /** * Get the county this constituency belongs to */ getCounty() { return c.get(this._data.county.toLowerCase()); } } function B() { return u; } function k(t) { const e = d.get(t); return e ? new f(e) : void 0; } function x(t) { const e = y.get(t.toLowerCase()); return e ? new f(e) : void 0; } function E(t) { const e = i.get(t); if (e) return e; const n = d.get(t); return n ? i.get(n.name) ?? [] : []; } function G(t) { const e = y.get(t.toLowerCase()); if (e) return c.get(e.county.toLowerCase()); const n = d.get(t); return n ? c.get(n.county.toLowerCase()) : void 0; } export { f as ConstituencyWrapper, B as getConstituencies, k as getConstituencyByCode, x as getConstituencyByName, G as getCountyOfConstituency, E as getWardsInConstituency };