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) • 9.55 kB
JavaScript
"use strict";var bt=Object.defineProperty;var mt=(t,e,o)=>e in t?bt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var r=(t,e,o)=>mt(t,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./counties-D9ZfM1Ad.cjs"),f=require("./constituencies-HrhCXHyg.cjs"),C=require("./wards-BHJ3nhLv.cjs"),w=require("./sub-counties-BGJlbhdB.cjs"),c=require("./area-zfFmEagr.cjs"),k=require("./search-NYp3IIQS.cjs"),a=require("./maps-B_hwSl98.cjs"),i=require("./LocationErrors-B_UyK2xz.cjs"),Bt=require("./version.cjs"),l=a.buildLookupMap(M.counties,t=>t.code),s=a.buildLookupMap(M.counties,t=>t.name.toLowerCase()),Mt=a.buildGroupMap(c.areas,t=>t.name.toLowerCase()),W=a.buildLookupMap(f.constituencies,t=>t.code),p=a.buildLookupMap(f.constituencies,t=>t.name.toLowerCase()),L=a.buildLookupMap(C.wards,t=>t.code),h=a.buildLookupMap(C.wards,t=>t.name.toLowerCase()),N=a.buildLookupMap(c.localities,t=>t.name.toLowerCase()),T=a.buildLookupMap(c.areas,t=>t.name.toLowerCase()),S=a.buildGroupMap(f.constituencies,t=>{var e;return(e=s.get(t.county.toLowerCase()))==null?void 0:e.code}),Wt=new Map(f.constituencies.flatMap(t=>{var o;const e=(o=s.get(t.county.toLowerCase()))==null?void 0:o.code;return e?[[t.code,e],[t.name,e]]:[]})),E=a.buildGroupMap(C.wards,t=>t.constituency),m=a.buildGroupMap(C.wards,t=>{var o;const e=p.get(t.constituency.toLowerCase());return e?(o=s.get(e.county.toLowerCase()))==null?void 0:o.code:void 0}),B=a.buildGroupMap(c.localities,t=>t.county),q=a.buildGroupMap(c.areas,t=>t.locality),O=a.buildGroupMap(c.areas,t=>t.county),F=a.buildLookupMap(w.subCounties,t=>t.code),I=a.buildLookupMap(w.subCounties,t=>t.name.toLowerCase()),Nt=a.buildGroupMap(w.subCounties,t=>{var e;return(e=s.get(t.county.toLowerCase()))==null?void 0:e.code});class y{constructor(e){r(this,"_data");this._data=e}get name(){return this._data.name}get county(){return this._data.county}get data(){return{...this._data}}getCounty(){const e=s.get(this._data.county.toLowerCase());return e?new A(e):void 0}areas(){return q.get(this._data.name)??[]}area(e){const o=this.areas().find(u=>u.name.toLowerCase()===e.toLowerCase());if(o)return o;throw new i.LocationNotFoundError("Area",e)}}class A{constructor(e){r(this,"_data");this._data=e}get code(){return this._data.code}get name(){return this._data.name}get data(){return{...this._data}}constituencies(){return(S.get(this._data.code)??[]).map(e=>new g(e))}constituency(e){const o=W.get(e);if((o==null?void 0:o.county)===this._data.name)return new g(o);const u=p.get(e.toLowerCase());if((u==null?void 0:u.county)===this._data.name)return new g(u);const d=(S.get(this._data.code)??[]).find(b=>b.name.toLowerCase()===e.toLowerCase());if(d)return new g(d);throw new i.LocationNotFoundError("Constituency",e)}wards(){return m.get(this._data.code)??[]}localities(){return(B.get(this._data.name)??[]).map(e=>new y(e))}locality(e){const o=(B.get(this._data.name)??[]).find(u=>u.name.toLowerCase()===e.toLowerCase());if(o)return new y(o);throw new i.LocationNotFoundError("Locality",e)}areas(){return O.get(this._data.name)??[]}areasByLocality(e){return this.areas().filter(o=>o.locality.toLowerCase()===e.toLowerCase())}}class g{constructor(e){r(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}}getCounty(){const e=s.get(this._data.county.toLowerCase());return e?new A(e):void 0}ward(e){const o=L.get(e);if((o==null?void 0:o.constituency)===this._data.name)return o;const u=h.get(e.toLowerCase());if((u==null?void 0:u.constituency)===this._data.name)return u;const d=C.wards.filter(b=>b.constituency===this._data.name&&b.name.toLowerCase()===e.toLowerCase());if(d.length===0)throw new i.LocationNotFoundError("Ward",e);if(d.length>1)throw new i.LocationError(`Multiple wards named '${e}' found in constituency '${this._data.name}'. Use specific ward code instead.`);return d[0]}wards(){return E.get(this._data.name)??[]}}function G(){return M.counties}function D(){return w.subCounties}function V(){return C.wards}function $(){return c.localities}function R(){return c.areas}function j(t){return l.get(t)}function P(t){const e=N.get(t.toLowerCase());return e?new y(e):void 0}function U(t){return c.localities.filter(e=>e.name.toLowerCase()===t.toLowerCase()).map(e=>new y(e))}function x(t){return T.get(t.toLowerCase())}function z(t){return B.get(t)??[]}function H(t){return q.get(t)??[]}function J(t){return O.get(t)??[]}function Q(t){const e=N.get(t.toLowerCase());if(e)return s.get(e.county.toLowerCase())}function X(t){const e=T.get(t.toLowerCase());if(e)return s.get(e.county.toLowerCase())}function Y(t){const e=T.get(t.toLowerCase());if(e)return N.get(e.locality.toLowerCase())}function Z(t){const e=l.get(t)??s.get(t.toLowerCase());return e?Nt.get(e.code)??[]:[]}function _(t){const e=F.get(t)??I.get(t.toLowerCase());return e?C.wards.filter(o=>o.constituency.toLowerCase()===e.name.toLowerCase()):[]}function K(t){const e=I.get(t.toLowerCase());return e?s.get(e.county.toLowerCase()):void 0}function tt(t){const e=L.get(t)??h.get(t.toLowerCase());if(!e)return;const o=Wt.get(e.constituency);return o?l.get(o):void 0}function et(t){const e=l.get(t)??s.get(t.toLowerCase());return e?new A(e):void 0}function ot(t,e){if(e){const u=(B.get(e)??[]).find(d=>d.name.toLowerCase()===t.toLowerCase());return u?new y(u):void 0}const o=N.get(t.toLowerCase());return o?new y(o):void 0}function nt(){return f.constituencies}function rt(t){const e=W.get(t);return e?new g(e):void 0}function at(t){if(m.has(t))return m.get(t)??[];const e=s.get(t.toLowerCase());return e?m.get(e.code)??[]:[]}function ut(t,e={}){return k.search(t,e)}function st(t,e,o){return k.searchByType(t,e,o)}function it(t){const e=E.get(t);if(e)return e;const o=W.get(t);return o?E.get(o.name)??[]:[]}function ct(t){const e=p.get(t.toLowerCase());if(e)return s.get(e.county.toLowerCase());const o=W.get(t);return o?s.get(o.county.toLowerCase()):void 0}function gt(t){return s.get(t.toLowerCase())}function dt(t){const e=p.get(t.toLowerCase());return e?new g(e):void 0}function Ct(t){return L.get(t)}function yt(t){return h.get(t.toLowerCase())}function ft(t){return F.get(t)}function wt(t){return I.get(t.toLowerCase())}function lt(t){const e=l.get(t)??s.get(t.toLowerCase());return e?(S.get(e.code)??[]).map(o=>new g(o)):[]}function pt(t){const e=L.get(t)??h.get(t.toLowerCase());if(!e)return;const o=p.get(e.constituency.toLowerCase());return o?new g(o):void 0}function Lt(t){const e=L.get(t)??h.get(t.toLowerCase());if(e)return I.get(e.constituency.toLowerCase())}function ht(t){return Mt.get(t.toLowerCase())??[]}const n=class n{static getInstance(){return n.instance||(n.instance=new n),n.instance}};r(n,"instance"),r(n,"getCounties",G),r(n,"getSubCounties",D),r(n,"getWards",V),r(n,"getLocalities",$),r(n,"getAreas",R),r(n,"getCountyByCode",j),r(n,"getLocalityByName",P),r(n,"getLocalitiesByName",U),r(n,"getAreaByName",x),r(n,"getLocalitiesInCounty",z),r(n,"getAreasInLocality",H),r(n,"getAreasInCounty",J),r(n,"getCountyOfLocality",Q),r(n,"getCountyOfArea",X),r(n,"getLocalityOfArea",Y),r(n,"getSubCountiesInCounty",Z),r(n,"getWardsInSubCounty",_),r(n,"getCountyOfSubCounty",K),r(n,"getCountyOfWard",tt),r(n,"county",et),r(n,"locality",ot),r(n,"getConstituencies",nt),r(n,"getConstituencyByCode",rt),r(n,"getConstituencyByName",dt),r(n,"getConstituenciesInCounty",lt),r(n,"getConstituencyOfWard",pt),r(n,"getSubCountyOfWard",Lt),r(n,"getWardsInCounty",at),r(n,"getWardByCode",Ct),r(n,"getWardByName",yt),r(n,"getSubCountyByCode",ft),r(n,"getSubCountyByName",wt),r(n,"getCountyByName",gt),r(n,"getAreasByName",ht),r(n,"search",ut),r(n,"searchByType",st),r(n,"getWardsInConstituency",it),r(n,"getCountyOfConstituency",ct);let v=n;exports.counties=M.counties;exports.constituencies=f.constituencies;exports.wards=C.wards;exports.subCounties=w.subCounties;exports.areas=c.areas;exports.localities=c.localities;exports.ConfigurationError=i.ConfigurationError;exports.DataValidationError=i.DataValidationError;exports.InvalidLocationCodeError=i.InvalidLocationCodeError;exports.KenyaLocationsError=i.LocationError;exports.LocationError=i.LocationError;exports.LocationNotFoundError=i.LocationNotFoundError;exports.NotFoundError=i.LocationNotFoundError;exports.SearchError=i.SearchError;exports.DATA_VERSION=Bt.DATA_VERSION;exports.ConstituencyWrapper=g;exports.CountyWrapper=A;exports.KenyaLocations=v;exports.LocalityWrapper=y;exports.county=et;exports.getAreaByName=x;exports.getAreas=R;exports.getAreasByName=ht;exports.getAreasInCounty=J;exports.getAreasInLocality=H;exports.getConstituencies=nt;exports.getConstituenciesInCounty=lt;exports.getConstituencyByCode=rt;exports.getConstituencyByName=dt;exports.getConstituencyOfWard=pt;exports.getCounties=G;exports.getCountyByCode=j;exports.getCountyByName=gt;exports.getCountyOfArea=X;exports.getCountyOfConstituency=ct;exports.getCountyOfLocality=Q;exports.getCountyOfSubCounty=K;exports.getCountyOfWard=tt;exports.getLocalities=$;exports.getLocalitiesByName=U;exports.getLocalitiesInCounty=z;exports.getLocalityByName=P;exports.getLocalityOfArea=Y;exports.getSubCounties=D;exports.getSubCountiesInCounty=Z;exports.getSubCountyByCode=ft;exports.getSubCountyByName=wt;exports.getSubCountyOfWard=Lt;exports.getWardByCode=Ct;exports.getWardByName=yt;exports.getWards=V;exports.getWardsInConstituency=it;exports.getWardsInCounty=at;exports.getWardsInSubCounty=_;exports.locality=ot;exports.search=ut;exports.searchByType=st;