npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ke-locations-data

v0.0.4

Published

A comprehensive TypeScript/JavaScript library providing structured data for all Kenyan administrative divisions including counties, constituencies, wards, localities, and areas with powerful search and lookup capabilities.

Readme

KE Locations Data

A comprehensive TypeScript/JavaScript library providing structured data for all Kenyan administrative divisions including counties, constituencies, wards, localities, and areas with powerful search and lookup capabilities.

npm version License: MIT

Features

  • Complete Coverage: All 47 counties, constituencies, wards, localities, and areas
  • Fast Search: Efficient lookup by code or name
  • Hierarchical Queries: Get all constituencies in a county, wards in a constituency, etc.
  • TypeScript Support: Full type definitions included
  • Optimized Performance: Map-based lookups for O(1) time complexity
  • Case Insensitive: All searches work regardless of case
  • Referential Integrity: Maintain relationships between administrative levels

Installation

npm i ke-locations-data

Quick Start

import { kenyaLocations } from 'ke-locations-data';

// Search for locations
const results = kenyaLocations.search('Nairobi');

// Get county by name
const county = kenyaLocations.getCountyByName('Mombasa');

// Get all constituencies in a county
const constituencies = kenyaLocations.getConstituenciesByCounty('47');

// Get all wards in a constituency
const wards = kenyaLocations.getWardsByConstituency('290');

API Reference

Search Methods

search(query: string, typeOrLimit?: SearchType | number, limit?: number): SearchResult[]

Search across all location types or filter by specific type.

// Search all types
const results = kenyaLocations.search('Westlands');

// Search with limit
const results = kenyaLocations.search('Nairobi', 5);

// Search specific type
const counties = kenyaLocations.search('Mombasa', 'county');

// Search specific type with limit
const wards = kenyaLocations.search('Park', 'ward', 3);

Parameters:

  • query: Search query string
  • typeOrLimit: Either a SearchType ('county' | 'constituency' | 'ward' | 'locality' | 'area') or a number for limit
  • limit: Maximum number of results (default: 10)

Returns: Array of SearchResult objects containing type and item data


getByType(type: SearchType): SearchResult[]

Get all locations of a specific type.

const allCounties = kenyaLocations.getByType('county');
const allWards = kenyaLocations.getByType('ward');

getAllData(): SearchResult[]

Get all location data combined.

const allLocations = kenyaLocations.getAllData();

County Methods

getCountyByCode(code: string): ICounty | undefined

Get a county by its code.

const nairobi = kenyaLocations.getCountyByCode('47');
// Returns: { code: '47', name: 'Nairobi', type: 'county' }

getCountyByName(name: string): ICounty | undefined

Get a county by its name (case-insensitive).

const mombasa = kenyaLocations.getCountyByName('Mombasa');
const sameMombasa = kenyaLocations.getCountyByName('MOMBASA'); // Works too!

getAllCounties(): ICounty[]

Get all 47 counties.

const counties = kenyaLocations.getAllCounties();
console.log(counties.length); // 47

Constituency Methods

getConstituencyByCode(code: string): IConstituency | undefined

Get a constituency by its code.

const westlands = kenyaLocations.getConstituencyByCode('290');

getConstituencyByName(name: string): IConstituency | undefined

Get a constituency by its name (case-insensitive).

const westlands = kenyaLocations.getConstituencyByName('Westlands');

getAllConstituencies(): IConstituency[]

Get all constituencies.

const constituencies = kenyaLocations.getAllConstituencies();

getConstituenciesByCounty(countyCode: string): IConstituency[]

Get all constituencies within a specific county.

// Get all constituencies in Nairobi
const nairobiConstituencies = kenyaLocations.getConstituenciesByCounty('47');

Ward Methods

getWardByCode(code: string): IWard | undefined

Get a ward by its code.

const ward = kenyaLocations.getWardByCode('1366');

getWardByName(name: string): IWard | undefined

Get a ward by its name (case-insensitive).

const parklands = kenyaLocations.getWardByName('Parklands/Highridge');

getAllWards(): IWard[]

Get all wards.

const wards = kenyaLocations.getAllWards();

getWardsByConstituency(constituencyCode: string): IWard[]

Get all wards within a specific constituency.

// Get all wards in Westlands constituency
const westlandsWards = kenyaLocations.getWardsByConstituency('290');

getWardsByCounty(countyCode: string): IWard[]

Get all wards within a specific county.

// Get all wards in Nairobi county
const nairobiWards = kenyaLocations.getWardsByCounty('47');

Locality Methods

getLocalityByCode(code: string): ILocality | undefined

Get a locality by its code.

const locality = kenyaLocations.getLocalityByCode('2853');

getLocalityByName(name: string): ILocality | undefined

Get a locality by its name (case-insensitive).

const karen = kenyaLocations.getLocalityByName('Karen');

getAllLocalities(): ILocality[]

Get all localities.

const localities = kenyaLocations.getAllLocalities();

getLocalitiesByCounty(countyCode: string): ILocality[]

Get all localities within a specific county.

const nairobiLocalities = kenyaLocations.getLocalitiesByCounty('47');

Area Methods

getAreaByCode(code: string): IArea | undefined

Get an area by its code.

const area = kenyaLocations.getAreaByCode('3125');

getAreaByName(name: string): IArea | undefined

Get an area by its name (case-insensitive).

const kilimani = kenyaLocations.getAreaByName('Kilimani');

getAllAreas(): IArea[]

Get all areas.

const areas = kenyaLocations.getAllAreas();

getAreasByCounty(countyCode: string): IArea[]

Get all areas within a specific county.

const nairobiAreas = kenyaLocations.getAreasByCounty('47');

getAreasByLocality(locality: string): IArea[]

Get all areas within a specific locality.

const karenAreas = kenyaLocations.getAreasByLocality('Karen');

TypeScript Types

Interfaces

interface ICounty {
  code: string;
  name: string;
  type: string;
}

interface IConstituency {
  code: string;
  name: string;
  county_code: string;
  county_name: string;
  type: string;
}

interface IWard {
  code: string;
  name: string;
  constituency_code: string;
  constituency_name: string;
  county_code: string;
  county_name: string;
  type: string;
}

interface ILocality {
  code: string;
  name: string;
  county_code: string;
  county_name: string;
  type: string;
}

interface IArea {
  code: string;
  name: string;
  locality: string;
  county_code: string;
  county_name: string;
  type: string;
}

type SearchType = 'county' | 'constituency' | 'ward' | 'locality' | 'area';

interface SearchResult {
  type: SearchType;
  item: ICounty | IConstituency | IWard | ILocality | IArea;
}

Performance

The library uses Map-based lookups for optimal performance:

  • Lookup by Code/Name: O(1) time complexity
  • Hierarchical Queries: O(n) where n is the filtered subset
  • Search Operations: Optimized with early returns
  • Memory Efficient: Data loaded once and reused

Browser Support

Works in all modern browsers and Node.js environments that support:

  • ES6+ features
  • Map/Set data structures
  • TypeScript 4.0+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Data Sources

Data is compiled from official Kenyan government sources and regularly updated to ensure accuracy.

License

MIT License - see LICENSE file for details

Author

Gerald Mumo

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.