UNPKG

naija-geo

Version:

Nigeria geographical data - states, cities & LGAs

39 lines (38 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.niajaGeo = void 0; const config_1 = require("./config"); class NiajaGeo { constructor() { this.getStates = () => this.states; this.getState = (targetState) => { const matchedState = this.states.find((currentState) => currentState.state.toLowerCase() === targetState.toLowerCase()); return matchedState || null; }; this.getDistricts = (targetState) => { const matchedState = this.getState(targetState); if (!matchedState) return []; return Object.values(matchedState.senatorialDistricts).flat(); }; this.getLgas = (targetState) => { const matchedState = this.getState(targetState); if (!matchedState) return []; const uniqueLgas = Array.from(new Set([ ...Object.values(matchedState.senatorialDistricts).flat(), ...matchedState.lgas, ])); return uniqueLgas; }; // Proper state-by-LGA implementation this.getStateByLga = (targetLga) => { const normalizedLga = targetLga.toLowerCase(); return (this.states.find((state) => state.lgas.some((lga) => lga.toLowerCase() === normalizedLga)) || null); }; this.states = config_1.NIGERIA_CONFIG; } } const niajaGeo = new NiajaGeo(); exports.niajaGeo = niajaGeo; exports.default = NiajaGeo;