UNPKG

kenya-locations

Version:

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

89 lines (88 loc) 2.11 kB
import n from "fuse.js"; import { c as C } from "./counties-CIvO8NBl.js"; import { c as L } from "./constituencies-CpiSuj07.js"; import { w as M } from "./wards-CGdGn1Pj.js"; import { s as O } from "./sub-counties-Crb1ccMT.js"; import { l as k, a as x } from "./area-DZRgJy_F.js"; const c = { keys: ["name"], threshold: 0.2, includeScore: !0, ignoreLocation: !0, // Performance optimization findAllMatches: !1, // Performance optimization minMatchCharLength: 2 // Performance optimization }; let y = null, m = null, p = null, d = null, f = null, h = null; function z() { y ?? (y = new n(C, c)), m ?? (m = new n(L, c)), p ?? (p = new n(M, c)), d ?? (d = new n(O, c)), f ?? (f = new n(k, c)), h ?? (h = new n(x, c)); } function A(o, r = {}) { const { limit: u = 10, types: e } = r; if (!o || o.trim().length < 2) return []; z(); const w = o.trim(), i = [], b = [ { type: "county", fuse: y, enabled: !e || e.includes("county") }, { type: "constituency", fuse: m, enabled: !e || e.includes("constituency") }, { type: "ward", fuse: p, enabled: !e || e.includes("ward") }, { type: "sub-county", fuse: d, enabled: !e || e.includes("sub-county") }, { type: "locality", fuse: f, enabled: !e || e.includes("locality") }, { type: "area", fuse: h, enabled: !e || e.includes("area") } ]; for (const { type: s, fuse: t, enabled: F } of b) if (F) { const g = t.search(w, { limit: u * 2 }); i.push( ...g.map( (a) => ({ type: s, item: a.item, score: a.score }) ) ); } const l = { county: 1, constituency: 2, ward: 3, "sub-county": 4, locality: 5, area: 6 }; return i.sort((s, t) => s.score !== t.score ? (s.score || 0) - (t.score || 0) : l[s.type] - l[t.type]).slice(0, u).map(({ score: s, ...t }) => t); } function j(o, r, u = 10) { return A(o, { limit: u, types: [r] }); } export { j as a, A as s };