kenya-locations
Version:
A comprehensive and intuitive TypeScript package for working with Kenyan administrative divisions (counties, sub-counties, constituencies, and wards)
125 lines (124 loc) • 3.16 kB
JavaScript
var L = Object.defineProperty;
var l = (o, t, e) => t in o ? L(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
var y = (o, t, e) => l(o, typeof t != "symbol" ? t + "" : t, e);
import { c as i } from "./counties-CIvO8NBl.js";
import { c as u } from "./constituencies-CpiSuj07.js";
import { l as h, a as _ } from "./area-DZRgJy_F.js";
import { w as M } from "./wards-CGdGn1Pj.js";
import { b as a, a as r } from "./maps-Bqmru5Ek.js";
import { L as p } from "./LocationErrors-oHe-kZTW.js";
import { ConstituencyWrapper as c } from "./constituencies.js";
import { LocalityWrapper as m } from "./localities.js";
const g = a(i, (o) => o.code), s = a(i, (o) => o.name.toLowerCase()), N = a(u, (o) => o.code), T = a(
u,
(o) => o.name.toLowerCase()
), w = r(
u,
(o) => {
var t;
return (t = s.get(o.county.toLowerCase())) == null ? void 0 : t.code;
}
), f = r(h, (o) => o.county), W = r(_, (o) => o.county), B = r(M, (o) => {
var e;
const t = T.get(o.constituency.toLowerCase());
return t ? (e = s.get(t.county.toLowerCase())) == null ? void 0 : e.code : void 0;
});
class b {
constructor(t) {
y(this, "_data");
this._data = t;
}
/** 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
*/
constituencies() {
return (w.get(this._data.code) ?? []).map(
(t) => new c(t)
);
}
/**
* Get a constituency in this county by name or code
* @throws LocationNotFoundError if not found
*/
constituency(t) {
const e = w.get(this._data.code) ?? [], n = N.get(t);
if ((n == null ? void 0 : n.county) === this._data.name)
return new c(n);
const d = e.find(
(C) => C.name.toLowerCase() === t.toLowerCase()
);
if (d) return new c(d);
throw new p("Constituency", t);
}
/**
* Get all localities in this county
*/
localities() {
return (f.get(this._data.name) ?? []).map(
(t) => new m(t)
);
}
/**
* Get a locality in this county by name
* @throws LocationNotFoundError if not found
*/
locality(t) {
const e = (f.get(this._data.name) ?? []).find(
(n) => n.name.toLowerCase() === t.toLowerCase()
);
if (e) return new m(e);
throw new p("Locality", t);
}
/**
* Get all areas in this county
*/
areas() {
return W.get(this._data.name) ?? [];
}
/**
* Get all wards in this county
*/
wards() {
return B.get(this._data.code) ?? [];
}
/**
* Get areas by locality name
*/
areasByLocality(t) {
return this.areas().filter(
(e) => e.locality.toLowerCase() === t.toLowerCase()
);
}
}
function z() {
return i;
}
function D(o) {
return g.get(o);
}
function H(o) {
return s.get(o.toLowerCase());
}
function I(o) {
const t = g.get(o) ?? s.get(o.toLowerCase());
return t ? new b(t) : void 0;
}
export {
b as CountyWrapper,
I as county,
z as getCounties,
D as getCountyByCode,
H as getCountyByName
};