Skip to content

Courier (experimental)

import { mapCourierStatus, normalizeCityForCourier } from 'pakdatakit/courier'

Maps a courier’s own status (its name, numeric ID or code, as the courier documents it) to one vocabulary, from order to delivery or return. It also maps the way a customer or a courier writes a city to the city’s name in pakdatakit’s city list, so orders can be matched against a courier’s service list. No API is called.

mapCourierStatus()
out-for-delivery
normalizeCityForCourier()
Rawalpindi
import { mapCourierStatus, normalizeCityForCourier } from 'pakdatakit';
mapCourierStatus('PostEx', 'Out for Delivery');
// → 'out-for-delivery'
mapCourierStatus('TCS', 'Delivered');
// → null
normalizeCityForCourier('LHR');
// → 'Lahore'
normalizeCityForCourier('lyallpur');
// → 'Faisalabad'
function mapCourierStatus(
courier: string,
raw: string | number,
): CourierStatus | null;
type CourierStatus =
| 'pending'
| 'booked'
| 'picked-up'
| 'in-transit'
| 'out-for-delivery'
| 'attempted'
| 'under-review'
| 'delivered'
| 'returning'
| 'returned'
| 'cancelled';

Parameters. courier: TCS, Leopards, PostEx, M&P, Trax or BlueEx (case-insensitive; LCS, MnP and Blue Ex are accepted). raw: the status as the courier returned it.

Returns the status, or null. It never throws. Matching ignores case and extra spaces. PostEx’s Attempt Made: <reason> history messages map to attempted.

Caveats. Only statuses the courier documents publicly are mapped: PostEx’s API guide and one Leopards status (“Returned to Shipper”). TCS, M&P, Trax and BlueEx publish no list, so they always return null, as does any status not in the list. Experimental: the mapping and the CourierStatus values may change in a minor release.

Related: normalizeCityForCourier().

function normalizeCityForCourier(input: string): string | null;

Parameters. input: a city as written. Accepts the exact name in any case, short forms (LHR, Khi, Pindi, Isb, FSD), the old name Lyallpur, a trailing “city”, and the main cities in Urdu script.

Returns a city from the city list, or null. It never throws.

Caveats. The short forms are common usage, not an official list.

Related: Geography, address.