kenya-locations
Version:
A comprehensive and intuitive TypeScript package for working with Kenyan administrative divisions (counties, sub-counties, constituencies, and wards)
458 lines (457 loc) • 12.3 kB
JavaScript
var k = Object.defineProperty;
var G = (t, e, o) => e in t ? k(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
var r = (t, e, o) => G(t, typeof e != "symbol" ? e + "" : e, o);
import { c as T } from "./counties-CIvO8NBl.js";
import { c as f } from "./constituencies-CpiSuj07.js";
import { w as C } from "./wards-CGdGn1Pj.js";
import { s as W } from "./sub-counties-Crb1ccMT.js";
import { l as b, a as y } from "./area-DZRgJy_F.js";
import { s as R, a as U } from "./search-CA4wlLsI.js";
import { b as u, a as g } from "./maps-Bqmru5Ek.js";
import { L as B, a as j } from "./LocationErrors-oHe-kZTW.js";
import { C as Ut, D as jt, I as qt, S as zt } from "./LocationErrors-oHe-kZTW.js";
import { DATA_VERSION as Jt } from "./version.js";
const w = u(T, (t) => t.code), s = u(T, (t) => t.name.toLowerCase()), q = g(y, (t) => t.name.toLowerCase()), v = u(f, (t) => t.code), m = u(
f,
(t) => t.name.toLowerCase()
), l = u(C, (t) => t.code), p = u(C, (t) => t.name.toLowerCase()), I = u(b, (t) => t.name.toLowerCase()), E = u(y, (t) => t.name.toLowerCase()), N = g(
f,
(t) => {
var e;
return (e = s.get(t.county.toLowerCase())) == null ? void 0 : e.code;
}
), z = new Map(
f.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]] : [];
})
), S = g(C, (t) => t.constituency), L = g(C, (t) => {
var o;
const e = m.get(t.constituency.toLowerCase());
return e ? (o = s.get(e.county.toLowerCase())) == null ? void 0 : o.code : void 0;
}), M = g(b, (t) => t.county), D = g(y, (t) => t.locality), F = g(y, (t) => t.county), V = u(W, (t) => t.code), A = u(
W,
(t) => t.name.toLowerCase()
), H = g(
W,
(t) => {
var e;
return (e = s.get(t.county.toLowerCase())) == null ? void 0 : e.code;
}
);
class d {
constructor(e) {
r(this, "_data");
this._data = e;
}
/** 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 the county this locality belongs to
* @returns CountyWrapper or undefined if not found
*/
getCounty() {
const e = s.get(this._data.county.toLowerCase());
return e ? new $(e) : void 0;
}
/**
* Get all areas in this locality
* @returns Array of Area
*/
areas() {
return D.get(this._data.name) ?? [];
}
/**
* Get an area by name
* @param name Name of the area
* @throws LocationNotFoundError if not found
*/
area(e) {
const o = this.areas().find(
(a) => a.name.toLowerCase() === e.toLowerCase()
);
if (o) return o;
throw new B("Area", e);
}
}
class $ {
constructor(e) {
r(this, "_data");
this._data = e;
}
/** Get the county code */
get code() {
return this._data.code;
}
/** Get the county name */
get name() {
return this._data.name;
}
/** Get all data for the county */
get data() {
return { ...this._data };
}
/**
* Get all constituencies in this county
* @returns Array of ConstituencyWrapper
*/
constituencies() {
return (N.get(this._data.code) ?? []).map(
(e) => new i(e)
);
}
/**
* Get a constituency by name or code
* @param nameOrCode Name or code of the constituency
* @throws LocationNotFoundError if not found
*/
constituency(e) {
const o = v.get(e);
if ((o == null ? void 0 : o.county) === this._data.name)
return new i(o);
const a = m.get(e.toLowerCase());
if ((a == null ? void 0 : a.county) === this._data.name)
return new i(a);
const c = (N.get(this._data.code) ?? []).find(
(h) => h.name.toLowerCase() === e.toLowerCase()
);
if (c) return new i(c);
throw new B("Constituency", e);
}
/**
* Get all wards in this county
* @returns Array of Ward
*/
wards() {
return L.get(this._data.code) ?? [];
}
/**
* Get all localities in this county
* @returns Array of LocalityWrapper
*/
localities() {
return (M.get(this._data.name) ?? []).map(
(e) => new d(e)
);
}
/**
* Get a locality by name
* @param name Name of the locality
* @throws LocationNotFoundError if not found
*/
locality(e) {
const o = (M.get(this._data.name) ?? []).find(
(a) => a.name.toLowerCase() === e.toLowerCase()
);
if (o) return new d(o);
throw new B("Locality", e);
}
/**
* Get all areas in this county
* @returns Array of Area
*/
areas() {
return F.get(this._data.name) ?? [];
}
/**
* Get areas by locality name
* @param localityName Name of the locality
* @returns Array of Area
*/
areasByLocality(e) {
return this.areas().filter(
(o) => o.locality.toLowerCase() === e.toLowerCase()
);
}
}
class i {
constructor(e) {
r(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 the county this constituency belongs to
* @returns CountyWrapper
*/
getCounty() {
const e = s.get(this._data.county.toLowerCase());
return e ? new $(e) : void 0;
}
/**
* Get a ward in this constituency by name or code
*/
ward(e) {
const o = l.get(e);
if ((o == null ? void 0 : o.constituency) === this._data.name) return o;
const a = p.get(e.toLowerCase());
if ((a == null ? void 0 : a.constituency) === this._data.name) return a;
const c = C.filter(
(h) => h.constituency === this._data.name && h.name.toLowerCase() === e.toLowerCase()
);
if (c.length === 0)
throw new B("Ward", e);
if (c.length > 1)
throw new j(
`Multiple wards named '${e}' found in constituency '${this._data.name}'. Use specific ward code instead.`
);
return c[0];
}
/**
* Get all wards in this constituency
*/
wards() {
return S.get(this._data.name) ?? [];
}
}
function J() {
return T;
}
function P() {
return W;
}
function Q() {
return C;
}
function X() {
return b;
}
function Y() {
return y;
}
function Z(t) {
return w.get(t);
}
function O(t) {
const e = I.get(t.toLowerCase());
return e ? new d(e) : void 0;
}
function _(t) {
return b.filter((e) => e.name.toLowerCase() === t.toLowerCase()).map((e) => new d(e));
}
function K(t) {
return E.get(t.toLowerCase());
}
function tt(t) {
return M.get(t) ?? [];
}
function et(t) {
return D.get(t) ?? [];
}
function ot(t) {
return F.get(t) ?? [];
}
function nt(t) {
const e = I.get(t.toLowerCase());
if (e)
return s.get(e.county.toLowerCase());
}
function rt(t) {
const e = E.get(t.toLowerCase());
if (e)
return s.get(e.county.toLowerCase());
}
function at(t) {
const e = E.get(t.toLowerCase());
if (e)
return I.get(e.locality.toLowerCase());
}
function st(t) {
const e = w.get(t) ?? s.get(t.toLowerCase());
return e ? H.get(e.code) ?? [] : [];
}
function ut(t) {
const e = V.get(t) ?? A.get(t.toLowerCase());
return e ? C.filter(
(o) => o.constituency.toLowerCase() === e.name.toLowerCase()
) : [];
}
function ct(t) {
const e = A.get(t.toLowerCase());
return e ? s.get(e.county.toLowerCase()) : void 0;
}
function it(t) {
const e = l.get(t) ?? p.get(t.toLowerCase());
if (!e) return;
const o = z.get(e.constituency);
return o ? w.get(o) : void 0;
}
function gt(t) {
const e = w.get(t) ?? s.get(t.toLowerCase());
return e ? new $(e) : void 0;
}
function Ct(t, e) {
if (e) {
const a = (M.get(e) ?? []).find(
(c) => c.name.toLowerCase() === t.toLowerCase()
);
return a ? new d(a) : void 0;
}
const o = I.get(t.toLowerCase());
return o ? new d(o) : void 0;
}
function dt() {
return f;
}
function ft(t) {
const e = v.get(t);
return e ? new i(e) : void 0;
}
function yt(t) {
if (L.has(t))
return L.get(t) ?? [];
const e = s.get(t.toLowerCase());
return e ? L.get(e.code) ?? [] : [];
}
function wt(t, e = {}) {
return R(t, e);
}
function mt(t, e, o) {
return U(t, e, o);
}
function lt(t) {
const e = S.get(t);
if (e) return e;
const o = v.get(t);
return o ? S.get(o.name) ?? [] : [];
}
function pt(t) {
const e = m.get(t.toLowerCase());
if (e) return s.get(e.county.toLowerCase());
const o = v.get(t);
return o ? s.get(o.county.toLowerCase()) : void 0;
}
function ht(t) {
return s.get(t.toLowerCase());
}
function Lt(t) {
const e = m.get(t.toLowerCase());
return e ? new i(e) : void 0;
}
function Bt(t) {
return l.get(t);
}
function Mt(t) {
return p.get(t.toLowerCase());
}
function Wt(t) {
return V.get(t);
}
function bt(t) {
return A.get(t.toLowerCase());
}
function vt(t) {
const e = w.get(t) ?? s.get(t.toLowerCase());
return e ? (N.get(e.code) ?? []).map(
(o) => new i(o)
) : [];
}
function It(t) {
const e = l.get(t) ?? p.get(t.toLowerCase());
if (!e) return;
const o = m.get(e.constituency.toLowerCase());
return o ? new i(o) : void 0;
}
function At(t) {
const e = l.get(t) ?? p.get(t.toLowerCase());
if (e)
return A.get(e.constituency.toLowerCase());
}
function Nt(t) {
return q.get(t.toLowerCase()) ?? [];
}
const n = class n {
/**
* Get the singleton instance of KenyaLocations
*/
static getInstance() {
return n.instance || (n.instance = new n()), n.instance;
}
};
r(n, "instance"), r(n, "getCounties", J), r(n, "getSubCounties", P), r(n, "getWards", Q), r(n, "getLocalities", X), r(n, "getAreas", Y), r(n, "getCountyByCode", Z), r(n, "getLocalityByName", O), r(n, "getLocalitiesByName", _), r(n, "getAreaByName", K), r(n, "getLocalitiesInCounty", tt), r(n, "getAreasInLocality", et), r(n, "getAreasInCounty", ot), r(n, "getCountyOfLocality", nt), r(n, "getCountyOfArea", rt), r(n, "getLocalityOfArea", at), r(n, "getSubCountiesInCounty", st), r(n, "getWardsInSubCounty", ut), r(n, "getCountyOfSubCounty", ct), r(n, "getCountyOfWard", it), r(n, "county", gt), r(n, "locality", Ct), r(n, "getConstituencies", dt), r(n, "getConstituencyByCode", ft), r(n, "getConstituencyByName", Lt), r(n, "getConstituenciesInCounty", vt), r(n, "getConstituencyOfWard", It), r(n, "getSubCountyOfWard", At), r(n, "getWardsInCounty", yt), r(n, "getWardByCode", Bt), r(n, "getWardByName", Mt), r(n, "getSubCountyByCode", Wt), r(n, "getSubCountyByName", bt), r(n, "getCountyByName", ht), r(n, "getAreasByName", Nt), r(n, "search", wt), r(n, "searchByType", mt), r(n, "getWardsInConstituency", lt), r(n, "getCountyOfConstituency", pt);
let x = n;
export {
Ut as ConfigurationError,
i as ConstituencyWrapper,
$ as CountyWrapper,
Jt as DATA_VERSION,
jt as DataValidationError,
qt as InvalidLocationCodeError,
x as KenyaLocations,
j as KenyaLocationsError,
d as LocalityWrapper,
j as LocationError,
B as LocationNotFoundError,
B as NotFoundError,
zt as SearchError,
y as areas,
f as constituencies,
T as counties,
gt as county,
K as getAreaByName,
Y as getAreas,
Nt as getAreasByName,
ot as getAreasInCounty,
et as getAreasInLocality,
dt as getConstituencies,
vt as getConstituenciesInCounty,
ft as getConstituencyByCode,
Lt as getConstituencyByName,
It as getConstituencyOfWard,
J as getCounties,
Z as getCountyByCode,
ht as getCountyByName,
rt as getCountyOfArea,
pt as getCountyOfConstituency,
nt as getCountyOfLocality,
ct as getCountyOfSubCounty,
it as getCountyOfWard,
X as getLocalities,
_ as getLocalitiesByName,
tt as getLocalitiesInCounty,
O as getLocalityByName,
at as getLocalityOfArea,
P as getSubCounties,
st as getSubCountiesInCounty,
Wt as getSubCountyByCode,
bt as getSubCountyByName,
At as getSubCountyOfWard,
Bt as getWardByCode,
Mt as getWardByName,
Q as getWards,
lt as getWardsInConstituency,
yt as getWardsInCounty,
ut as getWardsInSubCounty,
b as localities,
Ct as locality,
wt as search,
mt as searchByType,
W as subCounties,
C as wards
};