UNPKG

kenya-locations

Version:

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

353 lines (352 loc) 12.2 kB
import { County, Constituency, Ward, SearchResult, SubCounty, Area, Locality } from './types'; import { LocationError, LocationNotFoundError } from './errors/LocationErrors'; /** * 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 LocationNotFoundError 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 LocationNotFoundError 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 LocationNotFoundError 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[]; } /** * 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. * When the same name exists in multiple counties, returns the first match. * Use {@link getLocalitiesByName} to retrieve all matches, or pass a county * via the {@link locality} function to narrow the result. */ export declare function getLocalityByName(name: string): LocalityWrapper | undefined; /** * Get all localities matching a name across all counties. * Useful when the same locality name exists in more than one county. * @param name Locality name (case-insensitive) * @returns Array of LocalityWrapper instances */ export declare function getLocalitiesByName(name: string): LocalityWrapper[]; /** * 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 by name or code. * Sub-county names correspond to constituency names in the ward dataset, * so this matches wards whose constituency field equals the sub-county name. * @param nameOrCode Sub-county name or code */ export declare function getWardsInSubCounty(nameOrCode: 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; /** * Get a county by name (case-insensitive) */ export declare function getCountyByName(name: string): County | undefined; /** * Get a constituency by name (case-insensitive) */ export declare function getConstituencyByName(name: string): ConstituencyWrapper | undefined; /** * Get a ward by code */ export declare function getWardByCode(code: string): Ward | undefined; /** * Get a ward by name (case-insensitive). * Note: Multiple wards may share the same name across different constituencies. */ export declare function getWardByName(name: string): Ward | undefined; /** * Get a sub-county by code */ export declare function getSubCountyByCode(code: string): SubCounty | undefined; /** * Get a sub-county by name (case-insensitive) */ export declare function getSubCountyByName(name: string): SubCounty | undefined; /** * Get all constituencies in a county by county name or code */ export declare function getConstituenciesInCounty(nameOrCode: string): ConstituencyWrapper[]; /** * Get the constituency a ward belongs to by ward name or code */ export declare function getConstituencyOfWard(wardNameOrCode: string): ConstituencyWrapper | undefined; /** * Get the sub-county a ward belongs to by ward name or code. * Sub-county names correspond to constituency names in the ward dataset. */ export declare function getSubCountyOfWard(wardNameOrCode: string): SubCounty | undefined; /** * Get all areas matching a name across all localities. * Useful when the same area name exists in more than one locality. * @param name Area name (case-insensitive) */ export declare function getAreasByName(name: string): Area[]; /** * Main class for working with Kenya's administrative locations. * * @deprecated Use the tree-shakeable standalone functions instead. * Import directly from `kenya-locations` or its subpath exports * (e.g. `kenya-locations/counties`, `kenya-locations/wards`). * The class will be removed in a future major version. */ 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 getLocalitiesByName: typeof getLocalitiesByName; 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 getConstituencyByName: typeof getConstituencyByName; static getConstituenciesInCounty: typeof getConstituenciesInCounty; static getConstituencyOfWard: typeof getConstituencyOfWard; static getSubCountyOfWard: typeof getSubCountyOfWard; static getWardsInCounty: typeof getWardsInCounty; static getWardByCode: typeof getWardByCode; static getWardByName: typeof getWardByName; static getSubCountyByCode: typeof getSubCountyByCode; static getSubCountyByName: typeof getSubCountyByName; static getCountyByName: typeof getCountyByName; static getAreasByName: typeof getAreasByName; static search: typeof search; static searchByType: typeof searchByType; static getWardsInConstituency: typeof getWardsInConstituency; static getCountyOfConstituency: typeof getCountyOfConstituency; } export { CountyWrapper, ConstituencyWrapper, LocalityWrapper }; export { LocationError as KenyaLocationsError, LocationNotFoundError as NotFoundError, }; export default KenyaLocations;