A lightweight, zero-dependency JavaScript SDK for Nigerian states, LGAs, and geopolitical data
- π Zero Dependencies - Lightweight and fast
- π¦ 37 States + FCT - All Nigerian states and Federal Capital Territory
- ποΈ 774 LGAs - Complete list of Local Government Areas
- πΊοΈ 6 Geopolitical Regions - Query by regions
- π Fast Search - Search states and LGAs instantly
- πͺ TypeScript Support - Fully typed for better DX
- π² Tree-shakeable - Import only what you need
- β‘ Offline-first - No API calls, all data embedded
- π Universal - Works in Node.js, browsers, React, Vue, Next.js, etc.
npm install nigeria-geo-datayarn add nigeria-geo-datapnpm add nigeria-geo-dataimport { getAllStates, getStateByCode, getLGAsByState } from 'nigeria-geo-data';
// Get all states
const states = getAllStates();
console.log(states.length); // 37
// Get specific state
const lagos = getStateByCode('LA');
console.log(lagos.capital); // "Ikeja"
// Get LGAs for a state
const lagosLGAs = getLGAsByState('LA');
console.log(lagosLGAs.length); // 20const { getAllStates, getStateByCode } = require('nigeria-geo-data');
const lagos = getStateByCode('LA');
console.log(lagos);Get all Nigerian states (37 including FCT).
const states = getAllStates();
// Returns: State[]Get a state by its two-letter code.
const lagos = getStateByCode('LA');
// Returns: State | null
// {
// name: 'Lagos',
// capital: 'Ikeja',
// code: 'LA',
// region: 'South-West'
// }Get a state by its name (case-insensitive).
const lagos = getStateByName('Lagos');
// Returns: State | nullGet all states in a specific geopolitical region.
const southWestStates = getStatesByRegion('South-West');
// Returns: State[]
// ['Ekiti', 'Lagos', 'Ogun', 'Ondo', 'Osun', 'Oyo']Get the capital city of a state.
const capital = getStateCapital('LA');
// Returns: string | null
// "Ikeja"Check if a state code is valid. Returns a boolean
console.log(isValidStateCode('LA')); // true
console.log(isValidStateCode('XY')); // falseGet a state with all its LGAs included.
const lagosWithLGAs = getStateWithLGAs('LA');
// Returns: StateWithLGAs | null
// {
// name: 'Lagos',
// capital: 'Ikeja',
// code: 'LA',
// region: 'South-West',
// lgas: [...], // Array of LGA objects
// lgaCount: 20
// }Search states by name (partial match, case-insensitive).
const results = searchStates('Ondo');
// Returns: State[]Get the region a state belongs to.
const region = getStateRegion('LA');
// Returns: Region | null
// "South-West"Get all LGAs in Nigeria (774 total).
const lgas = getAllLGAs();
// Returns: LGA[]Get all LGAs in a specific state by state code.
const lagosLGAs = getLGAsByState('LA');
// Returns: LGA[]
// [
// { name: 'Agege', state: 'LA' },
// { name: 'Ajeromi-Ifelodun', state: 'LA' },
// ...
// ]Get all LGAs in a specific state by state name.
const lagosLGAs = getLGAsByStateName('Lagos');
// Returns: LGA[]Search LGAs by name across all states.
const results = searchLGAs('Ikeja');
// Returns: LGA[]
// [{ name: 'Ikeja', state: 'LA' }]Get the total count of LGAs, optionally filtered by state.
console.log(getLGACount()); // 774
console.log(getLGACount('LA')); // 20Check if an LGA exists in a specific state.
console.log(lgaExists('Ikeja', 'LA')); // true
console.log(lgaExists('Ikeja', 'KN')); // falseGet the first LGA that matches a name.
const lga = getLGAByName('Ikeja');
// Returns: LGA | nullGet all LGAs with a specific name (some LGA names appear in multiple states).
const lgas = getAllLGAsByName('Obi');
// Returns: LGA[]Get all geopolitical regions (6 total).
const regions = getAllRegions();
// Returns: Region[]
// ['North-Central', 'North-East', 'North-West', 'South-East', 'South-South', 'South-West']Get all states in a specific region.
const southWestStates = getRegionStates('South-West');
// Returns: State[]Get the region that a state belongs to.
const region = getRegionByState('LA');
// Returns: Region | null
// "South-West"Get statistics for a specific region.
const stats = getRegionStats('South-West');
// Returns: RegionStats
// {
// region: 'South-West',
// stateCount: 6,
// lgaCount: 137,
// states: [...]
// }Get statistics for all regions.
const allStats = getAllRegionStats();
// Returns: RegionStats[]Check if a region name is valid.
console.log(isValidRegion('South-West')); // true
console.log(isValidRegion('South-Middle')); // falseGet the number of states in a region.
console.log(getRegionStateCount('South-West')); // 6Get the number of LGAs in a region.
console.log(getRegionLGACount('South-West')); // 137Access library metadata:
import { METADATA } from 'nigeria-geo-data';
console.log(METADATA.totalStates); // 37
console.log(METADATA.totalLGAs); // 774
console.log(METADATA.regions); // Array of all regionsFull TypeScript support with exported types:
import type { State, LGA, Region, StateWithLGAs, RegionStats } from 'nigeria-geo-data';
const state: State = {
name: 'Lagos',
capital: 'Ikeja',
code: 'LA',
region: 'South-West'
};
const lga: LGA = {
name: 'Ikeja',
state: 'LA'
};
const region: Region = 'South-West';import { getAllStates, getLGAsByState } from 'nigeria-geo-data';
// State dropdown
const StateSelect = () => {
const states = getAllStates();
return (
<select>
{states.map(state => (
<option key={state.code} value={state.code}>
{state.name}
</option>
))}
</select>
);
};
// LGA dropdown based on selected state
const LGASelect = ({ stateCode }) => {
const lgas = getLGAsByState(stateCode);
return (
<select>
{lgas.map(lga => (
<option key={lga.name} value={lga.name}>
{lga.name}
</option>
))}
</select>
);
};import { isValidStateCode, lgaExists } from 'nigeria-geo-data';
function validateAddress(stateCode: string, lgaName: string) {
if (!isValidStateCode(stateCode)) {
return { valid: false, error: 'Invalid state code' };
}
if (!lgaExists(lgaName, stateCode)) {
return { valid: false, error: 'LGA does not exist in this state' };
}
return { valid: true };
}import { searchStates, searchLGAs } from 'nigeria-geo-data';
function searchLocation(query: string) {
const states = searchStates(query);
const lgas = searchLGAs(query);
return { states, lgas };
}import { getAllRegionStats } from 'nigeria-geo-data';
const stats = getAllRegionStats();
stats.forEach(stat => {
console.log(`${stat.region}:`);
console.log(` States: ${stat.stateCount}`);
console.log(` LGAs: ${stat.lgaCount}`);
});- States: 37 (including FCT Abuja)
- LGAs: 774
- Regions: 6 (North-Central, North-East, North-West, South-East, South-South, South-West)
- State Codes: All 37 two-letter codes
Contributions are 100% welcome! Please feel free to submit a Pull Request.
MIT Β© Imam Dahir
Made with π for Nigeria π³π¬