geo-ng
Version:
Retrieve a comprehensive list of states, areas, and sub-areas in Nigeria, providing users with essential geographic information for the country.
20 lines (15 loc) • 707 B
text/typescript
import { areas } from "./functions/nigeria-states";
import { StateCodes, NigeriaState } from "./@types";
const getNigeriaStates = (): Omit<NigeriaState, "subs">[] => {
return areas.map(({ subs, ...state }) => state);
};
const getLGAs = (stateCode: StateCodes): string[] => {
const state = areas.filter((state) => state.code === stateCode);
return state.length > 0 ? state[0].lgas : [];
};
const getLgaSubAreas = (stateCode: StateCodes, lga: string): string[] => {
const state = areas.filter((state) => state.code === stateCode);
const subAreas = state.length > 0 ? state[0]?.subs[lga] : [];
return subAreas;
};
export { getNigeriaStates, getLGAs, getLgaSubAreas, StateCodes, NigeriaState };