Skip to content

Postal codes and post offices

import { getPostalCode, getCityByPostalCode, getPostOffice, searchPostOffices } from 'pakdatakit/postal'

Two datasets: the main postal codes of the cities the package lists, and Pakistan Post’s full directory of about 2,560 delivery post offices, including towns and villages.

City (getCityByPostalCode)
—
Post office
Chak Dhamni
Town
Chak Dhamni
District
—
Province
Azad Jammu and Kashmir
import { getPostalCode, getCityByPostalCode, getPostOffice } from 'pakdatakit';
getPostalCode('Lahore');
// → '54000'
getCityByPostalCode('54000');
// → 'Lahore'
getPostOffice('12380');
// → {
// "code": "12380",
// "office": "Chak Dhamni",
// "town": "Chak Dhamni",
// "district": null,
// "province": "Azad Jammu and Kashmir"
// }
function getPostalCode(city: string): string | null;

Returns the primary postal code of a city (case-insensitive), or null for an unknown city.

function getCityByPostalCode(postalCode: string): string | null;

Returns the city for one of its own post offices. A village code returns null; use getPostOffice() for those.

function getPostOffice(code: string): PostOffice | null;
interface PostOffice {
code: string;
office: string;
town: string;
district: string | null;
province: string;
}

Returns any delivery post office by its five-digit code.

Caveats. The directory is a separate data file, loaded only when these functions are first called.

Related: searchPostOffices(), scoreAddress(), data sources.