UNPKG

kenya-locations

Version:

A comprehensive and intuitive TypeScript package for working with Kenyan administrative divisions (counties, sub-counties, constituencies, and wards)

287 lines (286 loc) 9.03 kB
import { County, Constituency, Ward, SearchResult, SubCounty, Area, Locality } from './types'; declare class NotFoundError extends Error { constructor(message: string); } /** * Locality class with methods to access area data * @example * const westlands = getLocalityByName('Westlands'); * westlands?.areas(); */ declare class LocalityWrapper { private readonly _data; constructor(data: Locality); /** Get the locality name */ get name(): string; /** Get the county this locality belongs to */ get county(): string; /** Get all data for the locality */ get data(): Locality; /** * Get the county this locality belongs to * @returns CountyWrapper or undefined if not found */ getCounty(): CountyWrapper | undefined; /** * Get all areas in this locality * @returns Array of Area */ areas(): Area[]; /** * Get an area by name * @param name Name of the area * @throws NotFoundError if not found */ area(name: string): Area; } /** * County class with methods to access constituency, locality, and area data * @example * const nairobi = county('Nairobi'); * nairobi?.constituencies(); * nairobi?.localities(); */ declare class CountyWrapper { private readonly _data; constructor(data: County); /** Get the county code */ get code(): string; /** Get the county name */ get name(): string; /** Get all data for the county */ get data(): County; /** * Get all constituencies in this county * @returns Array of ConstituencyWrapper */ constituencies(): ConstituencyWrapper[]; /** * Get a constituency by name or code * @param nameOrCode Name or code of the constituency * @throws NotFoundError if not found */ constituency(nameOrCode: string): ConstituencyWrapper; /** * Get all wards in this county * @returns Array of Ward */ wards(): Ward[]; /** * Get all localities in this county * @returns Array of LocalityWrapper */ localities(): LocalityWrapper[]; /** * Get a locality by name * @param name Name of the locality * @throws NotFoundError if not found */ locality(name: string): LocalityWrapper; /** * Get all areas in this county * @returns Array of Area */ areas(): Area[]; /** * Get areas by locality name * @param localityName Name of the locality * @returns Array of Area */ areasByLocality(localityName: string): Area[]; } /** * Constituency class with methods to access ward data * @example * const westlands = getConstituencyByCode('290'); * westlands?.wards(); */ declare class ConstituencyWrapper { private readonly _data; constructor(data: Constituency); /** Get the constituency code */ get code(): string; /** Get the constituency name */ get name(): string; /** Get the county this constituency belongs to */ get county(): string; /** Get all data for the constituency */ get data(): Constituency; /** * Get the county this constituency belongs to * @returns CountyWrapper */ getCounty(): CountyWrapper | undefined; /** * Get a ward in this constituency by name or code */ ward(nameOrCode: string): Ward; /** * Get all wards in this constituency */ wards(): Ward[]; } /** * Custom error class for KenyaLocations */ export declare class KenyaLocationsError extends Error { constructor(message: string); } /** * Get all counties */ export declare function getCounties(): County[]; /** * Get all sub-counties */ export declare function getSubCounties(): SubCounty[]; /** * Get all wards */ export declare function getWards(): Ward[]; /** * Get all localities */ export declare function getLocalities(): Locality[]; /** * Get all areas */ export declare function getAreas(): Area[]; /** * Get a county by its code */ export declare function getCountyByCode(code: string): County | undefined; /** * Get a locality by its name */ export declare function getLocalityByName(name: string): LocalityWrapper | undefined; /** * Get an area by its name */ export declare function getAreaByName(name: string): Area | undefined; /** * Get all localities in a county * @param countyName County name */ export declare function getLocalitiesInCounty(countyName: string): Locality[]; /** * Get all areas in a locality * @param localityName Locality name */ export declare function getAreasInLocality(localityName: string): Area[]; /** * Get all areas in a county * @param countyName County name */ export declare function getAreasInCounty(countyName: string): Area[]; /** * Get the county of a locality * @param localityName The name of the locality */ export declare function getCountyOfLocality(localityName: string): County | undefined; /** * Get the county of an area * @param areaName The name of the area */ export declare function getCountyOfArea(areaName: string): County | undefined; /** * Get the locality of an area * @param areaName The name of the area */ export declare function getLocalityOfArea(areaName: string): Locality | undefined; /** * Get all sub-counties in a county * @param nameOrCode County name or code */ export declare function getSubCountiesInCounty(nameOrCode: string): SubCounty[]; /** * Get all wards in a sub-county */ export declare function getWardsInSubCounty(subCountyCode: string): Ward[]; /** * Get the county of a sub-county * @param subCountyName The name of the sub-county */ export declare function getCountyOfSubCounty(subCountyName: string): County | undefined; /** * Get the county that a ward belongs to by ward name or code */ export declare function getCountyOfWard(wardNameOrCode: string): County | undefined; /** * Get a county by name or code */ export declare function county(nameOrCode: string): CountyWrapper | undefined; /** * Get a locality by name or county */ export declare function locality(name: string, countyName?: string): LocalityWrapper | undefined; /** * Get all constituencies */ export declare function getConstituencies(): Constituency[]; /** * Get a constituency by code */ export declare function getConstituencyByCode(code: string): ConstituencyWrapper | undefined; /** * Get all wards in a county */ export declare function getWardsInCounty(countyNameOrCode: string): Ward[]; /** * Search for counties, constituencies, wards, localities, or areas */ export declare function search(query: string, options?: { limit?: number; types?: ("county" | "constituency" | "ward" | "sub-county" | "locality" | "area")[]; }): SearchResult[]; /** * Search for a specific type of administrative division */ export declare function searchByType(query: string, type: "county" | "constituency" | "ward" | "sub-county" | "locality" | "area", limit?: number): SearchResult[]; /** * Get all wards in a constituency by name or code */ export declare function getWardsInConstituency(constituencyNameOrCode: string): Ward[]; /** * Get the county that a constituency belongs to */ export declare function getCountyOfConstituency(constituencyNameOrCode: string): County | undefined; /** * Main class for working with Kenya's administrative locations */ export declare class KenyaLocations { private static instance; /** * Get the singleton instance of KenyaLocations */ static getInstance(): KenyaLocations; static getCounties: typeof getCounties; static getSubCounties: typeof getSubCounties; static getWards: typeof getWards; static getLocalities: typeof getLocalities; static getAreas: typeof getAreas; static getCountyByCode: typeof getCountyByCode; static getLocalityByName: typeof getLocalityByName; static getAreaByName: typeof getAreaByName; static getLocalitiesInCounty: typeof getLocalitiesInCounty; static getAreasInLocality: typeof getAreasInLocality; static getAreasInCounty: typeof getAreasInCounty; static getCountyOfLocality: typeof getCountyOfLocality; static getCountyOfArea: typeof getCountyOfArea; static getLocalityOfArea: typeof getLocalityOfArea; static getSubCountiesInCounty: typeof getSubCountiesInCounty; static getWardsInSubCounty: typeof getWardsInSubCounty; static getCountyOfSubCounty: typeof getCountyOfSubCounty; static getCountyOfWard: typeof getCountyOfWard; static county: typeof county; static locality: typeof locality; static getConstituencies: typeof getConstituencies; static getConstituencyByCode: typeof getConstituencyByCode; static getWardsInCounty: typeof getWardsInCounty; static search: typeof search; static searchByType: typeof searchByType; static getWardsInConstituency: typeof getWardsInConstituency; static getCountyOfConstituency: typeof getCountyOfConstituency; } export { CountyWrapper, ConstituencyWrapper, LocalityWrapper, NotFoundError }; export default KenyaLocations;