pakdatakit 2.2.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DATA.md +512 -34
- package/LICENSE +1 -1
- package/NOTICE +14 -0
- package/README.md +472 -28
- package/dist/address.cjs +6 -5
- package/dist/address.js +4 -3
- package/dist/bills.cjs +19 -0
- package/dist/bills.d.cts +63 -0
- package/dist/bills.d.ts +63 -0
- package/dist/bills.js +2 -0
- package/dist/{chunk-4VSGCQ6K.cjs → chunk-2OBKPYJZ.cjs} +3 -3
- package/dist/chunk-33GOK7EE.cjs +5312 -0
- package/dist/chunk-33QMFE2Z.js +21244 -0
- package/dist/chunk-34U2ZMHR.js +194 -0
- package/dist/chunk-4GSBHJX6.js +165 -0
- package/dist/chunk-5DDHO5Z7.cjs +565 -0
- package/dist/chunk-5EY5DQS7.js +51 -0
- package/dist/chunk-5RGX4DWF.js +559 -0
- package/dist/chunk-5UCRHVI4.cjs +302 -0
- package/dist/{chunk-TTARJWGT.js → chunk-7DY26QPN.js} +2 -2
- package/dist/chunk-7E7L3NYS.cjs +11 -0
- package/dist/{chunk-3ZA265SK.cjs → chunk-AUQFA7EE.cjs} +172 -4
- package/dist/{chunk-QKH7W2CC.js → chunk-B7DOQ5QF.js} +6 -5
- package/dist/{chunk-HBOZIITD.js → chunk-CADQM4ZN.js} +14 -14
- package/dist/chunk-CF6AMRBU.cjs +198 -0
- package/dist/chunk-CZOZB4K3.js +61 -0
- package/dist/{chunk-3IARSCO6.cjs → chunk-DHOP7LQX.cjs} +25 -14
- package/dist/chunk-E2XU6NOW.js +909 -0
- package/dist/chunk-E6GWBOKV.cjs +911 -0
- package/dist/chunk-E6HSKRAE.js +9 -0
- package/dist/chunk-EA3SIHYT.js +313 -0
- package/dist/{chunk-33FXHM2E.cjs → chunk-ESKXG7Y6.cjs} +5 -5
- package/dist/chunk-I7UUPD3G.cjs +21252 -0
- package/dist/{chunk-YPPKY5XZ.js → chunk-IBZPJS4H.js} +26 -15
- package/dist/chunk-IDTRFOQW.js +35 -0
- package/dist/{chunk-XCXFGTHW.cjs → chunk-J5ZF46NZ.cjs} +14 -14
- package/dist/{chunk-NZQ47NWD.js → chunk-KRYHLYN2.js} +1 -1
- package/dist/{chunk-RXNYY5K5.js → chunk-LQHM3ADX.js} +172 -4
- package/dist/{chunk-HTERSQGF.cjs → chunk-MTS6SVNP.cjs} +4 -4
- package/dist/chunk-OTI7HY55.js +297 -0
- package/dist/{chunk-6IPPANNX.js → chunk-P7LVE2TF.js} +2 -2
- package/dist/{chunk-47P7HILD.cjs → chunk-QFPEFD67.cjs} +9 -8
- package/dist/chunk-RZQJAZKC.js +22 -0
- package/dist/{chunk-PLDVGOKZ.js → chunk-S274QFFB.js} +2 -2
- package/dist/chunk-SF4ECUZ6.cjs +56 -0
- package/dist/chunk-SQIHFEXI.cjs +25 -0
- package/dist/{chunk-NAJGGUAM.cjs → chunk-TC3VRWZV.cjs} +2 -2
- package/dist/{chunk-U7MWHXMF.cjs → chunk-TVL6RDAU.cjs} +4 -4
- package/dist/chunk-UYFTXD4P.js +168 -0
- package/dist/{chunk-AZV45DMG.js → chunk-V2XE3NCG.js} +2 -2
- package/dist/chunk-XCFZKCV2.cjs +37 -0
- package/dist/chunk-XOTCIXY6.js +5301 -0
- package/dist/chunk-XVEG53NN.cjs +322 -0
- package/dist/chunk-YDUXIENX.cjs +172 -0
- package/dist/chunk-YPAWNWFD.cjs +168 -0
- package/dist/chunk-YQFI7W3I.cjs +65 -0
- package/dist/{chunk-NTD4JLDW.cjs → chunk-YTLE5K7G.cjs} +1 -1
- package/dist/{chunk-EMH4IP2U.js → chunk-ZRONAQBV.js} +1 -1
- package/dist/class-validator.cjs +65 -0
- package/dist/class-validator.d.cts +63 -0
- package/dist/class-validator.d.ts +63 -0
- package/dist/class-validator.js +54 -0
- package/dist/cli.js +1 -1
- package/dist/courier.cjs +16 -0
- package/dist/courier.d.cts +51 -0
- package/dist/courier.d.ts +51 -0
- package/dist/courier.js +3 -0
- package/dist/fbr-invoice.cjs +25 -0
- package/dist/fbr-invoice.d.cts +170 -0
- package/dist/fbr-invoice.d.ts +170 -0
- package/dist/fbr-invoice.js +4 -0
- package/dist/geo.cjs +23 -6
- package/dist/geo.d.cts +56 -1
- package/dist/geo.d.ts +56 -1
- package/dist/geo.js +2 -1
- package/dist/holidays.cjs +4 -4
- package/dist/holidays.js +1 -1
- package/dist/iban.cjs +5 -5
- package/dist/iban.d.cts +8 -6
- package/dist/iban.d.ts +8 -6
- package/dist/iban.js +1 -1
- package/dist/incometax.cjs +27 -0
- package/dist/incometax.d.cts +91 -0
- package/dist/incometax.d.ts +91 -0
- package/dist/incometax.js +2 -0
- package/dist/index.cjs +253 -111
- package/dist/index.d.cts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +25 -15
- package/dist/input.cjs +9 -9
- package/dist/input.js +3 -3
- package/dist/joi.cjs +43 -0
- package/dist/joi.d.cts +25 -0
- package/dist/joi.d.ts +25 -0
- package/dist/joi.js +37 -0
- package/dist/networks.cjs +3 -3
- package/dist/networks.js +2 -2
- package/dist/numbers.cjs +6 -6
- package/dist/numbers.js +2 -2
- package/dist/passport.cjs +11 -0
- package/dist/passport.d.cts +27 -0
- package/dist/passport.d.ts +27 -0
- package/dist/passport.js +2 -0
- package/dist/phone.cjs +8 -8
- package/dist/phone.js +3 -3
- package/dist/postal.cjs +14 -6
- package/dist/postal.d.cts +54 -2
- package/dist/postal.d.ts +54 -2
- package/dist/postal.js +1 -1
- package/dist/quality.cjs +25 -0
- package/dist/quality.d.cts +62 -0
- package/dist/quality.d.ts +62 -0
- package/dist/quality.js +8 -0
- package/dist/raast.cjs +6 -6
- package/dist/raast.js +2 -2
- package/dist/salestax.cjs +20 -0
- package/dist/salestax.d.cts +106 -0
- package/dist/salestax.d.ts +106 -0
- package/dist/salestax.js +3 -0
- package/dist/superstruct.cjs +41 -0
- package/dist/superstruct.d.cts +25 -0
- package/dist/superstruct.d.ts +25 -0
- package/dist/superstruct.js +39 -0
- package/dist/text.cjs +21 -5
- package/dist/text.d.cts +90 -1
- package/dist/text.d.ts +90 -1
- package/dist/text.js +1 -1
- package/dist/valibot.cjs +18 -8
- package/dist/valibot.d.cts +3 -0
- package/dist/valibot.d.ts +3 -0
- package/dist/valibot.js +17 -7
- package/dist/vehicle.cjs +15 -0
- package/dist/vehicle.d.cts +43 -0
- package/dist/vehicle.d.ts +43 -0
- package/dist/vehicle.js +2 -0
- package/dist/whatsapp.cjs +3 -3
- package/dist/whatsapp.js +2 -2
- package/dist/yup.cjs +18 -8
- package/dist/yup.d.cts +3 -0
- package/dist/yup.d.ts +3 -0
- package/dist/yup.js +17 -7
- package/dist/zod.cjs +18 -8
- package/dist/zod.d.cts +3 -0
- package/dist/zod.d.ts +3 -0
- package/dist/zod.js +17 -7
- package/package.json +167 -6
- package/dist/chunk-34CJGJ67.cjs +0 -1697
- package/dist/chunk-4VVFS6FN.cjs +0 -715
- package/dist/chunk-E6DT2DWQ.js +0 -1689
- package/dist/chunk-GJENL6VK.cjs +0 -22
- package/dist/chunk-HUQY2WR5.js +0 -20
- package/dist/chunk-JKE4AMSZ.js +0 -47
- package/dist/chunk-KEHCTYLO.cjs +0 -52
- package/dist/chunk-LIYNKIKS.js +0 -709
package/README.md
CHANGED
|
@@ -43,16 +43,21 @@ Validate CNICs, analyze phone numbers, detect networks, build WhatsApp links, ch
|
|
|
43
43
|
|
|
44
44
|
## 📦 Packages
|
|
45
45
|
|
|
46
|
-
| Package
|
|
47
|
-
|
|
|
48
|
-
| [`pakdatakit`](https://www.npmjs.com/package/pakdatakit)
|
|
49
|
-
| [`pakdatakit` (Python)](https://github.com/chmuzamil/pakdatakit/tree/main/python)
|
|
50
|
-
| [`pakdatakit-react`](https://github.com/chmuzamil/pakdatakit/tree/main/react)
|
|
51
|
-
| [`pakdatakit-faker`](https://github.com/chmuzamil/pakdatakit/tree/main/faker)
|
|
52
|
-
| [`pakdatakit` (Dart)](https://github.com/chmuzamil/pakdatakit/tree/main/dart)
|
|
53
|
-
| [`pakdatakit_flutter`](https://github.com/chmuzamil/pakdatakit/tree/main/flutter)
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
| Package | Install | For |
|
|
47
|
+
| ------------------------------------------------------------------------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
48
|
+
| [`pakdatakit`](https://www.npmjs.com/package/pakdatakit) | `npm install pakdatakit` | JavaScript and TypeScript (Node, browsers, Bun, Deno) |
|
|
49
|
+
| [`pakdatakit` (Python)](https://github.com/chmuzamil/pakdatakit/tree/main/python) | `pip install pakdatakit` | Python 3.9+, same functions in snake_case, same data |
|
|
50
|
+
| [`pakdatakit-react`](https://github.com/chmuzamil/pakdatakit/tree/main/react) | `npm install pakdatakit-react` | React inputs that format as you type, and a Raast QR component |
|
|
51
|
+
| [`pakdatakit-faker`](https://github.com/chmuzamil/pakdatakit/tree/main/faker) | `npm install -D pakdatakit-faker` | Seeded mock data: CNICs, phones, IBANs, addresses and whole personas that pass every validator |
|
|
52
|
+
| [`pakdatakit` (Dart)](https://github.com/chmuzamil/pakdatakit/tree/main/dart) | `dart pub add pakdatakit` | Dart and Flutter (including web), same functions and data |
|
|
53
|
+
| [`pakdatakit_flutter`](https://github.com/chmuzamil/pakdatakit/tree/main/flutter) | `flutter pub add pakdatakit_flutter` | Flutter input formatters, form fields and a Raast QR widget |
|
|
54
|
+
| [`PakDataKit` (.NET)](https://github.com/chmuzamil/pakdatakit/tree/main/dotnet) | Build from `dotnet/` (not on NuGet yet) | .NET 8, same functions and data, with DataAnnotations and FluentValidation packages |
|
|
55
|
+
| [`chmuzamil/pakdatakit` (PHP)](https://github.com/chmuzamil/pakdatakit/tree/main/php) | Build from `php/` (not on Packagist yet) | PHP 8.2+, same functions and data, with Laravel rules, rule objects and Eloquent casts |
|
|
56
|
+
| [`pakdatakit-vue`](https://github.com/chmuzamil/pakdatakit/tree/main/vue) | Build from `vue/` (not on npm yet) | Vue 3 composables and a `v-pak-input` directive that format as you type |
|
|
57
|
+
| [`pakdatakit-angular`](https://github.com/chmuzamil/pakdatakit/tree/main/angular) | Build from `angular/` (not on npm yet) | Angular directives, pipes and form validators |
|
|
58
|
+
| [`pakdatakit-pay`](https://github.com/chmuzamil/pakdatakit/tree/main/pay) | Build from `pay/` (not on npm yet) | Server-side JazzCash secure hash: build it and verify responses in constant time |
|
|
59
|
+
|
|
60
|
+
The Python, Dart, .NET and PHP packages are checked against the TypeScript library with over 25,000 shared test cases, so all five give the same results.
|
|
56
61
|
|
|
57
62
|
---
|
|
58
63
|
|
|
@@ -66,20 +71,22 @@ The Python and Dart packages are checked against the TypeScript library with ove
|
|
|
66
71
|
|
|
67
72
|
## Why PakDataKit?
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- Validate CNIC numbers
|
|
72
|
-
- Normalize mobile numbers
|
|
73
|
-
- Detect mobile networks
|
|
74
|
-
- Generate WhatsApp click-to-chat links
|
|
75
|
-
- Validate Pakistani IBANs and detect banks
|
|
76
|
-
- Look up postal codes and cities
|
|
77
|
-
- Map cities to provinces
|
|
78
|
-
- Format PKR values in Lakh and Crore conventions
|
|
74
|
+
Most Pakistani apps validate CNICs, mobile numbers and IBANs with a regex copied from somewhere. A regex checks the shape. PakDataKit checks what the shape can't show:
|
|
79
75
|
|
|
80
|
-
|
|
76
|
+
| Task | Typical regex | PakDataKit |
|
|
77
|
+
| ----------------- | ---------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
78
|
+
| CNIC | 13 digits, maybe with dashes | Province code, province and gender decoding, Urdu digits |
|
|
79
|
+
| Mobile number | `03` + 9 digits | Allocated `03XX` prefixes only, `+92` / `0092` / `0` forms, original network |
|
|
80
|
+
| IBAN | `PK` + 22 characters | Mod-97 checksum, bank name and type from the bank code |
|
|
81
|
+
| NTN / STRN | Digit count | CNIC-based and business NTNs, display formats |
|
|
82
|
+
| Passport, plates | Usually not handled | Common-shape checks, with sources and limits in [DATA.md](./DATA.md) |
|
|
83
|
+
| Raast QR | Not possible | Create, parse and check payment QR codes (CRC, IBAN, amount, expiry) |
|
|
84
|
+
| Holidays, Hijri | Not possible | Observed Eid/Ashura/Milad dates from official notifications, Hijri conversion |
|
|
85
|
+
| Amounts, currency | Not possible | Lakh/crore formatting, amounts in words in English and Urdu |
|
|
86
|
+
| Forms | Write each rule per library | Ready rules for Zod, Valibot, Yup, Joi, Superstruct and class-validator (NestJS) |
|
|
87
|
+
| Other languages | Rewrite it | Python and Dart packages with the core functions, checked against over 25,000 shared test cases |
|
|
81
88
|
|
|
82
|
-
|
|
89
|
+
The npm package has no runtime dependencies, ships ESM and CommonJS with TypeScript types, and works offline: all data is bundled. Every dataset lists its sources in [DATA.md](./DATA.md).
|
|
83
90
|
|
|
84
91
|
---
|
|
85
92
|
|
|
@@ -139,7 +146,7 @@ import { validateCNIC } from 'pakdatakit/cnic';
|
|
|
139
146
|
const { analyzePhone } = require('pakdatakit/phone');
|
|
140
147
|
```
|
|
141
148
|
|
|
142
|
-
Subpaths: `address`, `cnic`, `format`, `geo`, `hijri`, `holidays`, `iban`, `input`, `networks`, `numbers`, `phone`, `postal`, `raast`, `tax`, `text`, `whatsapp`, `words`, plus the form adapters `zod`, `valibot` and `
|
|
149
|
+
Subpaths: `address`, `cnic`, `format`, `geo`, `hijri`, `holidays`, `iban`, `input`, `networks`, `numbers`, `passport`, `phone`, `postal`, `raast`, `tax`, `text`, `vehicle`, `whatsapp`, `words`, plus the form adapters `zod`, `valibot`, `yup`, `joi`, `superstruct` and `class-validator`.
|
|
143
150
|
|
|
144
151
|
---
|
|
145
152
|
|
|
@@ -396,7 +403,7 @@ getBankFromIBAN('invalid');
|
|
|
396
403
|
// null
|
|
397
404
|
```
|
|
398
405
|
|
|
399
|
-
Supported bank codes include HABB, MEZN, SCBL, UNIL, BAHL, NBPA, MUCB, JSBL, SADA (SadaPay), NAYA (NayaPay), RQMI (Raqami), MSHQ (Mashreq), and
|
|
406
|
+
Supported bank codes include HABB, MEZN, SCBL, UNIL, BAHL, NBPA, MUCB, JSBL, SADA (SadaPay), NAYA (NayaPay), RQMI (Raqami), MSHQ (Mashreq), and 50 total entries in the dataset, checked against real IBANs (see [DATA.md](./DATA.md)). Merged or renamed banks are labelled with their current name, e.g. `SAUD` → "Silkbank Limited (merged into United Bank Limited)".
|
|
400
407
|
|
|
401
408
|
---
|
|
402
409
|
|
|
@@ -404,7 +411,7 @@ Supported bank codes include HABB, MEZN, SCBL, UNIL, BAHL, NBPA, MUCB, JSBL, SAD
|
|
|
404
411
|
|
|
405
412
|
### getCityByPostalCode()
|
|
406
413
|
|
|
407
|
-
Returns the city for a Pakistani postal code.
|
|
414
|
+
Returns the city for a Pakistani postal code. Only codes of post offices in a city on pakdatakit's city list return a city; codes of offices in other towns and villages return `null` (use `getPostOffice()` for those).
|
|
408
415
|
|
|
409
416
|
```ts
|
|
410
417
|
getCityByPostalCode(postalCode: string): string | null
|
|
@@ -416,6 +423,12 @@ Examples:
|
|
|
416
423
|
getCityByPostalCode('60000');
|
|
417
424
|
// "Multan"
|
|
418
425
|
|
|
426
|
+
getCityByPostalCode('54660');
|
|
427
|
+
// "Lahore"
|
|
428
|
+
|
|
429
|
+
getCityByPostalCode('48330');
|
|
430
|
+
// null (a village post office; see getPostOffice)
|
|
431
|
+
|
|
419
432
|
getCityByPostalCode('99999');
|
|
420
433
|
// null
|
|
421
434
|
```
|
|
@@ -442,6 +455,30 @@ getPostalCode('karachi');
|
|
|
442
455
|
|
|
443
456
|
---
|
|
444
457
|
|
|
458
|
+
### getPostOffice() / searchPostOffices()
|
|
459
|
+
|
|
460
|
+
Every delivery post office in Pakistan Post's directory (about 2,560), including those in towns and villages.
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
getPostOffice(code: string): PostOffice | null
|
|
464
|
+
searchPostOffices(query: string): PostOffice[] // by office name, town or code prefix
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
```ts
|
|
468
|
+
getPostOffice('48330');
|
|
469
|
+
// { code: "48330", office: "Dulmial", town: "Dulmial", district: null, province: "Punjab" }
|
|
470
|
+
|
|
471
|
+
getPostOffice('54660');
|
|
472
|
+
// { code: "54660", office: "Lahore Gulberg Colony", town: "Lahore", district: "Lahore", province: "Punjab" }
|
|
473
|
+
|
|
474
|
+
searchPostOffices('dulmial');
|
|
475
|
+
// [{ code: "48330", office: "Dulmial", ... }]
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
`town` is the city the office belongs to when that is known, and otherwise the office's own name, which is usually its town or village. `district` is only given for offices in a district's headquarters town; the directory has no district column. The directory is a separate data file (about 32 kB gzipped), so it is only bundled when you call these functions.
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
445
482
|
## Mobile Networks
|
|
446
483
|
|
|
447
484
|
### getNetwork()
|
|
@@ -557,6 +594,43 @@ searchDistricts('karachi'); // ["Karachi Central", "Karachi East", ...]
|
|
|
557
594
|
|
|
558
595
|
---
|
|
559
596
|
|
|
597
|
+
### getDivisions() / getDivisionOfDistrict()
|
|
598
|
+
|
|
599
|
+
The 30 administrative divisions of the 2023 census (Punjab 9, Sindh 6, Khyber Pakhtunkhwa 7, Balochistan 8).
|
|
600
|
+
|
|
601
|
+
```ts
|
|
602
|
+
getDivisions('Sindh');
|
|
603
|
+
// ["Hyderabad", "Karachi", "Larkana", "Mirpur Khas", "Shaheed Benazirabad", "Sukkur"]
|
|
604
|
+
|
|
605
|
+
getDivisionOfDistrict('Attock'); // "Rawalpindi"
|
|
606
|
+
getDivisionOfDistrict('Quetta East'); // null (created after the census)
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
### getTehsils() / getTehsilDistrict()
|
|
612
|
+
|
|
613
|
+
The 591 tehsils, talukas and sub-divisions of the 2023 census.
|
|
614
|
+
|
|
615
|
+
```ts
|
|
616
|
+
getTehsils('Toba Tek Singh');
|
|
617
|
+
// ["Gojra", "Kamalia", "Pirmahal", "Toba Tek Singh"]
|
|
618
|
+
|
|
619
|
+
getTehsilDistrict('Gojra'); // "Toba Tek Singh"
|
|
620
|
+
getTehsilDistrict('Khanpur'); // null (three districts have a Khanpur)
|
|
621
|
+
getTehsilDistrict('Khanpur', 'Sindh'); // "Shikarpur"
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
**Census districts.** Every tehsil is recorded under the district it was in at the 2023 census, which had 136 districts. Districts created or split since then (Murree, Talagang, Quetta East and West, and others) are handled like this:
|
|
625
|
+
|
|
626
|
+
- `getTehsils('Rawalpindi')` still lists Murree, as the census did.
|
|
627
|
+
- `getTehsils('Murree')` lists only the tehsils an official source places in the new district (Kotli Sattian and Murree). Where no official list could be found, as for `Quetta East`, it is empty.
|
|
628
|
+
- `getTehsilDistrict()` and `getDivisionOfDistrict()` answer with census names: `Quetta`, not Quetta East or Quetta West.
|
|
629
|
+
|
|
630
|
+
Azad Jammu and Kashmir and Gilgit-Baltistan are not in the census tables, so they have no divisions or tehsils here. See [DATA.md](./DATA.md).
|
|
631
|
+
|
|
632
|
+
---
|
|
633
|
+
|
|
560
634
|
## Address Utilities
|
|
561
635
|
|
|
562
636
|
### parseAddress()
|
|
@@ -582,6 +656,53 @@ Formats structured components back into a mailing address string. Only the compo
|
|
|
582
656
|
|
|
583
657
|
---
|
|
584
658
|
|
|
659
|
+
## Cash on Delivery Checks
|
|
660
|
+
|
|
661
|
+
`import { scoreAddress, phoneRiskSignals } from 'pakdatakit/quality'`
|
|
662
|
+
|
|
663
|
+
Heuristics for spotting an order a rider will struggle to deliver. They look only at the text you pass: no lists of real people or numbers, no network calls, and they never throw.
|
|
664
|
+
|
|
665
|
+
### scoreAddress()
|
|
666
|
+
|
|
667
|
+
Scores a delivery address from 0 to 100 and lists what is missing. Built on `parseAddress` and the Pakistan Post directory: a postal code that is a known post office scores higher than an unknown one, and one in a different province from the city lowers the score.
|
|
668
|
+
|
|
669
|
+
```ts
|
|
670
|
+
scoreAddress(
|
|
671
|
+
'House 12, Street 4, Block B, Gulberg III, near Liberty Market, Lahore 54660',
|
|
672
|
+
);
|
|
673
|
+
// { score: 100, missing: [], parsed: { city: "Lahore", postalCode: "54660", ... } }
|
|
674
|
+
|
|
675
|
+
scoreAddress('Lahore').missing;
|
|
676
|
+
// ["houseNumber", "street", "area", "postalCode", "landmark"]
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
| Part | Points | Found when |
|
|
680
|
+
| ------------- | -----: | ------------------------------------------------------------------------------------------------- |
|
|
681
|
+
| `city` | 30 | `parseAddress` finds a city |
|
|
682
|
+
| `houseNumber` | 20 | a number other than the postal code ("House 12", "12b", "Flat 2") |
|
|
683
|
+
| `street` | 15 | street, road, lane, gali, chowk, bazaar, mohalla, گلی, محلہ … |
|
|
684
|
+
| `area` | 10 | an area segment, or block, sector, phase, town, colony, society, بلاک, سیکٹر … |
|
|
685
|
+
| `postalCode` | 15 | a known post office code (an unknown 5-digit code scores 5) |
|
|
686
|
+
| `landmark` | 10 | near, opp, behind, next to; nazd, nazdeek, qareeb, samne, peechay, bilmuqabil; نزد، قریب، سامنے … |
|
|
687
|
+
|
|
688
|
+
The weights are exported as `ADDRESS_WEIGHTS`. Importing `scoreAddress` adds about 44 kB gzipped (the post office directory); `phoneRiskSignals` alone is about 3 kB.
|
|
689
|
+
|
|
690
|
+
### phoneRiskSignals()
|
|
691
|
+
|
|
692
|
+
Returns the reasons to double-check a phone number given for a delivery, or `[]`.
|
|
693
|
+
|
|
694
|
+
```ts
|
|
695
|
+
phoneRiskSignals('0301-2945716'); // []
|
|
696
|
+
phoneRiskSignals('03001234567'); // ["sequential-digits", "test-number"]
|
|
697
|
+
phoneRiskSignals('03000000000'); // ["repeated-digits"]
|
|
698
|
+
phoneRiskSignals('042 35761234'); // ["landline"]
|
|
699
|
+
phoneRiskSignals('12345'); // ["invalid"]
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
Flags: `invalid`, `landline`, `not-mobile` (UAN, toll-free and other service numbers), `repeated-digits` (the 7-digit subscriber part uses at most two digits), `sequential-digits` (`1234567`, `7654321` …) and `test-number` (`03XX-1234567`, `03XX-7654321`, `0312-3456789`). The form adapters have a matching `pk.codPhone()` rule that passes only when there are no flags.
|
|
703
|
+
|
|
704
|
+
---
|
|
705
|
+
|
|
585
706
|
## Text Utilities
|
|
586
707
|
|
|
587
708
|
### normalizeRomanUrdu()
|
|
@@ -592,6 +713,58 @@ Normalizes informal Roman Urdu spellings (`ap kia ker` → `aap kya kar`).
|
|
|
592
713
|
|
|
593
714
|
Convert between English, Urdu, and Arabic-Indic digits.
|
|
594
715
|
|
|
716
|
+
### slugify()
|
|
717
|
+
|
|
718
|
+
Turns text into a URL slug. Urdu letters are kept as they are: Urdu does not write short vowels, so there is no single Roman spelling to transliterate to. Diacritics and zero-width characters are dropped, Urdu digits become `0-9`, and `script` limits which letters are kept (`any`, the default; `latin`; `urdu`).
|
|
719
|
+
|
|
720
|
+
```ts
|
|
721
|
+
slugify('Lahore Fort, 2024'); // "lahore-fort-2024"
|
|
722
|
+
slugify('لاہور قلعہ'); // "لاہور-قلعہ"
|
|
723
|
+
slugify('لاہور Fort', { script: 'latin' }); // "fort"
|
|
724
|
+
slugify('کراچی ۲۰۲۴', { script: 'urdu' }); // "کراچی-2024"
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### compareUrdu()
|
|
728
|
+
|
|
729
|
+
Sorts Urdu in alphabetical order, following the Unicode CLDR collation for Urdu (CLDR 49): ا آ ب بھ پ پھ ت تھ ٹ … ی یھ ے. A letter joined with ھ (بھ, پھ, کھ …) is a letter of its own, so بھائی comes after every other ب word. The same order is used in every port, without depending on the platform's ICU.
|
|
730
|
+
|
|
731
|
+
```ts
|
|
732
|
+
['ے', 'بھائی', 'آم', 'باغ', 'اب'].sort(compareUrdu);
|
|
733
|
+
// ["اب", "آم", "باغ", "بھائی", "ے"]
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
Digits come before letters (one digit at a time, so `10` before `2`), and other scripts after. The Arabic look-alikes ك ي ه are not Urdu letters in CLDR and sort after ے; write ک ی ہ to sort them as Urdu.
|
|
737
|
+
|
|
738
|
+
### isRTL() / wrapBidi()
|
|
739
|
+
|
|
740
|
+
`isRTL` is `true` when the first letter is from a right-to-left script. `wrapBidi` wraps text in Unicode directional isolates (FSI … PDI, or RLI/LRI with `'rtl'`/`'ltr'`), so an English order number or name does not jumble an Urdu sentence.
|
|
741
|
+
|
|
742
|
+
```ts
|
|
743
|
+
isRTL('123 سلام'); // true
|
|
744
|
+
isRTL('Order نمبر'); // false
|
|
745
|
+
`آرڈر ${wrapBidi('PDK-1042')} بھیج دیا گیا`;
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
---
|
|
749
|
+
|
|
750
|
+
## Income Tax on Salary
|
|
751
|
+
|
|
752
|
+
`import { calculateSalaryTax } from 'pakdatakit/incometax'`
|
|
753
|
+
|
|
754
|
+
Income tax on a salaried individual's taxable income, from the salaried rate table in the Income Tax Ordinance 2001 (First Schedule, Part I, Division I, clause (2), which applies when salary is more than 75% of taxable income). Tax years 2020 to 2027 are covered; a tax year runs from 1 July to 30 June and is named after the June it ends in.
|
|
755
|
+
|
|
756
|
+
```ts
|
|
757
|
+
calculateSalaryTax(1_800_000, { taxYear: 2026 });
|
|
758
|
+
// { tax: 72000, monthly: 6000, effectiveRate: 4,
|
|
759
|
+
// slab: { over: 1200000, upTo: 2200000, fixed: 6000, rate: 11 }, taxYear: 2026 }
|
|
760
|
+
|
|
761
|
+
calculateMonthlySalaryTax(150_000, { taxYear: 2026 })?.monthly; // 6000
|
|
762
|
+
getSalaryTaxSlabs(2027); // the table, its law and FBR source
|
|
763
|
+
getTaxYear('2025-07-01'); // 2026
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
Without `taxYear` or `date`, the current tax year is used, and a year that is not covered returns `null`. Tax is rounded half up to the paisa. Only the rate table is applied: the surcharge, tax credits, exemptions, the separate rate for pensions and withholding adjustments are not. Sources and the full table are in [DATA.md](DATA.md#income-tax-on-salary-income-tax-slabsjson).
|
|
767
|
+
|
|
595
768
|
---
|
|
596
769
|
|
|
597
770
|
## Hijri Calendar
|
|
@@ -710,6 +883,215 @@ FBR does not publish its check-digit algorithms, so these check the format only.
|
|
|
710
883
|
|
|
711
884
|
---
|
|
712
885
|
|
|
886
|
+
## Sales Tax
|
|
887
|
+
|
|
888
|
+
`import { getSalesTaxRate, calculateSalesTax, splitInclusive } from 'pakdatakit/salestax'`
|
|
889
|
+
|
|
890
|
+
Standard sales tax rates with the dates they applied, from 1 July 2019: federal sales tax on goods (FBR), and sales tax on services in Punjab (PRA), Sindh (SRB), Khyber Pakhtunkhwa (KPRA), Balochistan (BRA) and Islamabad Capital Territory (FBR). Each rate carries the law and the official document it comes from ([DATA.md](DATA.md#sales-tax-rates-sales-tax-ratesjson)). Reduced, higher and sector rates are not included.
|
|
891
|
+
|
|
892
|
+
### getSalesTaxRate()
|
|
893
|
+
|
|
894
|
+
```ts
|
|
895
|
+
getSalesTaxRate({ kind: 'goods', date: '2026-11-18' });
|
|
896
|
+
// { kind: "goods", authority: "FBR", province: null, rate: 18, from: "2023-02-23", to: null, law: "Sales Tax Act 1990, s. 3(1), …", source: "https://download1.fbr.gov.pk/…" }
|
|
897
|
+
|
|
898
|
+
getSalesTaxRate({ kind: 'services', province: 'Sindh', date: '2024-06-30' })
|
|
899
|
+
?.rate; // 13
|
|
900
|
+
getSalesTaxRate({ kind: 'services', province: 'ICT' })?.rate; // 15 (today)
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
`province` accepts the province names and `KP`, `KPK`, `ICT` and `Islamabad`. It returns `null` for a date before 1 July 2019, an invalid date, an unknown province, services without a province, or goods in Azad Jammu and Kashmir or Gilgit-Baltistan.
|
|
904
|
+
|
|
905
|
+
### calculateSalesTax() / splitInclusive()
|
|
906
|
+
|
|
907
|
+
```ts
|
|
908
|
+
calculateSalesTax(1000, { rate: 18 });
|
|
909
|
+
// { net: 1000, tax: 180, gross: 1180, rate: 18 }
|
|
910
|
+
|
|
911
|
+
calculateSalesTax(1000, { province: 'Punjab' });
|
|
912
|
+
// { net: 1000, tax: 160, gross: 1160, rate: 16 }
|
|
913
|
+
|
|
914
|
+
calculateSalesTax(1150, { province: 'Sindh', inclusive: true });
|
|
915
|
+
// { net: 1000, tax: 150, gross: 1150, rate: 15 }
|
|
916
|
+
|
|
917
|
+
splitInclusive(99.99, 18);
|
|
918
|
+
// { net: 84.74, tax: 15.25, gross: 99.99, rate: 18 }
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
Amounts are rounded half up to the paisa, reading the number as written (`1.005` is Rs 1.01). For an inclusive amount the value is rounded and the tax is the rest, so `net + tax` always equals `gross`. Amounts from 0 to one trillion rupees and rates from 0 to 100 with at most two decimals are accepted; anything else returns `null`, never an exception.
|
|
922
|
+
|
|
923
|
+
---
|
|
924
|
+
|
|
925
|
+
## Utility Bills
|
|
926
|
+
|
|
927
|
+
`import { parseElectricityRef, validateElectricityRef, validateGasConsumerNumber } from 'pakdatakit/bills'`
|
|
928
|
+
|
|
929
|
+
### parseElectricityRef() / validateElectricityRef()
|
|
930
|
+
|
|
931
|
+
Reads the identifiers printed on electricity bills, in the formats the utilities' own bill pages ask for:
|
|
932
|
+
|
|
933
|
+
| `type` | Format | Example |
|
|
934
|
+
| ------------- | ---------------------------------------------------------- | -------------------- |
|
|
935
|
+
| `reference` | DISCO (WAPDA) reference number: 14 digits, optional U or R | `02 12624 0045901 R` |
|
|
936
|
+
| `customer-id` | DISCO customer ID: 10 digits (11 for LESCO) | `1234567890` |
|
|
937
|
+
| `k-electric` | K-Electric account number: 13 digits starting `04000` | `0400012345678` |
|
|
938
|
+
|
|
939
|
+
```ts
|
|
940
|
+
parseElectricityRef('02-12624-0045901 R');
|
|
941
|
+
// { type: "reference", digits: "02126240045901", formatted: "02 12624 0045901 R", urbanRural: "R", disco: null }
|
|
942
|
+
|
|
943
|
+
parseElectricityRef('0400012345678');
|
|
944
|
+
// { type: "k-electric", digits: "0400012345678", formatted: "0400012345678", urbanRural: null, disco: "K-Electric" }
|
|
945
|
+
|
|
946
|
+
validateElectricityRef('12345'); // false
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
Spaces, dashes and dots are ignored, and Urdu digits are accepted. `disco` is `null` for DISCO bills: no official source maps reference or customer ID digits to a distribution company, so the library does not guess. No utility publishes a check digit, so only the format is checked; a well-formed number may still not exist.
|
|
950
|
+
|
|
951
|
+
### validateGasConsumerNumber()
|
|
952
|
+
|
|
953
|
+
```ts
|
|
954
|
+
validateGasConsumerNumber('12345678901', 'SNGPL'); // true (11 digits)
|
|
955
|
+
validateGasConsumerNumber('1234567890', 'SSGC'); // true (10 digits)
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
Sources are in [DATA.md](DATA.md#electricity-and-gas-bill-numbers).
|
|
959
|
+
|
|
960
|
+
---
|
|
961
|
+
|
|
962
|
+
## Couriers
|
|
963
|
+
|
|
964
|
+
`import { mapCourierStatus, normalizeCityForCourier } from 'pakdatakit/courier'`
|
|
965
|
+
|
|
966
|
+
Helpers for orders shipped with Pakistani couriers. There are no API clients: nothing is sent anywhere.
|
|
967
|
+
|
|
968
|
+
### mapCourierStatus()
|
|
969
|
+
|
|
970
|
+
> **Experimental.** `mapCourierStatus` and the `CourierStatus` values may change in a minor release while more couriers' status lists are added. Pin a minor version if you store these values. To add a courier, see [CONTRIBUTING.md](CONTRIBUTING.md#courier-status-lists).
|
|
971
|
+
|
|
972
|
+
Maps a courier's own status (name, numeric ID or code) to one vocabulary: `pending`, `booked`, `picked-up`, `in-transit`, `out-for-delivery`, `attempted`, `under-review`, `delivered`, `returning`, `returned` or `cancelled`.
|
|
973
|
+
|
|
974
|
+
```ts
|
|
975
|
+
mapCourierStatus('PostEx', 'Out For Delivery'); // "out-for-delivery"
|
|
976
|
+
mapCourierStatus('PostEx', 5); // "delivered"
|
|
977
|
+
mapCourierStatus('PostEx', 'Attempt Made: Customer not available'); // "attempted"
|
|
978
|
+
mapCourierStatus('Leopards', 'Returned to Shipper'); // "returned"
|
|
979
|
+
mapCourierStatus('TCS', 'Delivered'); // null
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
Only statuses a courier documents publicly are mapped: every order status and tracking code in PostEx's merchant API guide (v4.1.9), and Leopards' "Returned to Shipper". TCS, M&P, Trax and BlueEx publish no status list outside their merchant portals, so they return `null` for now, as does any status not in the list. No courier documents its tracking number format, so there is no tracking-number detection. Details are in [DATA.md](DATA.md#couriers).
|
|
983
|
+
|
|
984
|
+
### normalizeCityForCourier()
|
|
985
|
+
|
|
986
|
+
Maps how a customer or a courier writes a city to its name in the city list, so orders can be matched against a courier's service list.
|
|
987
|
+
|
|
988
|
+
```ts
|
|
989
|
+
normalizeCityForCourier('LHR'); // "Lahore"
|
|
990
|
+
normalizeCityForCourier('Khi'); // "Karachi"
|
|
991
|
+
normalizeCityForCourier('Pindi'); // "Rawalpindi"
|
|
992
|
+
normalizeCityForCourier('lyallpur'); // "Faisalabad"
|
|
993
|
+
normalizeCityForCourier('Karachi City'); // "Karachi"
|
|
994
|
+
normalizeCityForCourier('لاہور'); // "Lahore"
|
|
995
|
+
normalizeCityForCourier('Atlantis'); // null
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
---
|
|
999
|
+
|
|
1000
|
+
## FBR Digital Invoicing
|
|
1001
|
+
|
|
1002
|
+
`import { buildFbrInvoice, validateFbrInvoice } from 'pakdatakit/fbr-invoice'`
|
|
1003
|
+
|
|
1004
|
+
Types, a builder and an offline validator for the invoice JSON that FBR's Digital Invoicing API accepts (`postinvoicedata` and `validateinvoicedata`), following PRAL's "Technical Specification for DI API" version 1.12 (`FBR_DI_SPEC_VERSION`) and PRAL's Error Message Guide. There is no HTTP client and no token handling: send the invoice with your own code.
|
|
1005
|
+
|
|
1006
|
+
### buildFbrInvoice()
|
|
1007
|
+
|
|
1008
|
+
Works out each line's `salesTaxApplicable` when you leave it out (with `calculateSalesTax`), fills FBR's defaults and adds up the columns.
|
|
1009
|
+
|
|
1010
|
+
```ts
|
|
1011
|
+
const { invoice, totals } = buildFbrInvoice({
|
|
1012
|
+
invoiceType: 'Sale Invoice',
|
|
1013
|
+
invoiceDate: '2025-04-21',
|
|
1014
|
+
sellerNTNCNIC: '1234567',
|
|
1015
|
+
sellerBusinessName: 'Example Traders',
|
|
1016
|
+
sellerProvince: 'Sindh',
|
|
1017
|
+
sellerAddress: 'Karachi',
|
|
1018
|
+
buyerNTNCNIC: '7654321',
|
|
1019
|
+
buyerBusinessName: 'Example Buyer',
|
|
1020
|
+
buyerProvince: 'Punjab',
|
|
1021
|
+
buyerAddress: 'Lahore',
|
|
1022
|
+
buyerRegistrationType: 'Registered',
|
|
1023
|
+
items: [
|
|
1024
|
+
{
|
|
1025
|
+
hsCode: '0101.2100',
|
|
1026
|
+
productDescription: 'Horses',
|
|
1027
|
+
rate: '18%',
|
|
1028
|
+
uoM: 'Numbers, pieces, units',
|
|
1029
|
+
quantity: 2,
|
|
1030
|
+
valueSalesExcludingST: 1234,
|
|
1031
|
+
saleType: 'Goods at standard rate (default)',
|
|
1032
|
+
},
|
|
1033
|
+
],
|
|
1034
|
+
})!;
|
|
1035
|
+
invoice.items[0].salesTaxApplicable; // 222.12
|
|
1036
|
+
totals.salesTaxApplicable; // 222.12
|
|
1037
|
+
```
|
|
1038
|
+
|
|
1039
|
+
Rates of the form `N%` use the value excluding sales tax (or the retail price for Third Schedule goods); `Rs.N` rates use the quantity. Other rates (`Exempt`, combined rates) get 0 unless you give the tax.
|
|
1040
|
+
|
|
1041
|
+
### validateFbrInvoice()
|
|
1042
|
+
|
|
1043
|
+
Returns every problem it can find without calling FBR, with FBR's error code:
|
|
1044
|
+
|
|
1045
|
+
```ts
|
|
1046
|
+
validateFbrInvoice(invoice);
|
|
1047
|
+
// { valid: true, errors: [] }
|
|
1048
|
+
|
|
1049
|
+
validateFbrInvoice({
|
|
1050
|
+
...invoice,
|
|
1051
|
+
invoiceDate: '21-04-2025',
|
|
1052
|
+
buyerNTNCNIC: invoice.sellerNTNCNIC,
|
|
1053
|
+
});
|
|
1054
|
+
// { valid: false, errors: [
|
|
1055
|
+
// { code: "0005", field: "invoiceDate", message: "Invoice date must be in YYYY-MM-DD format" },
|
|
1056
|
+
// { code: "0058", field: "buyerNTNCNIC", message: "Buyer and seller must be different (self-invoicing is not allowed)" } ] }
|
|
1057
|
+
```
|
|
1058
|
+
|
|
1059
|
+
It checks required fields, formats (date, NTN/CNIC, FBR invoice number, sandbox scenario), amounts (not negative, at most 2 decimals, 4 for quantity), SRO rules and the sales tax arithmetic (to within one paisa). Pass `{ today: 'YYYY-MM-DD' }` to also reject future dates. It cannot check what needs FBR's reference APIs: registration status, and whether a province, HS code, unit, rate, sale type or SRO is in FBR's lists. A `valid` result means FBR's own validation is likely to pass, not that it will.
|
|
1060
|
+
|
|
1061
|
+
---
|
|
1062
|
+
|
|
1063
|
+
## Passports & Vehicle Plates
|
|
1064
|
+
|
|
1065
|
+
### validatePassport()
|
|
1066
|
+
|
|
1067
|
+
Checks the format of a Pakistani passport number: two letters and seven digits.
|
|
1068
|
+
|
|
1069
|
+
```ts
|
|
1070
|
+
validatePassport('AB1234567'); // true
|
|
1071
|
+
validatePassport('ab 1234567'); // true
|
|
1072
|
+
validatePassport('A12345678'); // false
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
DGIP does not publish the format, so this checks the common shape only. Other passport types may differ; see [DATA.md](./DATA.md#passport-numbers).
|
|
1076
|
+
|
|
1077
|
+
### parseVehiclePlate() / validateVehiclePlate()
|
|
1078
|
+
|
|
1079
|
+
Splits a vehicle registration number into its series letters, number and the optional year that older Punjab plates carry.
|
|
1080
|
+
|
|
1081
|
+
```ts
|
|
1082
|
+
parseVehiclePlate('lea 1234');
|
|
1083
|
+
// { series: 'LEA', number: '1234', year: null, formatted: 'LEA-1234' }
|
|
1084
|
+
|
|
1085
|
+
parseVehiclePlate('LEA-1234-19');
|
|
1086
|
+
// { series: 'LEA', number: '1234', year: '19', formatted: 'LEA-1234' }
|
|
1087
|
+
|
|
1088
|
+
validateVehiclePlate('ABC-123'); // true
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
Each province sets its own format and several changed in 2024–2026, so this accepts the shape they share (1–4 letters, then 1–4 digits) and does not check series letters against districts. See [DATA.md](./DATA.md#vehicle-registration-plates).
|
|
1092
|
+
|
|
1093
|
+
---
|
|
1094
|
+
|
|
713
1095
|
## Raast QR Codes
|
|
714
1096
|
|
|
715
1097
|
### createRaastP2PQr() / createMerchantQr() / parseRaastQr()
|
|
@@ -802,7 +1184,7 @@ Fixed holidays follow the year they applied in: Iqbal Day was restored in 2022 a
|
|
|
802
1184
|
|
|
803
1185
|
## Form Validation
|
|
804
1186
|
|
|
805
|
-
Ready-made schemas for [Zod](https://zod.dev), [Valibot](https://valibot.dev)
|
|
1187
|
+
Ready-made schemas for [Zod](https://zod.dev), [Valibot](https://valibot.dev), [Yup](https://github.com/jquense/yup), [Joi](https://joi.dev) and [Superstruct](https://docs.superstructjs.org), and decorators for [class-validator](https://github.com/typestack/class-validator) (and so NestJS). Install the library you use; PakDataKit does not depend on any of them.
|
|
806
1188
|
|
|
807
1189
|
```ts
|
|
808
1190
|
import { z } from 'zod';
|
|
@@ -829,7 +1211,47 @@ import { pk } from 'pakdatakit/yup';
|
|
|
829
1211
|
const CheckoutForm = object({ cnic: pk.cnic().required(), phone: pk.phone() });
|
|
830
1212
|
```
|
|
831
1213
|
|
|
832
|
-
|
|
1214
|
+
```ts
|
|
1215
|
+
import Joi from 'joi';
|
|
1216
|
+
import { pk } from 'pakdatakit/joi';
|
|
1217
|
+
|
|
1218
|
+
const CheckoutForm = Joi.object({
|
|
1219
|
+
cnic: pk.cnic().required(),
|
|
1220
|
+
phone: pk.phone(),
|
|
1221
|
+
});
|
|
1222
|
+
```
|
|
1223
|
+
|
|
1224
|
+
```ts
|
|
1225
|
+
import { object, optional } from 'superstruct';
|
|
1226
|
+
import { pk } from 'pakdatakit/superstruct';
|
|
1227
|
+
|
|
1228
|
+
const CheckoutForm = object({ cnic: pk.cnic(), phone: optional(pk.phone()) });
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
Available schemas: `pk.cnic()`, `pk.phone()`, `pk.iban()`, `pk.ntn()`, `pk.strn()`, `pk.landline()`, `pk.passport()`, `pk.vehiclePlate()` and `pk.codPhone()` (a mobile number with no `phoneRiskSignals` flags). Every factory accepts `{ message }` to replace the default error. The Yup schemas let empty values pass so `.required()` decides whether a field is mandatory.
|
|
1232
|
+
|
|
1233
|
+
### class-validator and NestJS
|
|
1234
|
+
|
|
1235
|
+
Decorators for DTOs, checked by NestJS's `ValidationPipe` like any other class-validator rule. No NestJS package is needed.
|
|
1236
|
+
|
|
1237
|
+
```ts
|
|
1238
|
+
import { IsOptional } from 'class-validator';
|
|
1239
|
+
import { IsCNIC, IsPakIBAN, IsPakPhone } from 'pakdatakit/class-validator';
|
|
1240
|
+
|
|
1241
|
+
export class CreateCustomerDto {
|
|
1242
|
+
@IsCNIC()
|
|
1243
|
+
cnic!: string;
|
|
1244
|
+
|
|
1245
|
+
@IsOptional()
|
|
1246
|
+
@IsPakPhone({ message: 'Enter a Pakistani mobile number' })
|
|
1247
|
+
phone?: string;
|
|
1248
|
+
|
|
1249
|
+
@IsPakIBAN()
|
|
1250
|
+
iban!: string;
|
|
1251
|
+
}
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
Decorators: `IsCNIC`, `IsPakPhone`, `IsPakIBAN` (named so it doesn't clash with class-validator's own `IsIBAN`), `IsNTN`, `IsSTRN`, `IsPakLandline`, `IsPakPassport`, `IsVehiclePlate` and `IsCodPhone`, also available as `pk.cnic()` and so on. They accept class-validator's options (`message`, `groups`, `each`, `always`); use `@IsOptional()` for optional fields. Values that are not strings fail.
|
|
833
1255
|
|
|
834
1256
|
### As-you-type helpers
|
|
835
1257
|
|
|
@@ -988,9 +1410,31 @@ See:
|
|
|
988
1410
|
|
|
989
1411
|
---
|
|
990
1412
|
|
|
1413
|
+
# Origin and attribution
|
|
1414
|
+
|
|
1415
|
+
- First commit: 29 May 2026,
|
|
1416
|
+
[`bdc426a`](https://github.com/chmuzamil/pakdatakit/commit/bdc426a84a1b4359dee218c33196810d6631559d)
|
|
1417
|
+
(git history).
|
|
1418
|
+
- First npm release:
|
|
1419
|
+
[`pakdatakit` 1.0.0](https://www.npmjs.com/package/pakdatakit/v/1.0.0), 29 May
|
|
1420
|
+
2026 (npm registry).
|
|
1421
|
+
|
|
1422
|
+
PakDataKit is released under the MIT licence. This covers the code of every
|
|
1423
|
+
port, the datasets in `data/` and the shared test vectors in `test-vectors/`.
|
|
1424
|
+
Anyone who copies or adapts any substantial part of it, in any language, must
|
|
1425
|
+
keep the copyright notice and the licence text:
|
|
1426
|
+
|
|
1427
|
+
```text
|
|
1428
|
+
Copyright (c) 2026 Muzamil Chaudhery and PakDataKit Contributors
|
|
1429
|
+
```
|
|
1430
|
+
|
|
1431
|
+
The same text is in [NOTICE](NOTICE).
|
|
1432
|
+
|
|
1433
|
+
---
|
|
1434
|
+
|
|
991
1435
|
# License
|
|
992
1436
|
|
|
993
|
-
MIT License
|
|
1437
|
+
MIT License. See [LICENSE](LICENSE).
|
|
994
1438
|
|
|
995
1439
|
---
|
|
996
1440
|
|
package/dist/address.cjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
3
|
+
var chunkQFPEFD67_cjs = require('./chunk-QFPEFD67.cjs');
|
|
4
|
+
require('./chunk-I7UUPD3G.cjs');
|
|
5
|
+
require('./chunk-33GOK7EE.cjs');
|
|
6
|
+
require('./chunk-E6GWBOKV.cjs');
|
|
6
7
|
require('./chunk-VPBMIYO2.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
Object.defineProperty(exports, "formatAddress", {
|
|
11
12
|
enumerable: true,
|
|
12
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkQFPEFD67_cjs.formatAddress; }
|
|
13
14
|
});
|
|
14
15
|
Object.defineProperty(exports, "parseAddress", {
|
|
15
16
|
enumerable: true,
|
|
16
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkQFPEFD67_cjs.parseAddress; }
|
|
17
18
|
});
|
package/dist/address.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { formatAddress, parseAddress } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
export { formatAddress, parseAddress } from './chunk-B7DOQ5QF.js';
|
|
2
|
+
import './chunk-33QMFE2Z.js';
|
|
3
|
+
import './chunk-XOTCIXY6.js';
|
|
4
|
+
import './chunk-E2XU6NOW.js';
|
|
4
5
|
import './chunk-ENQ7O7VW.js';
|
package/dist/bills.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkYQFI7W3I_cjs = require('./chunk-YQFI7W3I.cjs');
|
|
4
|
+
require('./chunk-VPBMIYO2.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "parseElectricityRef", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkYQFI7W3I_cjs.parseElectricityRef; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "validateElectricityRef", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkYQFI7W3I_cjs.validateElectricityRef; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "validateGasConsumerNumber", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkYQFI7W3I_cjs.validateGasConsumerNumber; }
|
|
19
|
+
});
|