pakdatakit 2.1.2 → 2.2.1
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 +105 -0
- package/README.md +94 -9
- package/dist/address.cjs +4 -4
- package/dist/address.d.cts +2 -1
- package/dist/address.d.ts +2 -1
- package/dist/address.js +2 -2
- package/dist/{chunk-PHHKIMO2.cjs → chunk-33FXHM2E.cjs} +5 -5
- package/dist/{chunk-3COX5FSL.cjs → chunk-34CJGJ67.cjs} +53 -6
- package/dist/chunk-3IARSCO6.cjs +317 -0
- package/dist/{chunk-BSS4Z7NI.cjs → chunk-3ZA265SK.cjs} +2 -2
- package/dist/{chunk-AUATLZA5.cjs → chunk-47P7HILD.cjs} +4 -4
- package/dist/{chunk-Q7XHVR3U.cjs → chunk-4VSGCQ6K.cjs} +86 -15
- package/dist/{chunk-Y6BUGLXU.js → chunk-6IPPANNX.js} +4 -1
- package/dist/{chunk-L45UXUWX.js → chunk-AZV45DMG.js} +1 -1
- package/dist/{chunk-QQQKISXT.js → chunk-BR4QLZPX.js} +11 -2
- package/dist/{chunk-K6CZFCX6.js → chunk-E6DT2DWQ.js} +53 -6
- package/dist/{chunk-P4CGOJEM.js → chunk-EMH4IP2U.js} +1 -1
- package/dist/{chunk-JNP27XW2.cjs → chunk-GJENL6VK.cjs} +6 -6
- package/dist/{chunk-APXP7OK7.cjs → chunk-HIZQBWNW.cjs} +11 -2
- package/dist/{chunk-YS7MOLK2.cjs → chunk-HTERSQGF.cjs} +3 -3
- package/dist/{chunk-E7GAK72W.js → chunk-HUQY2WR5.js} +3 -3
- package/dist/{chunk-KQKW2ZEK.cjs → chunk-NAJGGUAM.cjs} +2 -2
- package/dist/{chunk-YLWZGSFY.cjs → chunk-NTD4JLDW.cjs} +4 -0
- package/dist/{chunk-R7UTY3SY.js → chunk-NZQ47NWD.js} +84 -14
- package/dist/{chunk-432ZYMYV.js → chunk-PLDVGOKZ.js} +2 -2
- package/dist/{chunk-L2BDDM2W.js → chunk-QKH7W2CC.js} +1 -1
- package/dist/{chunk-T3E4B5MJ.js → chunk-RXNYY5K5.js} +1 -1
- package/dist/chunk-TTARJWGT.js +82 -0
- package/dist/chunk-U7MWHXMF.cjs +89 -0
- package/dist/chunk-YPPKY5XZ.js +312 -0
- package/dist/cli.js +1 -1
- package/dist/cnic.d.cts +2 -1
- package/dist/cnic.d.ts +2 -1
- package/dist/geo.cjs +6 -6
- package/dist/geo.js +1 -1
- package/dist/hijri.d.cts +2 -1
- package/dist/hijri.d.ts +2 -1
- package/dist/holidays.d.cts +4 -2
- package/dist/holidays.d.ts +4 -2
- package/dist/iban.cjs +11 -3
- package/dist/iban.d.cts +46 -1
- package/dist/iban.d.ts +46 -1
- package/dist/iban.js +1 -1
- package/dist/index.cjs +76 -37
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +16 -10
- package/dist/input.cjs +34 -0
- package/dist/input.d.cts +68 -0
- package/dist/input.d.ts +68 -0
- package/dist/input.js +5 -0
- package/dist/networks.cjs +3 -3
- package/dist/networks.d.cts +2 -1
- package/dist/networks.d.ts +2 -1
- package/dist/networks.js +2 -2
- package/dist/numbers.cjs +6 -6
- package/dist/numbers.d.cts +2 -1
- package/dist/numbers.d.ts +2 -1
- package/dist/numbers.js +2 -2
- package/dist/phone.cjs +8 -8
- package/dist/phone.d.cts +2 -1
- package/dist/phone.d.ts +2 -1
- package/dist/phone.js +3 -3
- package/dist/raast.cjs +9 -5
- package/dist/raast.d.cts +54 -8
- package/dist/raast.d.ts +54 -8
- package/dist/raast.js +2 -2
- package/dist/tax.d.cts +2 -1
- package/dist/tax.d.ts +2 -1
- package/dist/valibot.cjs +7 -7
- package/dist/valibot.js +6 -6
- package/dist/whatsapp.cjs +3 -3
- package/dist/whatsapp.js +2 -2
- package/dist/words.cjs +3 -3
- package/dist/words.d.cts +2 -1
- package/dist/words.d.ts +2 -1
- package/dist/words.js +1 -1
- package/dist/yup.cjs +7 -7
- package/dist/yup.js +6 -6
- package/dist/zod.cjs +7 -7
- package/dist/zod.js +6 -6
- package/package.json +24 -11
- package/dist/chunk-4EUKCSLW.js +0 -221
- package/dist/chunk-E47SNBWQ.cjs +0 -224
|
@@ -914,6 +914,10 @@ var districts_default = [
|
|
|
914
914
|
district: "Abbottabad",
|
|
915
915
|
province: "Khyber Pakhtunkhwa"
|
|
916
916
|
},
|
|
917
|
+
{
|
|
918
|
+
district: "Allai",
|
|
919
|
+
province: "Khyber Pakhtunkhwa"
|
|
920
|
+
},
|
|
917
921
|
{
|
|
918
922
|
district: "Astore",
|
|
919
923
|
province: "Gilgit-Baltistan"
|
|
@@ -950,10 +954,18 @@ var districts_default = [
|
|
|
950
954
|
district: "Bannu",
|
|
951
955
|
province: "Khyber Pakhtunkhwa"
|
|
952
956
|
},
|
|
957
|
+
{
|
|
958
|
+
district: "Bar Swat",
|
|
959
|
+
province: "Khyber Pakhtunkhwa"
|
|
960
|
+
},
|
|
953
961
|
{
|
|
954
962
|
district: "Barkhan",
|
|
955
963
|
province: "Balochistan"
|
|
956
964
|
},
|
|
965
|
+
{
|
|
966
|
+
district: "Barshore",
|
|
967
|
+
province: "Balochistan"
|
|
968
|
+
},
|
|
957
969
|
{
|
|
958
970
|
district: "Batagram",
|
|
959
971
|
province: "Khyber Pakhtunkhwa"
|
|
@@ -970,6 +982,10 @@ var districts_default = [
|
|
|
970
982
|
district: "Buner",
|
|
971
983
|
province: "Khyber Pakhtunkhwa"
|
|
972
984
|
},
|
|
985
|
+
{
|
|
986
|
+
district: "Central Dir",
|
|
987
|
+
province: "Khyber Pakhtunkhwa"
|
|
988
|
+
},
|
|
973
989
|
{
|
|
974
990
|
district: "Chagai",
|
|
975
991
|
province: "Balochistan"
|
|
@@ -998,10 +1014,6 @@ var districts_default = [
|
|
|
998
1014
|
district: "Darel",
|
|
999
1015
|
province: "Gilgit-Baltistan"
|
|
1000
1016
|
},
|
|
1001
|
-
{
|
|
1002
|
-
district: "Dera Bugti",
|
|
1003
|
-
province: "Balochistan"
|
|
1004
|
-
},
|
|
1005
1017
|
{
|
|
1006
1018
|
district: "Dera Ghazi Khan",
|
|
1007
1019
|
province: "Punjab"
|
|
@@ -1358,6 +1370,10 @@ var districts_default = [
|
|
|
1358
1370
|
district: "Neelam",
|
|
1359
1371
|
province: "Azad Jammu and Kashmir"
|
|
1360
1372
|
},
|
|
1373
|
+
{
|
|
1374
|
+
district: "North Dera Bugti",
|
|
1375
|
+
province: "Balochistan"
|
|
1376
|
+
},
|
|
1361
1377
|
{
|
|
1362
1378
|
district: "North Waziristan",
|
|
1363
1379
|
province: "Khyber Pakhtunkhwa"
|
|
@@ -1378,6 +1394,10 @@ var districts_default = [
|
|
|
1378
1394
|
district: "Orakzai",
|
|
1379
1395
|
province: "Khyber Pakhtunkhwa"
|
|
1380
1396
|
},
|
|
1397
|
+
{
|
|
1398
|
+
district: "Paharpur",
|
|
1399
|
+
province: "Khyber Pakhtunkhwa"
|
|
1400
|
+
},
|
|
1381
1401
|
{
|
|
1382
1402
|
district: "Pakpattan",
|
|
1383
1403
|
province: "Punjab"
|
|
@@ -1403,7 +1423,11 @@ var districts_default = [
|
|
|
1403
1423
|
province: "Sindh"
|
|
1404
1424
|
},
|
|
1405
1425
|
{
|
|
1406
|
-
district: "Quetta",
|
|
1426
|
+
district: "Quetta East",
|
|
1427
|
+
province: "Balochistan"
|
|
1428
|
+
},
|
|
1429
|
+
{
|
|
1430
|
+
district: "Quetta West",
|
|
1407
1431
|
province: "Balochistan"
|
|
1408
1432
|
},
|
|
1409
1433
|
{
|
|
@@ -1474,6 +1498,10 @@ var districts_default = [
|
|
|
1474
1498
|
district: "Sohbatpur",
|
|
1475
1499
|
province: "Balochistan"
|
|
1476
1500
|
},
|
|
1501
|
+
{
|
|
1502
|
+
district: "South Dera Bugti",
|
|
1503
|
+
province: "Balochistan"
|
|
1504
|
+
},
|
|
1477
1505
|
{
|
|
1478
1506
|
district: "Sudhnuti",
|
|
1479
1507
|
province: "Azad Jammu and Kashmir"
|
|
@@ -1538,6 +1566,10 @@ var districts_default = [
|
|
|
1538
1566
|
district: "Tor Ghar",
|
|
1539
1567
|
province: "Khyber Pakhtunkhwa"
|
|
1540
1568
|
},
|
|
1569
|
+
{
|
|
1570
|
+
district: "Tump",
|
|
1571
|
+
province: "Balochistan"
|
|
1572
|
+
},
|
|
1541
1573
|
{
|
|
1542
1574
|
district: "Umerkot",
|
|
1543
1575
|
province: "Sindh"
|
|
@@ -1566,6 +1598,10 @@ var districts_default = [
|
|
|
1566
1598
|
district: "Vehari",
|
|
1567
1599
|
province: "Punjab"
|
|
1568
1600
|
},
|
|
1601
|
+
{
|
|
1602
|
+
district: "Wadh",
|
|
1603
|
+
province: "Balochistan"
|
|
1604
|
+
},
|
|
1569
1605
|
{
|
|
1570
1606
|
district: "Washuk",
|
|
1571
1607
|
province: "Balochistan"
|
|
@@ -1619,8 +1655,19 @@ function getDistrictProvince(district) {
|
|
|
1619
1655
|
if (key.length === 0) {
|
|
1620
1656
|
return null;
|
|
1621
1657
|
}
|
|
1622
|
-
return districtLookup().get(key) ?? null;
|
|
1658
|
+
return districtLookup().get(key) ?? (Object.hasOwn(FORMER_DISTRICTS, key) ? FORMER_DISTRICTS[key] : null) ?? null;
|
|
1623
1659
|
}
|
|
1660
|
+
var FORMER_DISTRICTS = {
|
|
1661
|
+
// Split into Lower and Upper South Waziristan (2022).
|
|
1662
|
+
"south waziristan": "Khyber Pakhtunkhwa",
|
|
1663
|
+
// Split into Quetta East and Quetta West (2026).
|
|
1664
|
+
quetta: "Balochistan",
|
|
1665
|
+
// Became South Dera Bugti; Upper Dera Bugti became North Dera Bugti (2026).
|
|
1666
|
+
"dera bugti": "Balochistan",
|
|
1667
|
+
"upper dera bugti": "Balochistan",
|
|
1668
|
+
// Notified as Bar Swat (2026); reported as Upper Swat before that.
|
|
1669
|
+
"upper swat": "Khyber Pakhtunkhwa"
|
|
1670
|
+
};
|
|
1624
1671
|
function searchDistricts(query) {
|
|
1625
1672
|
const normalizedQuery = normalizeKey(query);
|
|
1626
1673
|
if (normalizedQuery.length === 0) {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk3ZA265SK_cjs = require('./chunk-3ZA265SK.cjs');
|
|
4
|
+
var chunk33FXHM2E_cjs = require('./chunk-33FXHM2E.cjs');
|
|
5
5
|
var chunkH6M6L26S_cjs = require('./chunk-H6M6L26S.cjs');
|
|
6
6
|
var chunkHTCSHHOR_cjs = require('./chunk-HTCSHHOR.cjs');
|
|
7
|
-
var
|
|
7
|
+
var chunk3IARSCO6_cjs = require('./chunk-3IARSCO6.cjs');
|
|
8
8
|
|
|
9
9
|
// src/adapters/rules.ts
|
|
10
10
|
var RULES = {
|
|
11
11
|
cnic: { test: chunkHTCSHHOR_cjs.validateCNIC, message: "Invalid CNIC number" },
|
|
12
|
-
phone: { test:
|
|
13
|
-
iban: { test:
|
|
12
|
+
phone: { test: chunk33FXHM2E_cjs.validatePhone, message: "Invalid Pakistani mobile number" },
|
|
13
|
+
iban: { test: chunk3IARSCO6_cjs.validateIBAN, message: "Invalid Pakistani IBAN" },
|
|
14
14
|
ntn: { test: chunkH6M6L26S_cjs.validateNTN, message: "Invalid NTN" },
|
|
15
15
|
strn: { test: chunkH6M6L26S_cjs.validateSTRN, message: "Invalid STRN" },
|
|
16
16
|
landline: {
|
|
17
|
-
test:
|
|
17
|
+
test: chunk3ZA265SK_cjs.validateLandline,
|
|
18
18
|
message: "Invalid Pakistani landline number"
|
|
19
19
|
}
|
|
20
20
|
};
|
|
@@ -145,6 +145,15 @@ var UR_0_TO_99 = [
|
|
|
145
145
|
"\u0627\u0679\u06BE\u0627\u0646\u0648\u06D2",
|
|
146
146
|
"\u0646\u0646\u0627\u0646\u0648\u06D2"
|
|
147
147
|
];
|
|
148
|
+
function resolveLanguage(language) {
|
|
149
|
+
const value = language ?? "en";
|
|
150
|
+
if (value !== "en" && value !== "ur") {
|
|
151
|
+
throw new RangeError(
|
|
152
|
+
`language must be 'en' or 'ur', received ${String(value)}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
148
157
|
function underHundred(n, language) {
|
|
149
158
|
if (language === "ur") {
|
|
150
159
|
return UR_0_TO_99[n];
|
|
@@ -170,7 +179,7 @@ function convert(n, language) {
|
|
|
170
179
|
return [underHundred(n, language)];
|
|
171
180
|
}
|
|
172
181
|
function numberToWords(n, options = {}) {
|
|
173
|
-
const language = options.language
|
|
182
|
+
const language = resolveLanguage(options.language);
|
|
174
183
|
if (!Number.isSafeInteger(n)) {
|
|
175
184
|
throw new RangeError(`Expected a safe integer, received ${String(n)}`);
|
|
176
185
|
}
|
|
@@ -190,7 +199,7 @@ function titleCase(text) {
|
|
|
190
199
|
);
|
|
191
200
|
}
|
|
192
201
|
function amountInWords(amount, options = {}) {
|
|
193
|
-
const language = options.language
|
|
202
|
+
const language = resolveLanguage(options.language);
|
|
194
203
|
if (!Number.isFinite(amount) || amount < 0) {
|
|
195
204
|
throw new RangeError(
|
|
196
205
|
`Amount must be a finite number of zero or more, received ${String(amount)}`
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkNTD4JLDW_cjs = require('./chunk-NTD4JLDW.cjs');
|
|
4
4
|
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
5
5
|
|
|
6
6
|
// src/networks.ts
|
|
7
7
|
var prefixMap = chunkVPBMIYO2_cjs.lazy(
|
|
8
8
|
() => new Map(
|
|
9
|
-
|
|
9
|
+
chunkNTD4JLDW_cjs.networks_default.map((entry) => [
|
|
10
10
|
entry.prefix,
|
|
11
11
|
entry.network
|
|
12
12
|
])
|
|
13
13
|
)
|
|
14
14
|
);
|
|
15
15
|
function getNetwork(phone) {
|
|
16
|
-
const prefix =
|
|
16
|
+
const prefix = chunkNTD4JLDW_cjs.getPhonePrefix(phone);
|
|
17
17
|
if (prefix === null) {
|
|
18
18
|
return "Unknown";
|
|
19
19
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { validateLandline } from './chunk-
|
|
2
|
-
import { validatePhone } from './chunk-
|
|
1
|
+
import { validateLandline } from './chunk-RXNYY5K5.js';
|
|
2
|
+
import { validatePhone } from './chunk-PLDVGOKZ.js';
|
|
3
3
|
import { validateSTRN, validateNTN } from './chunk-CEPNSHIC.js';
|
|
4
4
|
import { validateCNIC } from './chunk-EEVNLTB4.js';
|
|
5
|
-
import { validateIBAN } from './chunk-
|
|
5
|
+
import { validateIBAN } from './chunk-YPPKY5XZ.js';
|
|
6
6
|
|
|
7
7
|
// src/adapters/rules.ts
|
|
8
8
|
var RULES = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkNTD4JLDW_cjs = require('./chunk-NTD4JLDW.cjs');
|
|
4
4
|
|
|
5
5
|
// src/whatsapp.ts
|
|
6
6
|
function createWhatsAppLink(phone, message) {
|
|
7
|
-
const digits =
|
|
7
|
+
const digits = chunkNTD4JLDW_cjs.normalizePhoneDigits(phone);
|
|
8
8
|
if (digits === null) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
@@ -65,6 +65,9 @@ var allocatedPrefixes = chunkVPBMIYO2_cjs.lazy(
|
|
|
65
65
|
networks_default.map((entry) => entry.prefix)
|
|
66
66
|
)
|
|
67
67
|
);
|
|
68
|
+
function isAllocatedPrefix(prefix) {
|
|
69
|
+
return allocatedPrefixes().has(prefix);
|
|
70
|
+
}
|
|
68
71
|
function normalizePhoneDigits(phone) {
|
|
69
72
|
let digits = chunkVPBMIYO2_cjs.stripSeparators(chunkVPBMIYO2_cjs.toAsciiDigits(phone));
|
|
70
73
|
if (digits.startsWith("+")) {
|
|
@@ -95,5 +98,6 @@ function getPhonePrefix(phone) {
|
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
exports.getPhonePrefix = getPhonePrefix;
|
|
101
|
+
exports.isAllocatedPrefix = isAllocatedPrefix;
|
|
98
102
|
exports.networks_default = networks_default;
|
|
99
103
|
exports.normalizePhoneDigits = normalizePhoneDigits;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateIBAN } from './chunk-
|
|
1
|
+
import { validateIBAN } from './chunk-YPPKY5XZ.js';
|
|
2
2
|
import { stripSeparators } from './chunk-ENQ7O7VW.js';
|
|
3
3
|
|
|
4
4
|
// src/internal/emv.ts
|
|
@@ -55,12 +55,35 @@ function withCrc(payload) {
|
|
|
55
55
|
// src/raast.ts
|
|
56
56
|
var PK_IBAN_PATTERN = /^PK\d{2}[A-Z]{4}[A-Z0-9]{16}$/;
|
|
57
57
|
var DEFAULT_P2P_SCHEME = "00";
|
|
58
|
+
var DURATION_UNITS = { m: 6e4, h: 36e5, d: 864e5 };
|
|
59
|
+
function resolveExpiry(expiresAt, expiresIn, now) {
|
|
60
|
+
if (expiresAt !== void 0 && expiresIn !== void 0) {
|
|
61
|
+
throw new RangeError("Use either expiresAt or expiresIn, not both");
|
|
62
|
+
}
|
|
63
|
+
if (expiresIn === void 0) return expiresAt;
|
|
64
|
+
let ms;
|
|
65
|
+
if (typeof expiresIn === "number") {
|
|
66
|
+
ms = expiresIn;
|
|
67
|
+
} else {
|
|
68
|
+
const match = /^(\d+(?:\.\d+)?)([mhd])$/.exec(expiresIn);
|
|
69
|
+
if (!match) {
|
|
70
|
+
throw new RangeError(
|
|
71
|
+
`expiresIn must be milliseconds or like '30m', '12h' or '7d', received ${expiresIn}`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
ms = Number(match[1]) * DURATION_UNITS[match[2]];
|
|
75
|
+
}
|
|
76
|
+
if (!Number.isFinite(ms) || ms <= 0) {
|
|
77
|
+
throw new RangeError("expiresIn must be a positive duration");
|
|
78
|
+
}
|
|
79
|
+
return new Date(now.getTime() + ms);
|
|
80
|
+
}
|
|
58
81
|
function formatAmount(amount, maxLength, label) {
|
|
59
82
|
if (!Number.isFinite(amount) || amount <= 0) {
|
|
60
83
|
throw new RangeError(`${label} must be a positive number`);
|
|
61
84
|
}
|
|
62
85
|
const text = amount.toFixed(2);
|
|
63
|
-
if (text.length > maxLength) {
|
|
86
|
+
if (text.length > maxLength || !/^\d+\.\d{2}$/.test(text)) {
|
|
64
87
|
throw new RangeError(`${label} is too large for a Raast QR code`);
|
|
65
88
|
}
|
|
66
89
|
return text;
|
|
@@ -70,7 +93,7 @@ function formatP2PAmount(amount) {
|
|
|
70
93
|
throw new RangeError("amount must be a positive number");
|
|
71
94
|
}
|
|
72
95
|
const text = Number.isInteger(amount) ? String(amount) : amount.toFixed(2);
|
|
73
|
-
if (text.length > 10) {
|
|
96
|
+
if (text.length > 10 || !/^\d+(\.\d+)?$/.test(text)) {
|
|
74
97
|
throw new RangeError("amount is too large for a Raast QR code");
|
|
75
98
|
}
|
|
76
99
|
return text;
|
|
@@ -96,6 +119,11 @@ function normalizeIban(iban) {
|
|
|
96
119
|
return normalized;
|
|
97
120
|
}
|
|
98
121
|
function createRaastP2PQr(options) {
|
|
122
|
+
const expiresAt = resolveExpiry(
|
|
123
|
+
options.expiresAt,
|
|
124
|
+
options.expiresIn,
|
|
125
|
+
/* @__PURE__ */ new Date()
|
|
126
|
+
);
|
|
99
127
|
const iban = normalizeIban(options.iban);
|
|
100
128
|
let payload = encodeField("00", "02") + encodeField("01", options.amount === void 0 ? "11" : "12") + encodeField("02", options.scheme ?? DEFAULT_P2P_SCHEME);
|
|
101
129
|
if (options.bankName) {
|
|
@@ -112,10 +140,10 @@ function createRaastP2PQr(options) {
|
|
|
112
140
|
);
|
|
113
141
|
}
|
|
114
142
|
if (options.amount !== void 0) {
|
|
115
|
-
if (
|
|
116
|
-
throw new RangeError("A QR with an amount needs expiresAt");
|
|
143
|
+
if (expiresAt === void 0) {
|
|
144
|
+
throw new RangeError("A QR with an amount needs expiresAt or expiresIn");
|
|
117
145
|
}
|
|
118
|
-
payload += encodeField("07", formatExpiry(
|
|
146
|
+
payload += encodeField("07", formatExpiry(expiresAt));
|
|
119
147
|
}
|
|
120
148
|
const data = `${payload}1004`;
|
|
121
149
|
return `${data}${crc16(data)}`;
|
|
@@ -139,12 +167,12 @@ function createMerchantQr(options) {
|
|
|
139
167
|
);
|
|
140
168
|
}
|
|
141
169
|
const dynamic = options.dynamic ?? options.amount !== void 0;
|
|
142
|
-
const
|
|
170
|
+
for (const [id] of accountFields) {
|
|
143
171
|
if (!/^\d{2}$/.test(id)) {
|
|
144
172
|
throw new RangeError(`Invalid merchant account sub-field ID: ${id}`);
|
|
145
173
|
}
|
|
146
|
-
|
|
147
|
-
|
|
174
|
+
}
|
|
175
|
+
const account = accountFields.sort(([a], [b]) => Number(a) - Number(b)).map(([id, value]) => encodeField(id, value)).join("");
|
|
148
176
|
let payload = encodeField("00", "01") + encodeField("01", dynamic ? "12" : "11") + encodeField(tag, account) + encodeField("52", mcc) + encodeField("53", "586");
|
|
149
177
|
if (options.amount !== void 0) {
|
|
150
178
|
payload += encodeField("54", formatAmount(options.amount, 13, "amount"));
|
|
@@ -192,10 +220,21 @@ function createMerchantQr(options) {
|
|
|
192
220
|
function fieldValue(fields, id) {
|
|
193
221
|
return fields.find((field) => field.id === id)?.value ?? null;
|
|
194
222
|
}
|
|
223
|
+
function parseExpiry(value) {
|
|
224
|
+
const match = value ? /^(\d{2})(\d{2})(\d{4})(\d{2})(\d{2})$/.exec(value) : null;
|
|
225
|
+
if (!match) return null;
|
|
226
|
+
const [, dd, mm, yyyy, hh, min] = match;
|
|
227
|
+
const [day, month, year, hour, minute] = [dd, mm, yyyy, hh, min].map(
|
|
228
|
+
Number
|
|
229
|
+
);
|
|
230
|
+
const date = new Date(2e3, month - 1, day, hour, minute);
|
|
231
|
+
date.setFullYear(year);
|
|
232
|
+
const real = date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day && date.getHours() === hour && date.getMinutes() === minute;
|
|
233
|
+
return real ? `${yyyy}-${mm}-${dd}T${hh}:${min}` : null;
|
|
234
|
+
}
|
|
195
235
|
function toAmount(value) {
|
|
196
|
-
if (value === null) return null;
|
|
197
|
-
|
|
198
|
-
return Number.isFinite(amount) ? amount : null;
|
|
236
|
+
if (value === null || !/^\d+(\.\d+)?$/.test(value)) return null;
|
|
237
|
+
return Number(value);
|
|
199
238
|
}
|
|
200
239
|
function parseRaastQr(payload) {
|
|
201
240
|
const text = payload.trim();
|
|
@@ -240,7 +279,7 @@ function parseRaastQr(payload) {
|
|
|
240
279
|
iban,
|
|
241
280
|
ibanValid: iban !== null && validateIBAN(iban),
|
|
242
281
|
amount: toAmount(fieldValue(fields, kind === "p2p" ? "05" : "54")),
|
|
243
|
-
expiresAt:
|
|
282
|
+
expiresAt: parseExpiry(expiry),
|
|
244
283
|
bankName: kind === "p2p" ? fieldValue(fields, "03") : null,
|
|
245
284
|
particulars: kind === "p2p" ? fieldValue(fields, "06") : null,
|
|
246
285
|
merchantName: kind === "merchant" ? fieldValue(fields, "59") : null,
|
|
@@ -252,5 +291,36 @@ function parseRaastQr(payload) {
|
|
|
252
291
|
fields
|
|
253
292
|
};
|
|
254
293
|
}
|
|
294
|
+
function localDateTime(value) {
|
|
295
|
+
const [date, time] = value.split("T");
|
|
296
|
+
const [year, month, day] = date.split("-").map(Number);
|
|
297
|
+
const [hour, minute] = time.split(":").map(Number);
|
|
298
|
+
return new Date(year, month - 1, day, hour, minute);
|
|
299
|
+
}
|
|
300
|
+
function validateRaastQr(payload, options = {}) {
|
|
301
|
+
const qr = parseRaastQr(payload);
|
|
302
|
+
if (qr === null) {
|
|
303
|
+
return { valid: false, errors: ["not-a-raast-qr"], warnings: [], qr: null };
|
|
304
|
+
}
|
|
305
|
+
const errors = [];
|
|
306
|
+
const warnings = [];
|
|
307
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
308
|
+
if (!qr.crcValid) errors.push("bad-checksum");
|
|
309
|
+
if (qr.iban === null) errors.push("no-iban");
|
|
310
|
+
else if (!qr.ibanValid) errors.push("invalid-iban");
|
|
311
|
+
if (qr.kind === "p2p") {
|
|
312
|
+
if (qr.dynamic && qr.expiresAt === null) errors.push("missing-expiry");
|
|
313
|
+
if (!qr.dynamic && qr.amount !== null) warnings.push("amount-ignored");
|
|
314
|
+
if (qr.expiresAt !== null) {
|
|
315
|
+
const remaining = localDateTime(qr.expiresAt).getTime() - now.getTime();
|
|
316
|
+
if (remaining <= 0) {
|
|
317
|
+
errors.push("expired");
|
|
318
|
+
} else if (remaining <= (options.expiresSoonMs ?? 36e5)) {
|
|
319
|
+
warnings.push("expires-soon");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return { valid: errors.length === 0, errors, warnings, qr };
|
|
324
|
+
}
|
|
255
325
|
|
|
256
|
-
export { createMerchantQr, createRaastP2PQr, parseRaastQr };
|
|
326
|
+
export { createMerchantQr, createRaastP2PQr, parseRaastQr, validateRaastQr };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getNetwork } from './chunk-
|
|
2
|
-
import { normalizePhoneDigits } from './chunk-
|
|
1
|
+
import { getNetwork } from './chunk-AZV45DMG.js';
|
|
2
|
+
import { normalizePhoneDigits } from './chunk-6IPPANNX.js';
|
|
3
3
|
|
|
4
4
|
// src/phone.ts
|
|
5
5
|
function validatePhone(phone) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCityByPostalCode } from './chunk-LIYNKIKS.js';
|
|
2
|
-
import { cities_default, districts_default, getProvince, getDistrictProvince } from './chunk-
|
|
2
|
+
import { cities_default, districts_default, getProvince, getDistrictProvince } from './chunk-E6DT2DWQ.js';
|
|
3
3
|
import { lazy, normalizeWhitespace, normalizeKey } from './chunk-ENQ7O7VW.js';
|
|
4
4
|
|
|
5
5
|
// src/address.ts
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isAllocatedPrefix } from './chunk-6IPPANNX.js';
|
|
2
|
+
import { validateCNIC } from './chunk-EEVNLTB4.js';
|
|
3
|
+
import { validateIBAN } from './chunk-YPPKY5XZ.js';
|
|
4
|
+
import { toAsciiDigits } from './chunk-ENQ7O7VW.js';
|
|
5
|
+
|
|
6
|
+
// src/input.ts
|
|
7
|
+
var SEPARATORS = /[\s\-‐‑‒–—./()]/g;
|
|
8
|
+
function formatCNICInput(value) {
|
|
9
|
+
const digits = toAsciiDigits(value).replace(/\D/g, "").slice(0, 13);
|
|
10
|
+
if (digits.length <= 5) return digits;
|
|
11
|
+
if (digits.length <= 12) return `${digits.slice(0, 5)}-${digits.slice(5)}`;
|
|
12
|
+
return `${digits.slice(0, 5)}-${digits.slice(5, 12)}-${digits.slice(12)}`;
|
|
13
|
+
}
|
|
14
|
+
function checkCNICInput(value) {
|
|
15
|
+
const text = toAsciiDigits(value).replace(SEPARATORS, "");
|
|
16
|
+
if (text === "") return "empty";
|
|
17
|
+
if (!/^\d+$/.test(text) || text.length > 13) return "invalid";
|
|
18
|
+
if (!/^[1-8]/.test(text)) return "invalid";
|
|
19
|
+
if (text.length < 13) return "incomplete";
|
|
20
|
+
return validateCNIC(text) ? "valid" : "invalid";
|
|
21
|
+
}
|
|
22
|
+
function splitPhone(value) {
|
|
23
|
+
const text = toAsciiDigits(value).replace(SEPARATORS, "");
|
|
24
|
+
if (!/^\+?\d*$/.test(text)) return null;
|
|
25
|
+
for (const code of ["+92", "0092", "92"]) {
|
|
26
|
+
if (code.startsWith(text) && text.length < code.length) {
|
|
27
|
+
return text === "0" ? { national: "", international: false } : "incomplete";
|
|
28
|
+
}
|
|
29
|
+
if (text.startsWith(code)) {
|
|
30
|
+
const rest = text.slice(code.length);
|
|
31
|
+
return {
|
|
32
|
+
national: rest.startsWith("0") ? rest.slice(1) : rest,
|
|
33
|
+
international: true
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (text.startsWith("+")) return null;
|
|
38
|
+
return {
|
|
39
|
+
national: text.startsWith("0") ? text.slice(1) : text,
|
|
40
|
+
international: false
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function formatPhoneInput(value) {
|
|
44
|
+
const split = splitPhone(value);
|
|
45
|
+
if (split === null) return value;
|
|
46
|
+
if (split === "incomplete")
|
|
47
|
+
return toAsciiDigits(value).replace(SEPARATORS, "");
|
|
48
|
+
const digits = split.national.replace(/\D/g, "").slice(0, 10);
|
|
49
|
+
if (split.international) {
|
|
50
|
+
return digits.length <= 3 ? `+92 ${digits}`.trimEnd() : `+92 ${digits.slice(0, 3)} ${digits.slice(3)}`;
|
|
51
|
+
}
|
|
52
|
+
const local = `0${digits}`;
|
|
53
|
+
return local.length <= 4 ? local : `${local.slice(0, 4)}-${local.slice(4)}`;
|
|
54
|
+
}
|
|
55
|
+
function checkPhoneInput(value) {
|
|
56
|
+
if (toAsciiDigits(value).replace(SEPARATORS, "") === "") return "empty";
|
|
57
|
+
const split = splitPhone(value);
|
|
58
|
+
if (split === null) return "invalid";
|
|
59
|
+
if (split === "incomplete") return "incomplete";
|
|
60
|
+
const { national } = split;
|
|
61
|
+
if (national === "") return "incomplete";
|
|
62
|
+
if (!national.startsWith("3")) return "invalid";
|
|
63
|
+
if (national.length >= 3 && !isAllocatedPrefix(`0${national.slice(0, 3)}`)) {
|
|
64
|
+
return "invalid";
|
|
65
|
+
}
|
|
66
|
+
if (national.length < 10) return "incomplete";
|
|
67
|
+
return national.length === 10 ? "valid" : "invalid";
|
|
68
|
+
}
|
|
69
|
+
function formatIBANInput(value) {
|
|
70
|
+
const clean = value.toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 24);
|
|
71
|
+
return clean.replace(/(.{4})(?=.)/g, "$1 ");
|
|
72
|
+
}
|
|
73
|
+
var IBAN_SHAPE = /^(P(K(\d(\d([A-Z]([A-Z]([A-Z]([A-Z]([A-Z0-9]{0,16})?)?)?)?)?)?)?)?)?$/;
|
|
74
|
+
function checkIBANInput(value) {
|
|
75
|
+
const clean = value.toUpperCase().replace(/[\s-]/g, "");
|
|
76
|
+
if (clean === "") return "empty";
|
|
77
|
+
if (clean.length > 24 || !IBAN_SHAPE.test(clean)) return "invalid";
|
|
78
|
+
if (clean.length < 24) return "incomplete";
|
|
79
|
+
return validateIBAN(clean) ? "valid" : "invalid";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { checkCNICInput, checkIBANInput, checkPhoneInput, formatCNICInput, formatIBANInput, formatPhoneInput };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkNTD4JLDW_cjs = require('./chunk-NTD4JLDW.cjs');
|
|
4
|
+
var chunkHTCSHHOR_cjs = require('./chunk-HTCSHHOR.cjs');
|
|
5
|
+
var chunk3IARSCO6_cjs = require('./chunk-3IARSCO6.cjs');
|
|
6
|
+
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
7
|
+
|
|
8
|
+
// src/input.ts
|
|
9
|
+
var SEPARATORS = /[\s\-‐‑‒–—./()]/g;
|
|
10
|
+
function formatCNICInput(value) {
|
|
11
|
+
const digits = chunkVPBMIYO2_cjs.toAsciiDigits(value).replace(/\D/g, "").slice(0, 13);
|
|
12
|
+
if (digits.length <= 5) return digits;
|
|
13
|
+
if (digits.length <= 12) return `${digits.slice(0, 5)}-${digits.slice(5)}`;
|
|
14
|
+
return `${digits.slice(0, 5)}-${digits.slice(5, 12)}-${digits.slice(12)}`;
|
|
15
|
+
}
|
|
16
|
+
function checkCNICInput(value) {
|
|
17
|
+
const text = chunkVPBMIYO2_cjs.toAsciiDigits(value).replace(SEPARATORS, "");
|
|
18
|
+
if (text === "") return "empty";
|
|
19
|
+
if (!/^\d+$/.test(text) || text.length > 13) return "invalid";
|
|
20
|
+
if (!/^[1-8]/.test(text)) return "invalid";
|
|
21
|
+
if (text.length < 13) return "incomplete";
|
|
22
|
+
return chunkHTCSHHOR_cjs.validateCNIC(text) ? "valid" : "invalid";
|
|
23
|
+
}
|
|
24
|
+
function splitPhone(value) {
|
|
25
|
+
const text = chunkVPBMIYO2_cjs.toAsciiDigits(value).replace(SEPARATORS, "");
|
|
26
|
+
if (!/^\+?\d*$/.test(text)) return null;
|
|
27
|
+
for (const code of ["+92", "0092", "92"]) {
|
|
28
|
+
if (code.startsWith(text) && text.length < code.length) {
|
|
29
|
+
return text === "0" ? { national: "", international: false } : "incomplete";
|
|
30
|
+
}
|
|
31
|
+
if (text.startsWith(code)) {
|
|
32
|
+
const rest = text.slice(code.length);
|
|
33
|
+
return {
|
|
34
|
+
national: rest.startsWith("0") ? rest.slice(1) : rest,
|
|
35
|
+
international: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (text.startsWith("+")) return null;
|
|
40
|
+
return {
|
|
41
|
+
national: text.startsWith("0") ? text.slice(1) : text,
|
|
42
|
+
international: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function formatPhoneInput(value) {
|
|
46
|
+
const split = splitPhone(value);
|
|
47
|
+
if (split === null) return value;
|
|
48
|
+
if (split === "incomplete")
|
|
49
|
+
return chunkVPBMIYO2_cjs.toAsciiDigits(value).replace(SEPARATORS, "");
|
|
50
|
+
const digits = split.national.replace(/\D/g, "").slice(0, 10);
|
|
51
|
+
if (split.international) {
|
|
52
|
+
return digits.length <= 3 ? `+92 ${digits}`.trimEnd() : `+92 ${digits.slice(0, 3)} ${digits.slice(3)}`;
|
|
53
|
+
}
|
|
54
|
+
const local = `0${digits}`;
|
|
55
|
+
return local.length <= 4 ? local : `${local.slice(0, 4)}-${local.slice(4)}`;
|
|
56
|
+
}
|
|
57
|
+
function checkPhoneInput(value) {
|
|
58
|
+
if (chunkVPBMIYO2_cjs.toAsciiDigits(value).replace(SEPARATORS, "") === "") return "empty";
|
|
59
|
+
const split = splitPhone(value);
|
|
60
|
+
if (split === null) return "invalid";
|
|
61
|
+
if (split === "incomplete") return "incomplete";
|
|
62
|
+
const { national } = split;
|
|
63
|
+
if (national === "") return "incomplete";
|
|
64
|
+
if (!national.startsWith("3")) return "invalid";
|
|
65
|
+
if (national.length >= 3 && !chunkNTD4JLDW_cjs.isAllocatedPrefix(`0${national.slice(0, 3)}`)) {
|
|
66
|
+
return "invalid";
|
|
67
|
+
}
|
|
68
|
+
if (national.length < 10) return "incomplete";
|
|
69
|
+
return national.length === 10 ? "valid" : "invalid";
|
|
70
|
+
}
|
|
71
|
+
function formatIBANInput(value) {
|
|
72
|
+
const clean = value.toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 24);
|
|
73
|
+
return clean.replace(/(.{4})(?=.)/g, "$1 ");
|
|
74
|
+
}
|
|
75
|
+
var IBAN_SHAPE = /^(P(K(\d(\d([A-Z]([A-Z]([A-Z]([A-Z]([A-Z0-9]{0,16})?)?)?)?)?)?)?)?)?$/;
|
|
76
|
+
function checkIBANInput(value) {
|
|
77
|
+
const clean = value.toUpperCase().replace(/[\s-]/g, "");
|
|
78
|
+
if (clean === "") return "empty";
|
|
79
|
+
if (clean.length > 24 || !IBAN_SHAPE.test(clean)) return "invalid";
|
|
80
|
+
if (clean.length < 24) return "incomplete";
|
|
81
|
+
return chunk3IARSCO6_cjs.validateIBAN(clean) ? "valid" : "invalid";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
exports.checkCNICInput = checkCNICInput;
|
|
85
|
+
exports.checkIBANInput = checkIBANInput;
|
|
86
|
+
exports.checkPhoneInput = checkPhoneInput;
|
|
87
|
+
exports.formatCNICInput = formatCNICInput;
|
|
88
|
+
exports.formatIBANInput = formatIBANInput;
|
|
89
|
+
exports.formatPhoneInput = formatPhoneInput;
|