pakdatakit 2.3.0
pakdatakit: ^2.3.0 copied to clipboard
Pakistani data utilities: CNIC, phone, IBAN, postal codes, addresses, Hijri dates, holidays, amounts in words and Raast QR codes. Pure Dart, all platforms.
PakDataKit for Dart and Flutter #
Utilities for Pakistani data: CNIC, mobile numbers and networks, WhatsApp links, IBAN and banks, postal codes, cities and districts, address parsing, Roman Urdu, Hijri dates, public holidays, rupee formatting, amounts in words, NTN/STRN, landlines, Raast QR codes, and form-field helpers that format as the user types.
This is the Dart port of the pakdatakit npm package.
It ships the same datasets and is tested against the same 12,000+ test
vectors generated from the TypeScript library (also used by the Python
port), so all three give identical results.
- Pure Dart, no dependencies
- Works on every platform: Flutter (Android, iOS, web, desktop), the Dart
VM and server, and Dart compiled to JavaScript. No
dart:io; the data is embedded in the package. - Null-safe, immutable result classes with value equality and
toJson()
Install #
dart pub add pakdatakit
# or, in a Flutter app
flutter pub add pakdatakit
Examples #
import 'package:pakdatakit/pakdatakit.dart';
validateCNIC('35202-1234567-1'); // true
getCNICInfo('35202-1234567-1');
// CNICInfo{digits: 3520212345671, formatted: 35202-1234567-1, province: Punjab, gender: male}
formatPhone('0300 1234567'); // '+923001234567'
getNetwork('0345-1234567'); // NetworkName.telenor
createWhatsAppLink('03001234567', 'Salam!'); // 'https://wa.me/923001234567?text=Salam!'
validateIBAN('PK36 SCBL 0000 0011 2345 6702'); // true
getBankFromIBAN('PK36SCBL0000001123456702'); // 'Standard Chartered Bank (Pakistan) Limited'
getBankInfo('MEZN')?.type; // BankType.islamic
getProvince('Lahore'); // 'Punjab'
getDivisions('Sindh'); // ['Hyderabad', 'Karachi', 'Larkana', ...]
getDivisionOfDistrict('Lahore'); // 'Lahore'
getTehsils('Rawalpindi'); // tehsils of the district, sorted
getTehsilDistrict('Murree'); // 'Rawalpindi'
parseAddress('House 12, Street 5, Model Town Lahore 54000').postalCode; // '54000'
getPostOffice('48330')?.office; // 'Dulmial'
searchPostOffices('Dulmial').length; // offices whose name or town matches
formatPKR(150000); // 'Rs. 150,000'
formatLakh(2500000); // '25 Lakh'
amountInWords(125000, cheque: true); // 'Rupees One Lakh Twenty-Five Thousand Only'
numberToWords(125000, language: WordsLanguage.ur); // 'ایک لاکھ پچیس ہزار'
formatHijri(DateTime(2026, 3, 3)); // '14 Ramadan 1447'
isPakistanHoliday(DateTime(2025, 8, 14)); // true
getPakistanHolidays(2026).first; // Holiday{id: kashmir-day, ...}
final payload = createRaastP2PQr(
iban: 'PK36SCBL0000001123456702',
amount: 1500,
expiresIn: '1d', // or const Duration(days: 1)
);
validateRaastQr(payload).valid; // true
formatCNICInput('3520212'); // '35202-12'
checkPhoneInput('0300 12'); // InputState.incomplete
Each module can also be imported on its own, mirroring the npm entry points:
import 'package:pakdatakit/cnic.dart';
import 'package:pakdatakit/raast.dart';
Available: address, cnic, format, geo, hijri, holidays, iban,
input, networks, numbers, phone, postal, raast, tax, text,
whatsapp and words.
API #
Every function of the npm package is available under the same name
(validateCNIC, createRaastP2PQr, …). See the
API reference for what each one does.
In Dart:
- Options objects are named parameters:
{ expiresIn: '1d' }→expiresIn: '1d',{ language: 'ur' }→language: WordsLanguage.ur. - Results are immutable classes with
constconstructors,==/hashCode,toString()andtoJson(), which gives the same JSON (keys and values) as the npm package. - Closed sets of strings are enums (
InputState,NetworkName,NumberType,BankType,NTNType,HolidayId,RaastQrError, …), each with a.valueholding the npm string, e.g.NumberType.tollFree.value == 'toll-free'. nullwhere the npm package returnsnull.- Divisions and tehsils (
getDivisions,getDivisionOfDistrict,getTehsils,getTehsilDistrict) use the 2023 census: each tehsil is recorded under the district it was in then, and districts created since the census have no division.getDivisionsandgetTehsilDistricttake the province as an optional positional argument. - Postal codes:
getCityByPostalCodeand the other postal-code lookups only know the offices of cities pakdatakit lists (457 codes), so a village code returnsnull.getPostOfficeandsearchPostOfficescover every delivery office in Pakistan Post's directory (about 2,560) and returnPostOfficevalues (code,office,town,district,province). The directory is only referenced by these two functions, so release builds that do not call them leave it out. BankTypehas the State Bank's groups, includingBankType.publicSector('public-sector') for public sector commercial banks such as National Bank of Pakistan;BankInfo.activeisfalsefor banks that merged into another or have closed.- An
ArgumentErrorwhere the npm package throws aRangeError, e.g.formatPKR(double.nan)or a Raast QR with an amount but no expiry. - Dates are local
DateTimes; only the calendar date (or, for Raast expiry, the local time) is used.getHolidaysOnandisPakistanHolidaytake aDateTimeor a'YYYY-MM-DD'string. - Whole-number options are
int(Hijrioffset,hijriOffset, years); amounts arenum. ParsedRaastQr.isDynamicandcreateMerchantQr(isDynamic: …)are calleddynamicin the npm package (dynamicis a built-in Dart type);toJson()still usesdynamic.createRaastP2PQrtakes an optionalnow(the timeexpiresIncounts from), andexpiresInalso accepts aDuration.
dataVersion gives the date the datasets were last checked against their
sources; see DATA.md
for where each dataset comes from.
Same results as the npm package #
The datasets in lib/src/data/ are generated from the repository's shared
data/*.json, and the package is tested against the shared
test-vectors/,
produced by running the TypeScript library over 12,080 inputs. The tests pass
both on the Dart VM and compiled to JavaScript.
JavaScript behaviours that differ in Dart are reproduced exactly: whitespace
and trim, full Unicode case mapping (ß → SS), NFC normalization,
Math.round, number-to-string conversion, toFixed, localeCompare
ordering and stable sorting.
Development #
From dart/:
dart pub get
dart test
The files in lib/src/data/ are generated; don't edit them by hand. From the
repository root:
node scripts/generate-dart-data.mjs
License #
MIT