A zero-dependency TypeScript library for querying Nigerian states, LGAs, universities, airports, land mass, and geo-political zones. Works anywhere JavaScript runs — Node.js, React, Vue, Svelte, or plain JS.
npm install ng-locations
# or
yarn add ng-locations
# or
pnpm add ng-locations
"Lagos" or its UUID interchangeably" lagos ", "LAGOS", and "Lagos" all workAll functions that take a state or LGA identifier accept either the name or the UUID. Input is sanitized internally (trimmed and lowercased), so any casing or extra spaces work fine.
import { getStateCapital } from "ng-locations";
getStateCapital("Lagos") // "Ikeja"
getStateCapital("lagos") // "Ikeja"
getStateCapital(" LAGOS ") // "Ikeja"
getStateCapital("3ac495b8-4196-4126-bf9e-bb8d43a0355d") // "Yola"
import { getAllStatesInfo } from "ng-locations";
getAllStatesInfo();
// => [
// {
// name: "Abia",
// capital: "Umuahia",
// id: "2e14a7ed-349a-44f6-9e12-abfec3e5f6ed",
// lgas: [...],
// land_mass: "6,320 km²",
// universities: [...],
// airports: [],
// geopolitical_zone: "South East",
// },
// ...
// ]
import { getAllStates } from "ng-locations";
getAllStates();
// => [
// { name: "Abia", id: "2e14a7ed-349a-44f6-9e12-abfec3e5f6ed" },
// { name: "Adamawa", id: "3ac495b8-4196-4126-bf9e-bb8d43a0355d" },
// ...
// ]
import { getStateInfo } from "ng-locations";
getStateInfo("Lagos");
// => { name: "Lagos", capital: "Ikeja", id: "...", lgas: [...], ... }
getStateInfo("not-a-state");
// => "State not found. Check the ID or name passed."
import { getState } from "ng-locations";
getState("Lagos");
// => { name: "Lagos", id: "..." }
import { getStateCapital } from "ng-locations";
getStateCapital("Ogun"); // => "Abeokuta"
import { getStateLandMass } from "ng-locations";
getStateLandMass("Rivers"); // => "11,077 km²"
import { getStateGeoPoliticalZone } from "ng-locations";
getStateGeoPoliticalZone("Kano"); // => "North West"
import { getStateLGAs } from "ng-locations";
getStateLGAs("Abia");
// => [
// { name: "Aba South", id: "4c840cb1-..." },
// { name: "Arochukwu", id: "f46f5f01-..." },
// ...
// ]
import { getLGA } from "ng-locations";
// By state name + LGA name
getLGA("Abia", "Aba South");
// => { name: "Aba South", id: "4c840cb1-8f58-40d3-9aff-5a3b77fdba71" }
// By state ID + LGA ID
getLGA("2e14a7ed-...", "4c840cb1-...");
// => { name: "Aba South", id: "4c840cb1-..." }
// Mixed is also fine
getLGA("Abia", "4c840cb1-...");
// => { name: "Aba South", id: "4c840cb1-..." }
import { getStateUniversities } from "ng-locations";
getStateUniversities("Abia");
// => [
// { name: "Abia State University", location: "Uturu", type: "State" },
// { name: "Michael Okpara University of Agriculture", location: "Umudike", type: "Federal" },
// ]
import { getStateAirports } from "ng-locations";
getStateAirports("Lagos");
// => [
// { name: "Murtala Muhammed International Airport", IATA_code: "LOS", type: "International" },
// ]
All functions return the result directly or a string error message when the lookup fails.
| Function | Parameters | Returns |
|---|---|---|
getAllStatesInfo() |
— | TStateInfo[] |
getAllStates() |
— | TState[] |
getStateInfo(idOrName) |
string |
TStateInfo | string |
getState(idOrName) |
string |
TState | string |
getStateCapital(idOrName) |
string |
string |
getStateLandMass(idOrName) |
string |
string |
getStateGeoPoliticalZone(idOrName) |
string |
string |
getStateLGAs(idOrName) |
string |
TLGA[] | string |
getLGA(stateIdOrName, lgaIdOrName) |
string, string |
TLGA | string |
getStateUniversities(idOrName) |
string |
TUniversity[] | string |
getStateAirports(idOrName) |
string |
TAirport[] | string |
type TStateInfo = {
name: string;
capital: string;
id: string;
lgas: TLGA[];
land_mass: string;
universities: TUniversity[];
airports: TAirport[];
geopolitical_zone: string;
};
type TState = { name: string; id: string };
type TLGA = { name: string; id: string };
type TUniversity = { name: string; location: string; type: string };
type TAirport = { name: string; IATA_code: string; type: string };
const { getAllStates, getStateCapital } = require("ng-locations");
MIT © Muiz Haruna