kenya-locations
Version:
A comprehensive and intuitive TypeScript package for working with Kenyan administrative divisions (counties, sub-counties, constituencies, and wards)
2 lines (1 loc) • 2.17 kB
JavaScript
;var f=Object.defineProperty;var L=(t,e,n)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var w=(t,e,n)=>L(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./constituencies-HrhCXHyg.cjs"),a=require("./wards-BHJ3nhLv.cjs"),h=require("./counties-D9ZfM1Ad.cjs"),p=require("./LocationErrors-B_UyK2xz.cjs"),o=require("./maps-B_hwSl98.cjs"),d=o.buildLookupMap(u.constituencies,t=>t.code),C=o.buildLookupMap(u.constituencies,t=>t.name.toLowerCase()),c=o.buildLookupMap(h.counties,t=>t.name.toLowerCase()),m=o.buildLookupMap(a.wards,t=>t.name.toLowerCase()),l=o.buildLookupMap(a.wards,t=>t.code),i=o.buildGroupMap(a.wards,t=>t.constituency);class y{constructor(e){w(this,"_data");this._data=e}get code(){return this._data.code}get name(){return this._data.name}get county(){return this._data.county}get data(){return{...this._data}}wards(){return i.get(this._data.name)??[]}ward(e){const n=l.get(e);if((n==null?void 0:n.constituency)===this._data.name)return n;const s=m.get(e.toLowerCase());if((s==null?void 0:s.constituency)===this._data.name)return s;const r=a.wards.filter(g=>g.constituency===this._data.name&&g.name.toLowerCase()===e.toLowerCase());if(r.length===0)throw new p.LocationError(`Ward '${e}' not found in constituency '${this._data.name}'`);if(r.length>1)throw new p.LocationError(`Multiple wards named '${e}' found in constituency '${this._data.name}'. Use specific ward code instead.`);return r[0]}getCounty(){return c.get(this._data.county.toLowerCase())}}function M(){return u.constituencies}function _(t){const e=d.get(t);return e?new y(e):void 0}function b(t){const e=C.get(t.toLowerCase());return e?new y(e):void 0}function W(t){const e=i.get(t);if(e)return e;const n=d.get(t);return n?i.get(n.name)??[]:[]}function k(t){const e=C.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}exports.ConstituencyWrapper=y;exports.getConstituencies=M;exports.getConstituencyByCode=_;exports.getConstituencyByName=b;exports.getCountyOfConstituency=k;exports.getWardsInConstituency=W;