pakdatakit 2.1.2 → 2.2.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 +104 -0
- package/README.md +85 -3
- package/dist/address.cjs +4 -4
- package/dist/address.js +2 -2
- package/dist/{chunk-PHHKIMO2.cjs → chunk-33FXHM2E.cjs} +5 -5
- package/dist/chunk-3IARSCO6.cjs +317 -0
- package/dist/{chunk-BSS4Z7NI.cjs → chunk-3ZA265SK.cjs} +2 -2
- 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-AUATLZA5.cjs → chunk-CLL6VDPO.cjs} +4 -4
- 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-L2BDDM2W.js → chunk-I664KOWP.js} +1 -1
- package/dist/{chunk-K6CZFCX6.js → chunk-J272OMDL.js} +51 -6
- 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-T3E4B5MJ.js → chunk-RXNYY5K5.js} +1 -1
- package/dist/{chunk-3COX5FSL.cjs → chunk-SBS2GHM3.cjs} +51 -6
- 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/geo.cjs +6 -6
- package/dist/geo.js +1 -1
- package/dist/holidays.d.cts +2 -1
- package/dist/holidays.d.ts +2 -1
- package/dist/iban.cjs +11 -3
- package/dist/iban.d.cts +45 -1
- package/dist/iban.d.ts +45 -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 +67 -0
- package/dist/input.d.ts +67 -0
- package/dist/input.js +5 -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/phone.cjs +8 -8
- package/dist/phone.js +3 -3
- package/dist/raast.cjs +9 -5
- package/dist/raast.d.cts +53 -8
- package/dist/raast.d.ts +53 -8
- package/dist/raast.js +2 -2
- 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.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 +16 -3
- package/dist/chunk-4EUKCSLW.js +0 -221
- package/dist/chunk-E47SNBWQ.cjs +0 -224
|
@@ -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) {
|
|
@@ -916,6 +916,10 @@ var districts_default = [
|
|
|
916
916
|
district: "Abbottabad",
|
|
917
917
|
province: "Khyber Pakhtunkhwa"
|
|
918
918
|
},
|
|
919
|
+
{
|
|
920
|
+
district: "Allai",
|
|
921
|
+
province: "Khyber Pakhtunkhwa"
|
|
922
|
+
},
|
|
919
923
|
{
|
|
920
924
|
district: "Astore",
|
|
921
925
|
province: "Gilgit-Baltistan"
|
|
@@ -956,6 +960,10 @@ var districts_default = [
|
|
|
956
960
|
district: "Barkhan",
|
|
957
961
|
province: "Balochistan"
|
|
958
962
|
},
|
|
963
|
+
{
|
|
964
|
+
district: "Barshore",
|
|
965
|
+
province: "Balochistan"
|
|
966
|
+
},
|
|
959
967
|
{
|
|
960
968
|
district: "Batagram",
|
|
961
969
|
province: "Khyber Pakhtunkhwa"
|
|
@@ -972,6 +980,10 @@ var districts_default = [
|
|
|
972
980
|
district: "Buner",
|
|
973
981
|
province: "Khyber Pakhtunkhwa"
|
|
974
982
|
},
|
|
983
|
+
{
|
|
984
|
+
district: "Central Dir",
|
|
985
|
+
province: "Khyber Pakhtunkhwa"
|
|
986
|
+
},
|
|
975
987
|
{
|
|
976
988
|
district: "Chagai",
|
|
977
989
|
province: "Balochistan"
|
|
@@ -1000,10 +1012,6 @@ var districts_default = [
|
|
|
1000
1012
|
district: "Darel",
|
|
1001
1013
|
province: "Gilgit-Baltistan"
|
|
1002
1014
|
},
|
|
1003
|
-
{
|
|
1004
|
-
district: "Dera Bugti",
|
|
1005
|
-
province: "Balochistan"
|
|
1006
|
-
},
|
|
1007
1015
|
{
|
|
1008
1016
|
district: "Dera Ghazi Khan",
|
|
1009
1017
|
province: "Punjab"
|
|
@@ -1360,6 +1368,10 @@ var districts_default = [
|
|
|
1360
1368
|
district: "Neelam",
|
|
1361
1369
|
province: "Azad Jammu and Kashmir"
|
|
1362
1370
|
},
|
|
1371
|
+
{
|
|
1372
|
+
district: "North Dera Bugti",
|
|
1373
|
+
province: "Balochistan"
|
|
1374
|
+
},
|
|
1363
1375
|
{
|
|
1364
1376
|
district: "North Waziristan",
|
|
1365
1377
|
province: "Khyber Pakhtunkhwa"
|
|
@@ -1380,6 +1392,10 @@ var districts_default = [
|
|
|
1380
1392
|
district: "Orakzai",
|
|
1381
1393
|
province: "Khyber Pakhtunkhwa"
|
|
1382
1394
|
},
|
|
1395
|
+
{
|
|
1396
|
+
district: "Paharpur",
|
|
1397
|
+
province: "Khyber Pakhtunkhwa"
|
|
1398
|
+
},
|
|
1383
1399
|
{
|
|
1384
1400
|
district: "Pakpattan",
|
|
1385
1401
|
province: "Punjab"
|
|
@@ -1405,7 +1421,11 @@ var districts_default = [
|
|
|
1405
1421
|
province: "Sindh"
|
|
1406
1422
|
},
|
|
1407
1423
|
{
|
|
1408
|
-
district: "Quetta",
|
|
1424
|
+
district: "Quetta East",
|
|
1425
|
+
province: "Balochistan"
|
|
1426
|
+
},
|
|
1427
|
+
{
|
|
1428
|
+
district: "Quetta West",
|
|
1409
1429
|
province: "Balochistan"
|
|
1410
1430
|
},
|
|
1411
1431
|
{
|
|
@@ -1476,6 +1496,10 @@ var districts_default = [
|
|
|
1476
1496
|
district: "Sohbatpur",
|
|
1477
1497
|
province: "Balochistan"
|
|
1478
1498
|
},
|
|
1499
|
+
{
|
|
1500
|
+
district: "South Dera Bugti",
|
|
1501
|
+
province: "Balochistan"
|
|
1502
|
+
},
|
|
1479
1503
|
{
|
|
1480
1504
|
district: "Sudhnuti",
|
|
1481
1505
|
province: "Azad Jammu and Kashmir"
|
|
@@ -1540,6 +1564,10 @@ var districts_default = [
|
|
|
1540
1564
|
district: "Tor Ghar",
|
|
1541
1565
|
province: "Khyber Pakhtunkhwa"
|
|
1542
1566
|
},
|
|
1567
|
+
{
|
|
1568
|
+
district: "Tump",
|
|
1569
|
+
province: "Balochistan"
|
|
1570
|
+
},
|
|
1543
1571
|
{
|
|
1544
1572
|
district: "Umerkot",
|
|
1545
1573
|
province: "Sindh"
|
|
@@ -1560,6 +1588,10 @@ var districts_default = [
|
|
|
1560
1588
|
district: "Upper South Waziristan",
|
|
1561
1589
|
province: "Khyber Pakhtunkhwa"
|
|
1562
1590
|
},
|
|
1591
|
+
{
|
|
1592
|
+
district: "Upper Swat",
|
|
1593
|
+
province: "Khyber Pakhtunkhwa"
|
|
1594
|
+
},
|
|
1563
1595
|
{
|
|
1564
1596
|
district: "Usta Muhammad",
|
|
1565
1597
|
province: "Balochistan"
|
|
@@ -1568,6 +1600,10 @@ var districts_default = [
|
|
|
1568
1600
|
district: "Vehari",
|
|
1569
1601
|
province: "Punjab"
|
|
1570
1602
|
},
|
|
1603
|
+
{
|
|
1604
|
+
district: "Wadh",
|
|
1605
|
+
province: "Balochistan"
|
|
1606
|
+
},
|
|
1571
1607
|
{
|
|
1572
1608
|
district: "Washuk",
|
|
1573
1609
|
province: "Balochistan"
|
|
@@ -1621,8 +1657,17 @@ function getDistrictProvince(district) {
|
|
|
1621
1657
|
if (key.length === 0) {
|
|
1622
1658
|
return null;
|
|
1623
1659
|
}
|
|
1624
|
-
return districtLookup().get(key) ?? null;
|
|
1660
|
+
return districtLookup().get(key) ?? (Object.hasOwn(FORMER_DISTRICTS, key) ? FORMER_DISTRICTS[key] : null) ?? null;
|
|
1625
1661
|
}
|
|
1662
|
+
var FORMER_DISTRICTS = {
|
|
1663
|
+
// Split into Lower and Upper South Waziristan (2022).
|
|
1664
|
+
"south waziristan": "Khyber Pakhtunkhwa",
|
|
1665
|
+
// Split into Quetta East and Quetta West (2026).
|
|
1666
|
+
quetta: "Balochistan",
|
|
1667
|
+
// Became South Dera Bugti; Upper Dera Bugti became North Dera Bugti (2026).
|
|
1668
|
+
"dera bugti": "Balochistan",
|
|
1669
|
+
"upper dera bugti": "Balochistan"
|
|
1670
|
+
};
|
|
1626
1671
|
function searchDistricts(query) {
|
|
1627
1672
|
const normalizedQuery = chunkVPBMIYO2_cjs.normalizeKey(query);
|
|
1628
1673
|
if (normalizedQuery.length === 0) {
|
|
@@ -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;
|