pakdatakit 2.5.1 → 2.7.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 +83 -7
- package/README.md +94 -31
- package/dist/{chunk-LQHM3ADX.js → chunk-33JPVN33.js} +11 -6
- package/dist/{chunk-XCFZKCV2.cjs → chunk-36K225SE.cjs} +14 -9
- package/dist/{chunk-CEPNSHIC.js → chunk-3OCMTNQ7.js} +1 -1
- package/dist/{chunk-YDUXIENX.cjs → chunk-4YLSPXBZ.cjs} +2 -2
- package/dist/{chunk-2OBKPYJZ.cjs → chunk-6AIN4FKB.cjs} +12 -4
- package/dist/chunk-7NTUEHQV.cjs +69 -0
- package/dist/{chunk-KRYHLYN2.js → chunk-BATPA7GN.js} +12 -4
- package/dist/chunk-CKCOK6X4.js +64 -0
- package/dist/{chunk-7DY26QPN.js → chunk-CRYCAMWC.js} +1 -1
- package/dist/{chunk-TVL6RDAU.cjs → chunk-EGF4CINK.cjs} +2 -2
- package/dist/{chunk-XVEG53NN.cjs → chunk-GOGEMCGG.cjs} +84 -0
- package/dist/chunk-NDW52ZK3.js +85 -0
- package/dist/chunk-NLSIAPZG.cjs +90 -0
- package/dist/{chunk-IDTRFOQW.js → chunk-OYQJQE5R.js} +10 -5
- package/dist/{chunk-5RGX4DWF.js → chunk-SGGQ6XB2.js} +46 -14
- package/dist/{chunk-UYFTXD4P.js → chunk-T6K46DGW.js} +1 -1
- package/dist/{chunk-AUQFA7EE.cjs → chunk-VSIVT5RT.cjs} +11 -6
- package/dist/{chunk-H6M6L26S.cjs → chunk-VZIBHQC7.cjs} +2 -2
- package/dist/{chunk-EA3SIHYT.js → chunk-WYNM5ZWY.js} +84 -1
- package/dist/{chunk-5DDHO5Z7.cjs → chunk-XWGSREI5.cjs} +46 -14
- package/dist/class-validator.cjs +18 -9
- package/dist/class-validator.d.cts +12 -3
- package/dist/class-validator.d.ts +12 -3
- package/dist/class-validator.js +17 -9
- package/dist/cli.js +1 -1
- package/dist/cnic.cjs +11 -3
- package/dist/cnic.d.cts +80 -3
- package/dist/cnic.d.ts +80 -3
- package/dist/cnic.js +1 -1
- package/dist/format.cjs +11 -3
- package/dist/format.d.cts +57 -1
- package/dist/format.d.ts +57 -1
- package/dist/format.js +1 -1
- package/dist/incometax.cjs +6 -6
- package/dist/incometax.d.cts +51 -7
- package/dist/incometax.d.ts +51 -7
- package/dist/incometax.js +1 -1
- package/dist/index.cjs +67 -47
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +10 -10
- package/dist/input.cjs +8 -8
- package/dist/input.js +2 -2
- package/dist/joi.cjs +10 -8
- package/dist/joi.d.cts +2 -1
- package/dist/joi.d.ts +2 -1
- package/dist/joi.js +9 -7
- package/dist/numbers.cjs +5 -5
- package/dist/numbers.d.cts +28 -5
- package/dist/numbers.d.ts +28 -5
- package/dist/numbers.js +1 -1
- package/dist/quality.cjs +5 -5
- package/dist/quality.js +2 -2
- package/dist/raast.cjs +5 -5
- package/dist/raast.d.cts +17 -6
- package/dist/raast.d.ts +17 -6
- package/dist/raast.js +1 -1
- package/dist/{rules-GxgPiVws.d.cts → rules-GEELAOfb.d.cts} +5 -0
- package/dist/{rules-GxgPiVws.d.ts → rules-GEELAOfb.d.ts} +5 -0
- package/dist/superstruct.cjs +10 -8
- package/dist/superstruct.d.cts +2 -1
- package/dist/superstruct.d.ts +2 -1
- package/dist/superstruct.js +9 -7
- package/dist/tax.cjs +5 -5
- package/dist/tax.d.cts +8 -2
- package/dist/tax.d.ts +8 -2
- package/dist/tax.js +2 -2
- package/dist/text.cjs +13 -9
- package/dist/text.d.cts +40 -4
- package/dist/text.d.ts +40 -4
- package/dist/text.js +1 -1
- package/dist/valibot.cjs +16 -8
- package/dist/valibot.d.cts +2 -1
- package/dist/valibot.d.ts +2 -1
- package/dist/valibot.js +15 -7
- package/dist/words.d.cts +4 -1
- package/dist/words.d.ts +4 -1
- package/dist/yup.cjs +10 -8
- package/dist/yup.d.cts +2 -1
- package/dist/yup.d.ts +2 -1
- package/dist/yup.js +9 -7
- package/dist/zod.cjs +12 -8
- package/dist/zod.d.cts +2 -1
- package/dist/zod.d.ts +2 -1
- package/dist/zod.js +11 -7
- package/package.json +2 -2
- package/dist/chunk-6TSKA2PH.js +0 -38
- package/dist/chunk-EEVNLTB4.js +0 -32
- package/dist/chunk-HTCSHHOR.cjs +0 -35
- package/dist/chunk-LVHTH4P7.cjs +0 -41
package/DATA.md
CHANGED
|
@@ -7,7 +7,7 @@ extracted CSV files in `data/sources/` and read by the generator: Pakistan
|
|
|
7
7
|
Post's post code directory and the 2023 census's administrative units. The exported `dataVersion` is the
|
|
8
8
|
date the data was last checked.
|
|
9
9
|
|
|
10
|
-
**Data version: 2026-11-
|
|
10
|
+
**Data version: 2026-11-22**
|
|
11
11
|
|
|
12
12
|
The datasets were audited against official sources on 16 November 2026;
|
|
13
13
|
[AUDIT.md](AUDIT.md) has the findings, the fixes made and what is still open.
|
|
@@ -132,6 +132,30 @@ plan with the same districts.
|
|
|
132
132
|
- PTCL's own list differs for Azad Jammu and Kashmir (Muzaffarabad "58",
|
|
133
133
|
Kotli "574") and has no Mirpur or Gilgit entry. The ITU plan is the newer
|
|
134
134
|
list from PTA, so it is followed.
|
|
135
|
+
- **Non-geographic numbers** (since 2.7.0), from PTA's documents only:
|
|
136
|
+
- **UAN**: an area code, then `111` and six digits, 11 to 13 digits in all
|
|
137
|
+
("National Universal Access Number" in the ITU plan of 9 November 2021,
|
|
138
|
+
page 1). Written without the area code (`111-123-456`), as UANs are
|
|
139
|
+
advertised, it is accepted with `e164: null`.
|
|
140
|
+
- **Toll-free**: `800` and five digits, 8 in all ("National Toll Free
|
|
141
|
+
Number", same page). Before 2.7.0 an 8-digit form taken from
|
|
142
|
+
libphonenumber was also accepted; PTA's plan does not list it, so it is
|
|
143
|
+
now rejected.
|
|
144
|
+
- **Premium rate**: `0900` and five digits. The 2021 plan does not list
|
|
145
|
+
0900; PTA's National Numbering Plan 2008 (Consultation Paper, final
|
|
146
|
+
version, 25 June 2008, section 9.1.4,
|
|
147
|
+
https://www.pta.gov.pk/assets/media/nnp_08_final.pdf, retrieved
|
|
148
|
+
2026-11-22) gives this as the "current structure". The 6-digit form in
|
|
149
|
+
the same paper was a proposal.
|
|
150
|
+
- **Personal (`0122`)**: seen in use, no PTA source, not supported
|
|
151
|
+
(decided 2026-11-22). libphonenumber lists `0122` as personal numbers,
|
|
152
|
+
but neither PTA's 2021 plan nor its 2008 paper does, so since 2.7.0
|
|
153
|
+
`analyzeNumber` returns `null` for them and `validateLandline` rejects
|
|
154
|
+
them with or without `services`. The `personal` number type is kept so
|
|
155
|
+
existing code compiles, is never returned, and will be removed in 3.0.
|
|
156
|
+
- The 2008 paper's own text gives `0800` and `111` other lengths (six and
|
|
157
|
+
seven digits) as proposals; the 2021 plan, which is newer and was sent
|
|
158
|
+
to the ITU, is followed.
|
|
135
159
|
- **Number lengths** are not taken from the ITU plan (its length table could
|
|
136
160
|
not be read reliably). The patterns in `numbers.ts` come from
|
|
137
161
|
libphonenumber's PK metadata (v9.0.41), which already accepted numbers in
|
|
@@ -413,15 +437,67 @@ How sure we are, and what is left out:
|
|
|
413
437
|
table was also checked against the Finance Act, 2026 as gazetted and FBR
|
|
414
438
|
Circular No. 02 of 2026-27. For earlier years the Finance Act texts
|
|
415
439
|
(Gazette) were not read; FBR's consolidations are the source.
|
|
416
|
-
- **Not applied** (out of scope):
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
(2026 onwards: 0% up to Rs 10 million, 5% above), and withholding
|
|
421
|
-
adjustments.
|
|
440
|
+
- **Not applied** (out of scope): tax credits, exemptions, the separate
|
|
441
|
+
rate for pension from a former employer (2026 onwards: 0% up to Rs 10
|
|
442
|
+
million, 5% above), super tax under section 4C, and withholding
|
|
443
|
+
adjustments. The section 4AB surcharge is applied on request; see below.
|
|
422
444
|
- Tax is rounded half up to the paisa; the Ordinance's own rounding to whole
|
|
423
445
|
rupees is left to the caller.
|
|
424
446
|
|
|
447
|
+
### Surcharge under section 4AB (`surcharge` in `income-tax-slabs.json`)
|
|
448
|
+
|
|
449
|
+
Since 2.7.0 each tax year carries the section 4AB surcharge, which
|
|
450
|
+
`calculateSalaryTax` adds with `includeSurcharge: true` (off by default in
|
|
451
|
+
2.x). The section's wording, the same in every version: a surcharge "at the
|
|
452
|
+
rate of ten percent of the income tax imposed under Division I of Part I of
|
|
453
|
+
the First Schedule where the taxable income exceeds rupees ten million". It
|
|
454
|
+
is a percentage of the whole tax from the rate table, not of the tax on the
|
|
455
|
+
income above Rs 10 million, so one rupee over the threshold adds it in full
|
|
456
|
+
(there is no marginal relief in the section). All documents retrieved
|
|
457
|
+
2026-11-22.
|
|
458
|
+
|
|
459
|
+
| Tax year | Salaried rate | Law | Source |
|
|
460
|
+
| --------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
461
|
+
| 2020–2024 | none | Section 4AB did not exist (it is absent from FBR's consolidated Ordinance amended up to 30.06.2023) | https://download1.fbr.gov.pk/Docs/202412215122448762IncomeTaxOrdinance,2001Amendedupto30.06.2023.pdf |
|
|
462
|
+
| 2025 | 10% | Finance Act 2024, s. 8(2), Gazette of Pakistan (Extraordinary), 30 June 2024, p. 279: inserts section 4AB; in force 1 July 2024 (s. 1(2)) | https://download1.fbr.gov.pk/Docs/2024630146346801FinanceAct-2024.pdf |
|
|
463
|
+
| 2026 | 9% | Finance Act 2025: adds the proviso "in case of an individual deriving income chargeable under the head Salary, a surcharge shall be payable at the rate of nine percent", per FBR's consolidated Ordinance amended up to 31.07.2025 (footnote 5 to section 4AB) | https://download1.fbr.gov.pk/Docs/2025881983148210Income-Tax-Ordinance,-2001-Amended-upto-31.07.2025.pdf |
|
|
464
|
+
| 2027 | none | Finance Act 2026, s. 5(2)(b): the proviso now reads "no surcharge shall be payable" | https://download1.fbr.gov.pk/Docs/20266291261044366FinanceAct2026.pdf |
|
|
465
|
+
|
|
466
|
+
Supporting FBR documents:
|
|
467
|
+
|
|
468
|
+
- **Circular No. 01 of 2025-26 (Income Tax)**, C. No. 4(32) IT-Budget/2025,
|
|
469
|
+
2 August 2025, page 3: the employer collects the "surcharge, if applicable
|
|
470
|
+
under the provision of section 4AB, at the rate of 9%"
|
|
471
|
+
(https://download1.fbr.gov.pk/Docs/2025841183918948CircularNo01of2025-26IncomeTax.pdf).
|
|
472
|
+
- **Circular No. 02 of 2026-27 (Income Tax)**, 8 September 2026, paragraph
|
|
473
|
+
8: the nine percent surcharge on salaried individuals is withdrawn, and the
|
|
474
|
+
ten percent surcharge on other individuals and associations of persons
|
|
475
|
+
continues (https://download1.fbr.gov.pk/Docs/202698139527880CircularNo.2of2026-27.pdf).
|
|
476
|
+
- **FBR's consolidated Ordinance (2026)** prints section 4AB with the 2026
|
|
477
|
+
proviso and footnotes for each amendment
|
|
478
|
+
(https://download1.fbr.gov.pk/Docs/2026724177725705IncomeTaxOrdinanace2001.pdf).
|
|
479
|
+
|
|
480
|
+
How sure we are:
|
|
481
|
+
|
|
482
|
+
- **Verified** from the section's text in each consolidation and, for 2025
|
|
483
|
+
and 2027, from the Finance Act as gazetted. The Finance Act 2025 itself
|
|
484
|
+
was not read: FBR's budget pages returned HTTP 403 on 2026-11-22. The 9%
|
|
485
|
+
rate for 2026 rests on FBR's consolidation and Circular No. 01 of 2025-26.
|
|
486
|
+
- **Only salaried individuals are covered**, because only the salaried rate
|
|
487
|
+
table is: the 10% rate for other individuals and associations of persons
|
|
488
|
+
is not applied.
|
|
489
|
+
- The surcharge is rounded half up to the paisa, like the tax.
|
|
490
|
+
|
|
491
|
+
## Roman Urdu name spellings (`data/sources/roman-urdu-names.json`)
|
|
492
|
+
|
|
493
|
+
Not used by the library at run time: a test list for `romanUrduKey`. It
|
|
494
|
+
groups everyday spellings of 118 common Pakistani given names and surnames
|
|
495
|
+
(277 spellings), compiled for PakDataKit's tests from common usage; it is
|
|
496
|
+
not an official list. In 2.7.0, 96.8% of pairs of spellings of the same name
|
|
497
|
+
share a key, and 8 of 38,004 pairs of different names (0.021%) do, all from
|
|
498
|
+
two close pairs: Sajid and Sajjad, and Amna and Amina. The test suite fails
|
|
499
|
+
if these rates get worse than 95% and 0.05%.
|
|
500
|
+
|
|
425
501
|
## Urdu alphabetical order (no dataset)
|
|
426
502
|
|
|
427
503
|
`compareUrdu` follows the Unicode CLDR collation tailoring for Urdu
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
<a href="https://www.npmjs.com/package/pakdatakit-pay"><img src="https://img.shields.io/npm/v/pakdatakit-pay?label=pakdatakit-pay" alt="pakdatakit-pay"></a>
|
|
28
28
|
<a href="https://www.npmjs.com/package/pakdatakit"><img src="https://img.shields.io/npm/dm/pakdatakit?label=downloads" alt="npm downloads"></a>
|
|
29
29
|
<a href="https://www.npmjs.com/package/pakdatakit#provenance"><img src="https://img.shields.io/badge/npm-provenance-2ea44f?logo=npm" alt="npm provenance"></a>
|
|
30
|
-
<a href="https://
|
|
30
|
+
<a href="https://pakdatakit.dev/api/typescript/"><img src="https://img.shields.io/badge/docs-API%20reference-blue" alt="API docs"></a>
|
|
31
31
|
</p>
|
|
32
32
|
|
|
33
33
|
PakDataKit validates, formats and looks up Pakistani data: CNICs, mobile and landline numbers, IBANs and banks, NTN/STRN, passports and vehicle plates, Raast QR codes, sales tax and salary income tax, FBR digital invoices, electricity and gas bill references, cities, districts, tehsils, postal codes and post offices, Urdu text, Hijri dates and public holidays.
|
|
@@ -37,27 +37,27 @@ PakDataKit validates, formats and looks up Pakistani data: CNICs, mobile and lan
|
|
|
37
37
|
- **Offline and dependency-free.** All data is bundled and no function makes a network call. The npm package has no runtime dependencies and ships ESM, CommonJS and types.
|
|
38
38
|
- **Sourced data.** Every dataset lists its official sources in [DATA.md](./DATA.md).
|
|
39
39
|
|
|
40
|
-
**[Try it in the playground](https://pakdatakit
|
|
40
|
+
**[pakdatakit.dev](https://pakdatakit.dev/)** · **[Try it in the playground](https://pakdatakit.dev/playground/)** · **[API reference](https://pakdatakit.dev/api/typescript/)** · **[llms.txt](https://pakdatakit.dev/llms.txt)** / **[llms-full.txt](https://pakdatakit.dev/llms-full.txt)** for AI coding assistants
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
44
44
|
## 📦 Packages
|
|
45
45
|
|
|
46
|
-
| Package
|
|
47
|
-
|
|
|
48
|
-
| [`pakdatakit`](https://www.npmjs.com/package/pakdatakit)
|
|
49
|
-
| [`pakdatakit`](https://pypi.org/project/pakdatakit/) ([Python](
|
|
50
|
-
| [`pakdatakit`](https://pub.dev/packages/pakdatakit) ([Dart](
|
|
51
|
-
| [`pakdatakit_flutter`](https://pub.dev/packages/pakdatakit_flutter) ([Flutter](
|
|
52
|
-
| [`PakDataKit`](https://www.nuget.org/packages/PakDataKit) ([.NET](
|
|
53
|
-
| [`PakDataKit.DataAnnotations`](https://www.nuget.org/packages/PakDataKit.DataAnnotations)
|
|
54
|
-
| [`PakDataKit.FluentValidation`](https://www.nuget.org/packages/PakDataKit.FluentValidation)
|
|
55
|
-
| [`chmuzamil/pakdatakit`](https://packagist.org/packages/chmuzamil/pakdatakit) ([PHP/Laravel](
|
|
56
|
-
| [`pakdatakit-react`](https://www.npmjs.com/package/pakdatakit-react) ([React](
|
|
57
|
-
| [`pakdatakit-vue`](https://www.npmjs.com/package/pakdatakit-vue) ([Vue](
|
|
58
|
-
| [`pakdatakit-angular`](https://www.npmjs.com/package/pakdatakit-angular) ([Angular](
|
|
59
|
-
| [`pakdatakit-faker`](https://www.npmjs.com/package/pakdatakit-faker) ([mock data](
|
|
60
|
-
| [`pakdatakit-pay`](https://www.npmjs.com/package/pakdatakit-pay) ([JazzCash hash](
|
|
46
|
+
| Package | Registry | Install | Version |
|
|
47
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| [`pakdatakit`](https://www.npmjs.com/package/pakdatakit) | npm | `npm install pakdatakit` | [](https://www.npmjs.com/package/pakdatakit) |
|
|
49
|
+
| [`pakdatakit`](https://pypi.org/project/pakdatakit/) ([Python](https://github.com/chmuzamil/pakdatakit/tree/main/python)) | PyPI | `pip install pakdatakit` | [](https://pypi.org/project/pakdatakit/) |
|
|
50
|
+
| [`pakdatakit`](https://pub.dev/packages/pakdatakit) ([Dart](https://github.com/chmuzamil/pakdatakit/tree/main/dart)) | pub.dev | `dart pub add pakdatakit` | [](https://pub.dev/packages/pakdatakit) |
|
|
51
|
+
| [`pakdatakit_flutter`](https://pub.dev/packages/pakdatakit_flutter) ([Flutter](https://github.com/chmuzamil/pakdatakit/tree/main/flutter)) | pub.dev | `flutter pub add pakdatakit_flutter` | [](https://pub.dev/packages/pakdatakit_flutter) |
|
|
52
|
+
| [`PakDataKit`](https://www.nuget.org/packages/PakDataKit) ([.NET](https://github.com/chmuzamil/pakdatakit/tree/main/dotnet)) | NuGet | `dotnet add package PakDataKit` | [](https://www.nuget.org/packages/PakDataKit) |
|
|
53
|
+
| [`PakDataKit.DataAnnotations`](https://www.nuget.org/packages/PakDataKit.DataAnnotations) | NuGet | `dotnet add package PakDataKit.DataAnnotations` | [](https://www.nuget.org/packages/PakDataKit.DataAnnotations) |
|
|
54
|
+
| [`PakDataKit.FluentValidation`](https://www.nuget.org/packages/PakDataKit.FluentValidation) | NuGet | `dotnet add package PakDataKit.FluentValidation` | [](https://www.nuget.org/packages/PakDataKit.FluentValidation) |
|
|
55
|
+
| [`chmuzamil/pakdatakit`](https://packagist.org/packages/chmuzamil/pakdatakit) ([PHP/Laravel](https://github.com/chmuzamil/pakdatakit/tree/main/php)) | Packagist | `composer require chmuzamil/pakdatakit` | [](https://packagist.org/packages/chmuzamil/pakdatakit) |
|
|
56
|
+
| [`pakdatakit-react`](https://www.npmjs.com/package/pakdatakit-react) ([React](https://github.com/chmuzamil/pakdatakit/tree/main/react)) | npm | `npm install pakdatakit-react` | [](https://www.npmjs.com/package/pakdatakit-react) |
|
|
57
|
+
| [`pakdatakit-vue`](https://www.npmjs.com/package/pakdatakit-vue) ([Vue](https://github.com/chmuzamil/pakdatakit/tree/main/vue)) | npm | `npm install pakdatakit-vue` | [](https://www.npmjs.com/package/pakdatakit-vue) |
|
|
58
|
+
| [`pakdatakit-angular`](https://www.npmjs.com/package/pakdatakit-angular) ([Angular](https://github.com/chmuzamil/pakdatakit/tree/main/angular)) | npm | `npm install pakdatakit-angular` | [](https://www.npmjs.com/package/pakdatakit-angular) |
|
|
59
|
+
| [`pakdatakit-faker`](https://www.npmjs.com/package/pakdatakit-faker) ([mock data](https://github.com/chmuzamil/pakdatakit/tree/main/faker)) | npm | `npm install -D pakdatakit-faker` | [](https://www.npmjs.com/package/pakdatakit-faker) |
|
|
60
|
+
| [`pakdatakit-pay`](https://www.npmjs.com/package/pakdatakit-pay) ([JazzCash hash](https://github.com/chmuzamil/pakdatakit/tree/main/pay)) | npm | `npm install pakdatakit-pay` | [](https://www.npmjs.com/package/pakdatakit-pay) |
|
|
61
61
|
|
|
62
62
|
---
|
|
63
63
|
|
|
@@ -240,6 +240,22 @@ getCNICInfo('invalid');
|
|
|
240
240
|
|
|
241
241
|
The first digit is the province where the CNIC was first registered, which is not necessarily where the holder lives now. The last digit is odd for male and even for female.
|
|
242
242
|
|
|
243
|
+
### findCNICs() / maskCNICs()
|
|
244
|
+
|
|
245
|
+
Finds or masks CNICs in free text, such as a chat message or a note, for example before logging it.
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
findCNICs('CNIC: 35202-1234567-1, phone 0300-1234567');
|
|
249
|
+
// [{ raw: '35202-1234567-1', digits: '3520212345671',
|
|
250
|
+
// formatted: '35202-1234567-1', start: 6, end: 21 }]
|
|
251
|
+
|
|
252
|
+
maskCNICs('My CNIC is 35202 1234567-1');
|
|
253
|
+
// { text: 'My CNIC is XXXXX XXXXXXX-X', count: 1 }
|
|
254
|
+
maskCNICs(text, { mask: '*' });
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
A match is 13 digits starting with a province code (1-8), together or in 5-7-1 groups with any hyphen, dash, dot or space between the groups (the two may differ), in ASCII, Urdu or Arabic-Indic digits, and never next to another digit. It is a pattern match: other 13-digit numbers starting with 1-8 also match. `validateCNIC` stays strict. Offsets are UTF-16 code units in TypeScript, Dart and C#, and code points in Python and PHP.
|
|
258
|
+
|
|
243
259
|
---
|
|
244
260
|
|
|
245
261
|
## Phone Utilities
|
|
@@ -503,7 +519,7 @@ getNetwork('03451234567');
|
|
|
503
519
|
|
|
504
520
|
### analyzeNumber() / getNumberType() / validateLandline() / getAreaCode()
|
|
505
521
|
|
|
506
|
-
Identifies any Pakistani number: mobile, landline, UAN (`111`), toll-free (`0800`)
|
|
522
|
+
Identifies any Pakistani number: mobile, landline, UAN (`111`), toll-free (`0800`) or premium-rate (`0900`). `0122` numbers are not recognised: they are seen in use but no PTA document lists them. Service numbers follow PTA's numbering plan: a UAN is an area code, `111` and six digits (`111-123-456` without the area code also works); toll-free is `0800` and five digits; premium is `0900` and five digits. Landline patterns come from Google's libphonenumber, with area codes from PTA's plan.
|
|
507
523
|
|
|
508
524
|
```ts
|
|
509
525
|
analyzeNumber('021-111-825-888');
|
|
@@ -514,6 +530,8 @@ analyzeNumber('042 35761234');
|
|
|
514
530
|
|
|
515
531
|
getNumberType('0800-12345'); // 'toll-free'
|
|
516
532
|
validateLandline('051-9260138'); // true
|
|
533
|
+
validateLandline('021-111-123-456'); // false: a UAN
|
|
534
|
+
validateLandline('021-111-123-456', { services: true }); // true: UAN, toll-free or premium
|
|
517
535
|
getAreaCode('Mardan'); // '0937'
|
|
518
536
|
```
|
|
519
537
|
|
|
@@ -690,6 +708,18 @@ Flags: `invalid`, `landline`, `not-mobile` (UAN, toll-free and other service num
|
|
|
690
708
|
|
|
691
709
|
Normalizes informal Roman Urdu spellings (`ap kia ker` → `aap kya kar`).
|
|
692
710
|
|
|
711
|
+
### romanUrduKey()
|
|
712
|
+
|
|
713
|
+
A phonetic key so that different Roman Urdu spellings of a name match. Compare keys, not text.
|
|
714
|
+
|
|
715
|
+
```ts
|
|
716
|
+
romanUrduKey('Mubeen') === romanUrduKey('Mobeen'); // true
|
|
717
|
+
romanUrduKey('Muhammad Rehman'); // 'muhmd rahmn', the same as 'Mohammad Rahman'
|
|
718
|
+
romanUrduKey('Hussain') === romanUrduKey('Hassan'); // false
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
On 277 spellings of 118 common Pakistani names, 96.8% of same-name pairs share a key and 0.021% of different-name pairs do. Treat a match as "probably the same", not proof.
|
|
722
|
+
|
|
693
723
|
### toUrduDigits() / toEnglishDigits()
|
|
694
724
|
|
|
695
725
|
Convert between English, Urdu, and Arabic-Indic digits.
|
|
@@ -736,15 +766,19 @@ Income tax on a salaried individual's taxable income, from the salaried rate tab
|
|
|
736
766
|
|
|
737
767
|
```ts
|
|
738
768
|
calculateSalaryTax(1_800_000, { taxYear: 2026 });
|
|
739
|
-
// { tax: 72000, monthly: 6000, effectiveRate: 4,
|
|
769
|
+
// { tax: 72000, surcharge: 0, total: 72000, monthly: 6000, effectiveRate: 4,
|
|
740
770
|
// slab: { over: 1200000, upTo: 2200000, fixed: 6000, rate: 11 }, taxYear: 2026 }
|
|
741
771
|
|
|
772
|
+
// With the section 4AB surcharge (above Rs 10 million):
|
|
773
|
+
calculateSalaryTax(12_000_000, { taxYear: 2026, includeSurcharge: true });
|
|
774
|
+
// { tax: 3381000, surcharge: 304290, total: 3685290, monthly: 307107.5, … }
|
|
775
|
+
|
|
742
776
|
calculateMonthlySalaryTax(150_000, { taxYear: 2026 })?.monthly; // 6000
|
|
743
777
|
getSalaryTaxSlabs(2027); // the table, its law and FBR source
|
|
744
778
|
getTaxYear('2025-07-01'); // 2026
|
|
745
779
|
```
|
|
746
780
|
|
|
747
|
-
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.
|
|
781
|
+
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. With `includeSurcharge: true` the section 4AB surcharge is added: a percentage of the whole tax once taxable income exceeds Rs 10 million (10% in tax year 2025, 9% for salaried individuals in 2026, none in 2027 or before 2025). It is off by default in 2.x so that existing results don't change, and will be on by default in 3.0. Tax credits, exemptions, the separate rate for pensions, super tax and withholding adjustments are not applied. Sources and the full table are in [DATA.md](DATA.md#income-tax-on-salary-income-tax-slabsjson).
|
|
748
782
|
|
|
749
783
|
---
|
|
750
784
|
|
|
@@ -810,6 +844,35 @@ formatLakh(50000);
|
|
|
810
844
|
// "Rs. 50,000"
|
|
811
845
|
```
|
|
812
846
|
|
|
847
|
+
### parseAmount() / formatAmountInput()
|
|
848
|
+
|
|
849
|
+
Reads a rupee amount the way people type it in Pakistan, rounded half-up to
|
|
850
|
+
the paisa. Returns `null` for anything that is not exactly one non-negative
|
|
851
|
+
amount; it never throws.
|
|
852
|
+
|
|
853
|
+
```ts
|
|
854
|
+
parseAmount(input: string): { value: number; raw: string } | null
|
|
855
|
+
formatAmountInput(input: string): string | null
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
```ts
|
|
859
|
+
parseAmount('Rs. 1,50,000/-'); // { value: 150000, raw: 'Rs. 1,50,000/-' }
|
|
860
|
+
parseAmount('2.25cr'); // { value: 22500000, raw: '2.25cr' }
|
|
861
|
+
parseAmount('۱٫۵ لاکھ'); // { value: 150000, ... }
|
|
862
|
+
parseAmount('1.005'); // { value: 1.01, ... }: exact, on the digits
|
|
863
|
+
parseAmount('5-10k'); // null: a range
|
|
864
|
+
formatAmountInput('1.5 lakh'); // "Rs. 150,000"
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
Accepted: `150,000` and `1,50,000` grouping with decimals; Urdu and
|
|
868
|
+
Arabic-Indic digits; `Rs`, `Rs.`, `PKR` or `₨` before or after the number and
|
|
869
|
+
a trailing `/-`; `k`, `thousand(s)`, `hazar`, `ہزار`, `lakh(s)`, `lac(s)`,
|
|
870
|
+
`لاکھ`, `crore(s)`, `cr` and `کروڑ`, also with decimals (`1.5 lakh`);
|
|
871
|
+
whitespace around and between the parts. Rejected: negatives, ranges, more
|
|
872
|
+
than one number, leftover letters, broken or ambiguous grouping (`1,50`,
|
|
873
|
+
`1.500,00`) and amounts over Rs. 50 trillion. Every form is listed on
|
|
874
|
+
[pakdatakit.dev/docs/amount](https://pakdatakit.dev/docs/amount/).
|
|
875
|
+
|
|
813
876
|
---
|
|
814
877
|
|
|
815
878
|
## Amounts in Words
|
|
@@ -1126,18 +1189,18 @@ Checks a scanned QR before anyone pays, for example to warn about a QR sticker t
|
|
|
1126
1189
|
|
|
1127
1190
|
```ts
|
|
1128
1191
|
validateRaastQr(scannedText);
|
|
1129
|
-
// { valid: false, errors: ['expired'], warnings: [], qr: { iban: 'PK36…', amount: 1500, … } }
|
|
1192
|
+
// { valid: false, kind: 'p2p', errors: ['expired'], warnings: [], qr: { iban: 'PK36…', amount: 1500, … } }
|
|
1130
1193
|
```
|
|
1131
1194
|
|
|
1132
|
-
| Errors | Meaning
|
|
1133
|
-
| -------------------------- |
|
|
1134
|
-
| `not-a-raast-qr` | Not a Pakistani payment QR
|
|
1135
|
-
| `bad-checksum` | The QR was damaged or its contents were edited
|
|
1136
|
-
| `no-iban` / `invalid-iban` |
|
|
1137
|
-
| `expired` | A QR with an amount is past its expiry
|
|
1138
|
-
| `missing-expiry` | A QR with an amount has no expiry, so banking apps reject it
|
|
1195
|
+
| Errors | Meaning |
|
|
1196
|
+
| -------------------------- | ---------------------------------------------------------------------- |
|
|
1197
|
+
| `not-a-raast-qr` | Not a Pakistani payment QR |
|
|
1198
|
+
| `bad-checksum` | The QR was damaged or its contents were edited |
|
|
1199
|
+
| `no-iban` / `invalid-iban` | A person-to-person QR with no IBAN, or an IBAN that fails its checksum |
|
|
1200
|
+
| `expired` | A QR with an amount is past its expiry |
|
|
1201
|
+
| `missing-expiry` | A QR with an amount has no expiry, so banking apps reject it |
|
|
1139
1202
|
|
|
1140
|
-
Warnings (payment still works): `amount-ignored` when a static QR carries an amount that apps ignore,
|
|
1203
|
+
Warnings (payment still works): `amount-ignored` when a static QR carries an amount that apps ignore, `expires-soon` when it expires within an hour (`expiresSoonMs` changes this), and `no-iban` for a merchant QR without an IBAN, which pays through the merchant's own scheme. `kind` is `'p2p'`, `'merchant'` or `null`. Pass `now` to check against another time.
|
|
1141
1204
|
|
|
1142
1205
|
---
|
|
1143
1206
|
|
|
@@ -1209,7 +1272,7 @@ import { pk } from 'pakdatakit/superstruct';
|
|
|
1209
1272
|
const CheckoutForm = object({ cnic: pk.cnic(), phone: optional(pk.phone()) });
|
|
1210
1273
|
```
|
|
1211
1274
|
|
|
1212
|
-
Available schemas: `pk.cnic()`, `pk.phone()`, `pk.iban()`, `pk.ntn()`, `pk.strn()`, `pk.landline()`, `pk.passport()`, `pk.vehiclePlate()
|
|
1275
|
+
Available schemas: `pk.cnic()`, `pk.phone()`, `pk.iban()`, `pk.ntn()`, `pk.strn()`, `pk.landline()`, `pk.passport()`, `pk.vehiclePlate()`, `pk.codPhone()` (a mobile number with no `phoneRiskSignals` flags), `pk.landline({ services: true })` (also UAN, toll-free and premium numbers) and `pk.amount()` (an amount `parseAmount()` reads, such as `1.5 lakh`; convert it with `parseAmount` on submit). Every factory accepts `{ message }` to replace the default error. The Yup schemas let empty values pass so `.required()` decides whether a field is mandatory.
|
|
1213
1276
|
|
|
1214
1277
|
### class-validator and NestJS
|
|
1215
1278
|
|
|
@@ -1232,7 +1295,7 @@ export class CreateCustomerDto {
|
|
|
1232
1295
|
}
|
|
1233
1296
|
```
|
|
1234
1297
|
|
|
1235
|
-
Decorators: `IsCNIC`, `IsPakPhone`, `IsPakIBAN` (named so it doesn't clash with class-validator's own `IsIBAN`), `IsNTN`, `IsSTRN`, `IsPakLandline
|
|
1298
|
+
Decorators: `IsCNIC`, `IsPakPhone`, `IsPakIBAN` (named so it doesn't clash with class-validator's own `IsIBAN`), `IsNTN`, `IsSTRN`, `IsPakLandline` (with `{ services: true }` for UAN, toll-free and premium numbers), `IsPakPassport`, `IsVehiclePlate`, `IsCodPhone` and `IsPakAmount`, 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.
|
|
1236
1299
|
|
|
1237
1300
|
### As-you-type helpers
|
|
1238
1301
|
|
|
@@ -469,9 +469,8 @@ var area_codes_default = [
|
|
|
469
469
|
var FIXED_LINE = /^(?:(?:(?:21|42)[2-9]|58[126])\d{7}|(?:2[25]|4[0146-9]|5[1-35-7]|6[1-8]|7[14]|8[16]|91)[2-9]\d{6,7}|(?:2(?:3[2358]|4[2-4]|9[2-8])|45[3479]|54[2-467]|60[468]|72[236]|8(?:2[2-689]|3[23578]|4[3478]|5[2356])|9(?:2[2-8]|3[27-9]|4[2-6]|6[3569]|9[25-8]))[2-9]\d{5,6})$/;
|
|
470
470
|
var UAN = /^((?:2(?:[125]|3[2358]|4[2-4]|9[2-8])|4(?:[0-246-9]|5[3479])|5(?:[1-35-7]|4[2-467])|6(?:0[468]|[1-8])|7(?:[14]|2[236])|8(?:[16]|2[2-689]|3[23578]|4[3478]|5[2356])|9(?:1|22|3[27-9]|4[2-6]|6[3569]|9[2-7])))111(\d{6})$/;
|
|
471
471
|
var UAN_WITHOUT_AREA_CODE = /^111(\d{6})$/;
|
|
472
|
-
var TOLL_FREE = /^800(\d{5}
|
|
472
|
+
var TOLL_FREE = /^800(\d{5})$/;
|
|
473
473
|
var PREMIUM = /^900(\d{5})$/;
|
|
474
|
-
var PERSONAL = /^122(\d{6})$/;
|
|
475
474
|
var areaCodes = /* @__PURE__ */ lazy(() => area_codes_default);
|
|
476
475
|
var areaCodeMap = /* @__PURE__ */ lazy(
|
|
477
476
|
() => new Map(areaCodes().map((entry) => [entry.code, entry.cities]))
|
|
@@ -543,8 +542,6 @@ function analyzeNumber(phone) {
|
|
|
543
542
|
if (tollFree) return service("toll-free", "800", tollFree[1]);
|
|
544
543
|
const premium = PREMIUM.exec(national);
|
|
545
544
|
if (premium) return service("premium", "900", premium[1]);
|
|
546
|
-
const personal = PERSONAL.exec(national);
|
|
547
|
-
if (personal) return service("personal", "122", personal[1]);
|
|
548
545
|
const uan = UAN.exec(national);
|
|
549
546
|
if (uan) {
|
|
550
547
|
const code = uan[1];
|
|
@@ -571,8 +568,16 @@ function analyzeNumber(phone) {
|
|
|
571
568
|
function getNumberType(phone) {
|
|
572
569
|
return analyzeNumber(phone)?.type ?? null;
|
|
573
570
|
}
|
|
574
|
-
|
|
575
|
-
|
|
571
|
+
var SERVICE_TYPES = /* @__PURE__ */ new Set([
|
|
572
|
+
"uan",
|
|
573
|
+
"toll-free",
|
|
574
|
+
"premium"
|
|
575
|
+
]);
|
|
576
|
+
function validateLandline(phone, options = {}) {
|
|
577
|
+
if (typeof phone !== "string") return false;
|
|
578
|
+
const type = getNumberType(phone);
|
|
579
|
+
if (type === "landline") return true;
|
|
580
|
+
return options.services === true && type !== null && SERVICE_TYPES.has(type);
|
|
576
581
|
}
|
|
577
582
|
function getAreaCode(city) {
|
|
578
583
|
const key = normalizeKey(city);
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkESKXG7Y6_cjs = require('./chunk-ESKXG7Y6.cjs');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var chunk4YLSPXBZ_cjs = require('./chunk-4YLSPXBZ.cjs');
|
|
5
|
+
var chunkVZIBHQC7_cjs = require('./chunk-VZIBHQC7.cjs');
|
|
6
6
|
var chunkSQIHFEXI_cjs = require('./chunk-SQIHFEXI.cjs');
|
|
7
7
|
var chunkDHOP7LQX_cjs = require('./chunk-DHOP7LQX.cjs');
|
|
8
|
-
var
|
|
8
|
+
var chunkVSIVT5RT_cjs = require('./chunk-VSIVT5RT.cjs');
|
|
9
9
|
var chunk7E7L3NYS_cjs = require('./chunk-7E7L3NYS.cjs');
|
|
10
|
-
var
|
|
10
|
+
var chunk7NTUEHQV_cjs = require('./chunk-7NTUEHQV.cjs');
|
|
11
|
+
var chunkNLSIAPZG_cjs = require('./chunk-NLSIAPZG.cjs');
|
|
11
12
|
|
|
12
13
|
// src/adapters/rules.ts
|
|
13
14
|
var RULES = {
|
|
14
|
-
cnic: { test:
|
|
15
|
+
cnic: { test: chunk7NTUEHQV_cjs.validateCNIC, message: "Invalid CNIC number" },
|
|
15
16
|
phone: { test: chunkESKXG7Y6_cjs.validatePhone, message: "Invalid Pakistani mobile number" },
|
|
16
17
|
iban: { test: chunkDHOP7LQX_cjs.validateIBAN, message: "Invalid Pakistani IBAN" },
|
|
17
|
-
ntn: { test:
|
|
18
|
-
strn: { test:
|
|
18
|
+
ntn: { test: chunkVZIBHQC7_cjs.validateNTN, message: "Invalid NTN" },
|
|
19
|
+
strn: { test: chunkVZIBHQC7_cjs.validateSTRN, message: "Invalid STRN" },
|
|
19
20
|
landline: {
|
|
20
|
-
test:
|
|
21
|
+
test: (value, options) => chunkVSIVT5RT_cjs.validateLandline(value, { services: options.services === true }),
|
|
21
22
|
message: "Invalid Pakistani landline number"
|
|
22
23
|
},
|
|
23
24
|
passport: {
|
|
@@ -29,8 +30,12 @@ var RULES = {
|
|
|
29
30
|
message: "Invalid vehicle registration number"
|
|
30
31
|
},
|
|
31
32
|
codPhone: {
|
|
32
|
-
test: (value) =>
|
|
33
|
+
test: (value) => chunk4YLSPXBZ_cjs.phoneRiskSignals(value).length === 0,
|
|
33
34
|
message: "Enter a mobile number a courier can call"
|
|
35
|
+
},
|
|
36
|
+
amount: {
|
|
37
|
+
test: (value) => chunkNLSIAPZG_cjs.parseAmount(value) !== null,
|
|
38
|
+
message: "Enter an amount in rupees, like 150,000 or 1.5 lakh"
|
|
34
39
|
}
|
|
35
40
|
};
|
|
36
41
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVSIVT5RT_cjs = require('./chunk-VSIVT5RT.cjs');
|
|
4
4
|
var chunkQFPEFD67_cjs = require('./chunk-QFPEFD67.cjs');
|
|
5
5
|
var chunkI7UUPD3G_cjs = require('./chunk-I7UUPD3G.cjs');
|
|
6
6
|
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
@@ -150,7 +150,7 @@ function scoreAddress(input) {
|
|
|
150
150
|
var ASCENDING = "01234567890";
|
|
151
151
|
var DESCENDING = "09876543210";
|
|
152
152
|
function phoneRiskSignals(input) {
|
|
153
|
-
const info = typeof input === "string" ?
|
|
153
|
+
const info = typeof input === "string" ? chunkVSIVT5RT_cjs.analyzeNumber(input) : null;
|
|
154
154
|
if (info === null) return ["invalid"];
|
|
155
155
|
if (info.type === "landline") return ["landline"];
|
|
156
156
|
if (info.type !== "mobile" || info.e164 === null) return ["not-mobile"];
|
|
@@ -302,14 +302,22 @@ function localDateTime(value) {
|
|
|
302
302
|
function validateRaastQr(payload, options = {}) {
|
|
303
303
|
const qr = parseRaastQr(payload);
|
|
304
304
|
if (qr === null) {
|
|
305
|
-
return {
|
|
305
|
+
return {
|
|
306
|
+
valid: false,
|
|
307
|
+
kind: null,
|
|
308
|
+
errors: ["not-a-raast-qr"],
|
|
309
|
+
warnings: [],
|
|
310
|
+
qr: null
|
|
311
|
+
};
|
|
306
312
|
}
|
|
307
313
|
const errors = [];
|
|
308
314
|
const warnings = [];
|
|
309
315
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
310
316
|
if (!qr.crcValid) errors.push("bad-checksum");
|
|
311
|
-
if (qr.iban === null)
|
|
312
|
-
|
|
317
|
+
if (qr.iban === null) {
|
|
318
|
+
if (qr.kind === "merchant") warnings.push("no-iban");
|
|
319
|
+
else errors.push("no-iban");
|
|
320
|
+
} else if (!qr.ibanValid) errors.push("invalid-iban");
|
|
313
321
|
if (qr.kind === "p2p") {
|
|
314
322
|
if (qr.dynamic && qr.expiresAt === null) errors.push("missing-expiry");
|
|
315
323
|
if (!qr.dynamic && qr.amount !== null) warnings.push("amount-ignored");
|
|
@@ -322,7 +330,7 @@ function validateRaastQr(payload, options = {}) {
|
|
|
322
330
|
}
|
|
323
331
|
}
|
|
324
332
|
}
|
|
325
|
-
return { valid: errors.length === 0, errors, warnings, qr };
|
|
333
|
+
return { valid: errors.length === 0, kind: qr.kind, errors, warnings, qr };
|
|
326
334
|
}
|
|
327
335
|
|
|
328
336
|
exports.createMerchantQr = createMerchantQr;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
4
|
+
|
|
5
|
+
// src/cnic.ts
|
|
6
|
+
var CNIC_PATTERN = /^[1-8]\d{4}([-‐‑‒–—. ]?)\d{7}\1\d$/;
|
|
7
|
+
function validateCNIC(cnic) {
|
|
8
|
+
return CNIC_PATTERN.test(chunkVPBMIYO2_cjs.toAsciiDigits(cnic.trim()));
|
|
9
|
+
}
|
|
10
|
+
var CNIC_PROVINCES = {
|
|
11
|
+
"1": "Khyber Pakhtunkhwa",
|
|
12
|
+
"2": "Khyber Pakhtunkhwa",
|
|
13
|
+
"3": "Punjab",
|
|
14
|
+
"4": "Sindh",
|
|
15
|
+
"5": "Balochistan",
|
|
16
|
+
"6": "Islamabad Capital Territory",
|
|
17
|
+
"7": "Gilgit-Baltistan",
|
|
18
|
+
"8": "Azad Jammu and Kashmir"
|
|
19
|
+
};
|
|
20
|
+
function getCNICInfo(cnic) {
|
|
21
|
+
if (!validateCNIC(cnic)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const digits = chunkVPBMIYO2_cjs.toAsciiDigits(cnic).replace(/\D/g, "");
|
|
25
|
+
const lastDigit = Number(digits[12]);
|
|
26
|
+
return {
|
|
27
|
+
digits,
|
|
28
|
+
formatted: `${digits.slice(0, 5)}-${digits.slice(5, 12)}-${digits[12]}`,
|
|
29
|
+
province: CNIC_PROVINCES[digits[0]],
|
|
30
|
+
gender: lastDigit % 2 === 1 ? "male" : "female"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
var ANY_DIGIT = /[0-9\u06F0-\u06F9\u0660-\u0669]/.source;
|
|
34
|
+
var CNIC_SEPARATOR = /[-\u2010\u2011\u2012\u2013\u2014. ]/.source;
|
|
35
|
+
var CNIC_IN_TEXT = new RegExp(
|
|
36
|
+
`(?<!${ANY_DIGIT})` + /[1-8\u06F1-\u06F8\u0661-\u0668]/.source + `${ANY_DIGIT}{4}${CNIC_SEPARATOR}?${ANY_DIGIT}{7}${CNIC_SEPARATOR}?${ANY_DIGIT}(?!${ANY_DIGIT})`,
|
|
37
|
+
"g"
|
|
38
|
+
);
|
|
39
|
+
function findCNICs(text) {
|
|
40
|
+
if (typeof text !== "string") return [];
|
|
41
|
+
return [...text.matchAll(CNIC_IN_TEXT)].map((match) => {
|
|
42
|
+
const raw = match[0];
|
|
43
|
+
const digits = chunkVPBMIYO2_cjs.toAsciiDigits(raw).replace(/\D/g, "");
|
|
44
|
+
const start = match.index;
|
|
45
|
+
return {
|
|
46
|
+
raw,
|
|
47
|
+
digits,
|
|
48
|
+
formatted: `${digits.slice(0, 5)}-${digits.slice(5, 12)}-${digits[12]}`,
|
|
49
|
+
start,
|
|
50
|
+
end: start + raw.length
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function maskCNICs(text, options = {}) {
|
|
55
|
+
if (typeof text !== "string") return { text: "", count: 0 };
|
|
56
|
+
const mask = typeof options.mask === "string" ? options.mask : "X";
|
|
57
|
+
const digit = new RegExp(ANY_DIGIT, "g");
|
|
58
|
+
let count = 0;
|
|
59
|
+
const masked = text.replace(CNIC_IN_TEXT, (raw) => {
|
|
60
|
+
count += 1;
|
|
61
|
+
return raw.replace(digit, () => mask);
|
|
62
|
+
});
|
|
63
|
+
return { text: masked, count };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.findCNICs = findCNICs;
|
|
67
|
+
exports.getCNICInfo = getCNICInfo;
|
|
68
|
+
exports.maskCNICs = maskCNICs;
|
|
69
|
+
exports.validateCNIC = validateCNIC;
|
|
@@ -300,14 +300,22 @@ function localDateTime(value) {
|
|
|
300
300
|
function validateRaastQr(payload, options = {}) {
|
|
301
301
|
const qr = parseRaastQr(payload);
|
|
302
302
|
if (qr === null) {
|
|
303
|
-
return {
|
|
303
|
+
return {
|
|
304
|
+
valid: false,
|
|
305
|
+
kind: null,
|
|
306
|
+
errors: ["not-a-raast-qr"],
|
|
307
|
+
warnings: [],
|
|
308
|
+
qr: null
|
|
309
|
+
};
|
|
304
310
|
}
|
|
305
311
|
const errors = [];
|
|
306
312
|
const warnings = [];
|
|
307
313
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
308
314
|
if (!qr.crcValid) errors.push("bad-checksum");
|
|
309
|
-
if (qr.iban === null)
|
|
310
|
-
|
|
315
|
+
if (qr.iban === null) {
|
|
316
|
+
if (qr.kind === "merchant") warnings.push("no-iban");
|
|
317
|
+
else errors.push("no-iban");
|
|
318
|
+
} else if (!qr.ibanValid) errors.push("invalid-iban");
|
|
311
319
|
if (qr.kind === "p2p") {
|
|
312
320
|
if (qr.dynamic && qr.expiresAt === null) errors.push("missing-expiry");
|
|
313
321
|
if (!qr.dynamic && qr.amount !== null) warnings.push("amount-ignored");
|
|
@@ -320,7 +328,7 @@ function validateRaastQr(payload, options = {}) {
|
|
|
320
328
|
}
|
|
321
329
|
}
|
|
322
330
|
}
|
|
323
|
-
return { valid: errors.length === 0, errors, warnings, qr };
|
|
331
|
+
return { valid: errors.length === 0, kind: qr.kind, errors, warnings, qr };
|
|
324
332
|
}
|
|
325
333
|
|
|
326
334
|
export { createMerchantQr, createRaastP2PQr, parseRaastQr, validateRaastQr };
|