pakdatakit 2.2.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/DATA.md +512 -34
  2. package/LICENSE +1 -1
  3. package/NOTICE +14 -0
  4. package/README.md +472 -28
  5. package/dist/address.cjs +6 -5
  6. package/dist/address.js +4 -3
  7. package/dist/bills.cjs +19 -0
  8. package/dist/bills.d.cts +63 -0
  9. package/dist/bills.d.ts +63 -0
  10. package/dist/bills.js +2 -0
  11. package/dist/{chunk-4VSGCQ6K.cjs → chunk-2OBKPYJZ.cjs} +3 -3
  12. package/dist/chunk-33GOK7EE.cjs +5312 -0
  13. package/dist/chunk-33QMFE2Z.js +21244 -0
  14. package/dist/chunk-34U2ZMHR.js +194 -0
  15. package/dist/chunk-4GSBHJX6.js +165 -0
  16. package/dist/chunk-5DDHO5Z7.cjs +565 -0
  17. package/dist/chunk-5EY5DQS7.js +51 -0
  18. package/dist/chunk-5RGX4DWF.js +559 -0
  19. package/dist/chunk-5UCRHVI4.cjs +302 -0
  20. package/dist/{chunk-TTARJWGT.js → chunk-7DY26QPN.js} +2 -2
  21. package/dist/chunk-7E7L3NYS.cjs +11 -0
  22. package/dist/{chunk-3ZA265SK.cjs → chunk-AUQFA7EE.cjs} +172 -4
  23. package/dist/{chunk-QKH7W2CC.js → chunk-B7DOQ5QF.js} +6 -5
  24. package/dist/{chunk-HBOZIITD.js → chunk-CADQM4ZN.js} +14 -14
  25. package/dist/chunk-CF6AMRBU.cjs +198 -0
  26. package/dist/chunk-CZOZB4K3.js +61 -0
  27. package/dist/{chunk-3IARSCO6.cjs → chunk-DHOP7LQX.cjs} +25 -14
  28. package/dist/chunk-E2XU6NOW.js +909 -0
  29. package/dist/chunk-E6GWBOKV.cjs +911 -0
  30. package/dist/chunk-E6HSKRAE.js +9 -0
  31. package/dist/chunk-EA3SIHYT.js +313 -0
  32. package/dist/{chunk-33FXHM2E.cjs → chunk-ESKXG7Y6.cjs} +5 -5
  33. package/dist/chunk-I7UUPD3G.cjs +21252 -0
  34. package/dist/{chunk-YPPKY5XZ.js → chunk-IBZPJS4H.js} +26 -15
  35. package/dist/chunk-IDTRFOQW.js +35 -0
  36. package/dist/{chunk-XCXFGTHW.cjs → chunk-J5ZF46NZ.cjs} +14 -14
  37. package/dist/{chunk-NZQ47NWD.js → chunk-KRYHLYN2.js} +1 -1
  38. package/dist/{chunk-RXNYY5K5.js → chunk-LQHM3ADX.js} +172 -4
  39. package/dist/{chunk-HTERSQGF.cjs → chunk-MTS6SVNP.cjs} +4 -4
  40. package/dist/chunk-OTI7HY55.js +297 -0
  41. package/dist/{chunk-6IPPANNX.js → chunk-P7LVE2TF.js} +2 -2
  42. package/dist/{chunk-47P7HILD.cjs → chunk-QFPEFD67.cjs} +9 -8
  43. package/dist/chunk-RZQJAZKC.js +22 -0
  44. package/dist/{chunk-PLDVGOKZ.js → chunk-S274QFFB.js} +2 -2
  45. package/dist/chunk-SF4ECUZ6.cjs +56 -0
  46. package/dist/chunk-SQIHFEXI.cjs +25 -0
  47. package/dist/{chunk-NAJGGUAM.cjs → chunk-TC3VRWZV.cjs} +2 -2
  48. package/dist/{chunk-U7MWHXMF.cjs → chunk-TVL6RDAU.cjs} +4 -4
  49. package/dist/chunk-UYFTXD4P.js +168 -0
  50. package/dist/{chunk-AZV45DMG.js → chunk-V2XE3NCG.js} +2 -2
  51. package/dist/chunk-XCFZKCV2.cjs +37 -0
  52. package/dist/chunk-XOTCIXY6.js +5301 -0
  53. package/dist/chunk-XVEG53NN.cjs +322 -0
  54. package/dist/chunk-YDUXIENX.cjs +172 -0
  55. package/dist/chunk-YPAWNWFD.cjs +168 -0
  56. package/dist/chunk-YQFI7W3I.cjs +65 -0
  57. package/dist/{chunk-NTD4JLDW.cjs → chunk-YTLE5K7G.cjs} +1 -1
  58. package/dist/{chunk-EMH4IP2U.js → chunk-ZRONAQBV.js} +1 -1
  59. package/dist/class-validator.cjs +65 -0
  60. package/dist/class-validator.d.cts +63 -0
  61. package/dist/class-validator.d.ts +63 -0
  62. package/dist/class-validator.js +54 -0
  63. package/dist/cli.js +1 -1
  64. package/dist/courier.cjs +16 -0
  65. package/dist/courier.d.cts +51 -0
  66. package/dist/courier.d.ts +51 -0
  67. package/dist/courier.js +3 -0
  68. package/dist/fbr-invoice.cjs +25 -0
  69. package/dist/fbr-invoice.d.cts +170 -0
  70. package/dist/fbr-invoice.d.ts +170 -0
  71. package/dist/fbr-invoice.js +4 -0
  72. package/dist/geo.cjs +23 -6
  73. package/dist/geo.d.cts +56 -1
  74. package/dist/geo.d.ts +56 -1
  75. package/dist/geo.js +2 -1
  76. package/dist/holidays.cjs +4 -4
  77. package/dist/holidays.js +1 -1
  78. package/dist/iban.cjs +5 -5
  79. package/dist/iban.d.cts +8 -6
  80. package/dist/iban.d.ts +8 -6
  81. package/dist/iban.js +1 -1
  82. package/dist/incometax.cjs +27 -0
  83. package/dist/incometax.d.cts +91 -0
  84. package/dist/incometax.d.ts +91 -0
  85. package/dist/incometax.js +2 -0
  86. package/dist/index.cjs +253 -111
  87. package/dist/index.d.cts +12 -4
  88. package/dist/index.d.ts +12 -4
  89. package/dist/index.js +25 -15
  90. package/dist/input.cjs +9 -9
  91. package/dist/input.js +3 -3
  92. package/dist/joi.cjs +43 -0
  93. package/dist/joi.d.cts +25 -0
  94. package/dist/joi.d.ts +25 -0
  95. package/dist/joi.js +37 -0
  96. package/dist/networks.cjs +3 -3
  97. package/dist/networks.js +2 -2
  98. package/dist/numbers.cjs +6 -6
  99. package/dist/numbers.js +2 -2
  100. package/dist/passport.cjs +11 -0
  101. package/dist/passport.d.cts +27 -0
  102. package/dist/passport.d.ts +27 -0
  103. package/dist/passport.js +2 -0
  104. package/dist/phone.cjs +8 -8
  105. package/dist/phone.js +3 -3
  106. package/dist/postal.cjs +14 -6
  107. package/dist/postal.d.cts +54 -2
  108. package/dist/postal.d.ts +54 -2
  109. package/dist/postal.js +1 -1
  110. package/dist/quality.cjs +25 -0
  111. package/dist/quality.d.cts +62 -0
  112. package/dist/quality.d.ts +62 -0
  113. package/dist/quality.js +8 -0
  114. package/dist/raast.cjs +6 -6
  115. package/dist/raast.js +2 -2
  116. package/dist/salestax.cjs +20 -0
  117. package/dist/salestax.d.cts +106 -0
  118. package/dist/salestax.d.ts +106 -0
  119. package/dist/salestax.js +3 -0
  120. package/dist/superstruct.cjs +41 -0
  121. package/dist/superstruct.d.cts +25 -0
  122. package/dist/superstruct.d.ts +25 -0
  123. package/dist/superstruct.js +39 -0
  124. package/dist/text.cjs +21 -5
  125. package/dist/text.d.cts +90 -1
  126. package/dist/text.d.ts +90 -1
  127. package/dist/text.js +1 -1
  128. package/dist/valibot.cjs +18 -8
  129. package/dist/valibot.d.cts +3 -0
  130. package/dist/valibot.d.ts +3 -0
  131. package/dist/valibot.js +17 -7
  132. package/dist/vehicle.cjs +15 -0
  133. package/dist/vehicle.d.cts +43 -0
  134. package/dist/vehicle.d.ts +43 -0
  135. package/dist/vehicle.js +2 -0
  136. package/dist/whatsapp.cjs +3 -3
  137. package/dist/whatsapp.js +2 -2
  138. package/dist/yup.cjs +18 -8
  139. package/dist/yup.d.cts +3 -0
  140. package/dist/yup.d.ts +3 -0
  141. package/dist/yup.js +17 -7
  142. package/dist/zod.cjs +18 -8
  143. package/dist/zod.d.cts +3 -0
  144. package/dist/zod.d.ts +3 -0
  145. package/dist/zod.js +17 -7
  146. package/package.json +167 -6
  147. package/dist/chunk-34CJGJ67.cjs +0 -1697
  148. package/dist/chunk-4VVFS6FN.cjs +0 -715
  149. package/dist/chunk-E6DT2DWQ.js +0 -1689
  150. package/dist/chunk-GJENL6VK.cjs +0 -22
  151. package/dist/chunk-HUQY2WR5.js +0 -20
  152. package/dist/chunk-JKE4AMSZ.js +0 -47
  153. package/dist/chunk-KEHCTYLO.cjs +0 -52
  154. package/dist/chunk-LIYNKIKS.js +0 -709
@@ -0,0 +1,297 @@
1
+ import { calculateSalesTax } from './chunk-34U2ZMHR.js';
2
+ import { toUnits, fromPaisa, divideHalfUp } from './chunk-5EY5DQS7.js';
3
+ import { normalizeKey } from './chunk-ENQ7O7VW.js';
4
+
5
+ // src/fbr-invoice.ts
6
+ var FBR_DI_SPEC_VERSION = "1.12";
7
+ var INVOICE_TYPES = /* @__PURE__ */ new Set(["Sale Invoice", "Debit Note"]);
8
+ var REGISTRATION_TYPES = /* @__PURE__ */ new Set(["Registered", "Unregistered"]);
9
+ var NTN_OR_CNIC = /^(?:\d{7}|\d{13})$/;
10
+ var FBR_INVOICE_NUMBER = /^(?:\d{7}|\d{13})DI\d{13}$/;
11
+ var SCENARIO = /^SN0(?:0[1-9]|1\d|2[0-8])$/;
12
+ var PERCENT_RATE = /^(\d+(?:\.\d+)?)%$/;
13
+ var PER_UNIT_RATE = /^rs\.?\s*(\d+(?:\.\d+)?)$/i;
14
+ var isText = (value) => typeof value === "string";
15
+ var filled = (value) => isText(value) && value.trim().length > 0;
16
+ var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
17
+ var saleTypeKey = (value) => isText(value) ? normalizeKey(value) : "";
18
+ function decimalPlaces(value) {
19
+ if (!Number.isFinite(value)) return null;
20
+ const match = /^-?\d+(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(value));
21
+ if (!match) return null;
22
+ const places = (match[1] ?? "").length - Number(match[2] ?? "0");
23
+ return places > 0 ? places : 0;
24
+ }
25
+ function expectedSalesTax(item) {
26
+ if (!isObject(item) || !isText(item.rate)) return null;
27
+ const rate = item.rate.trim();
28
+ const percent = PERCENT_RATE.exec(rate);
29
+ if (percent) {
30
+ const base = saleTypeKey(item.saleType) === "3rd schedule goods" ? item.fixedNotifiedValueOrRetailPrice : item.valueSalesExcludingST;
31
+ if (typeof base !== "number") return null;
32
+ return calculateSalesTax(base, { rate: Number(percent[1]) })?.tax ?? null;
33
+ }
34
+ const perUnit = PER_UNIT_RATE.exec(rate);
35
+ if (perUnit) {
36
+ if (typeof item.quantity !== "number") return null;
37
+ const quantity = toUnits(item.quantity, 4);
38
+ const price = toUnits(Number(perUnit[1]), 2);
39
+ if (quantity === null || price === null) return null;
40
+ return fromPaisa(divideHalfUp(BigInt(quantity) * BigInt(price), 10000n));
41
+ }
42
+ return null;
43
+ }
44
+ var NUMBER_FIELDS = [
45
+ "quantity",
46
+ "valueSalesExcludingST",
47
+ "salesTaxApplicable",
48
+ "salesTaxWithheldAtSource",
49
+ "extraTax",
50
+ "furtherTax",
51
+ "fedPayable",
52
+ "discount"
53
+ ];
54
+ function columnTotal(items, key) {
55
+ const scale = key === "quantity" ? 4 : 2;
56
+ let sum = 0;
57
+ for (const item of items) {
58
+ const value = item[key];
59
+ if (typeof value !== "number") continue;
60
+ const units = toUnits(value, scale);
61
+ if (units !== null) sum += units;
62
+ }
63
+ return sum / (scale === 4 ? 1e4 : 100);
64
+ }
65
+ function buildFbrInvoice(input) {
66
+ if (!isObject(input) || !Array.isArray(input.items)) return null;
67
+ const items = [];
68
+ for (const raw of input.items) {
69
+ if (!isObject(raw)) return null;
70
+ const line = raw;
71
+ const item = {
72
+ ...line,
73
+ totalValues: line.totalValues ?? 0,
74
+ fixedNotifiedValueOrRetailPrice: line.fixedNotifiedValueOrRetailPrice ?? 0,
75
+ salesTaxWithheldAtSource: line.salesTaxWithheldAtSource ?? 0
76
+ };
77
+ item.salesTaxApplicable = line.salesTaxApplicable ?? expectedSalesTax(item) ?? 0;
78
+ items.push(item);
79
+ }
80
+ const invoice = {
81
+ ...input,
82
+ buyerNTNCNIC: input.buyerNTNCNIC ?? "",
83
+ invoiceRefNo: input.invoiceRefNo ?? "",
84
+ items
85
+ };
86
+ const totals = Object.fromEntries(
87
+ NUMBER_FIELDS.map((key) => [key, columnTotal(items, key)])
88
+ );
89
+ return { invoice, totals };
90
+ }
91
+ function validDate(text) {
92
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
93
+ if (!match) return false;
94
+ const [y, m, d] = [Number(match[1]), Number(match[2]), Number(match[3])];
95
+ const leap = y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
96
+ const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
97
+ return m >= 1 && m <= 12 && d >= 1 && d <= days[m - 1];
98
+ }
99
+ function validateFbrInvoice(invoice, options = {}) {
100
+ const errors = [];
101
+ const add = (code, field, message) => errors.push({ code, field, message });
102
+ if (!isObject(invoice)) {
103
+ add(null, "invoice", "The invoice must be an object");
104
+ return { valid: false, errors };
105
+ }
106
+ const inv = invoice;
107
+ if (!filled(inv.invoiceType)) {
108
+ add("0011", "invoiceType", "Invoice type is empty");
109
+ } else if (!INVOICE_TYPES.has(inv.invoiceType)) {
110
+ add(
111
+ "0003",
112
+ "invoiceType",
113
+ 'Invoice type must be "Sale Invoice" or "Debit Note"'
114
+ );
115
+ }
116
+ if (!filled(inv.invoiceDate)) {
117
+ add("0042", "invoiceDate", "Invoice date is empty");
118
+ } else if (!/^\d{4}-\d{2}-\d{2}$/.test(inv.invoiceDate)) {
119
+ add("0005", "invoiceDate", "Invoice date must be in YYYY-MM-DD format");
120
+ } else if (!validDate(inv.invoiceDate)) {
121
+ add("0113", "invoiceDate", "Invoice date is not a valid date");
122
+ } else if (isText(options?.today) && validDate(options.today) && inv.invoiceDate > options.today) {
123
+ add("0043", "invoiceDate", "Invoice date is later than today");
124
+ }
125
+ if (!isText(inv.sellerNTNCNIC) || !NTN_OR_CNIC.test(inv.sellerNTNCNIC)) {
126
+ add("0401", "sellerNTNCNIC", "Seller NTN or CNIC must be 7 or 13 digits");
127
+ }
128
+ if (!filled(inv.sellerBusinessName)) {
129
+ add(null, "sellerBusinessName", "Seller business name is required");
130
+ }
131
+ if (!filled(inv.sellerProvince)) {
132
+ add("0073", "sellerProvince", "Seller province is empty");
133
+ }
134
+ if (!filled(inv.sellerAddress)) {
135
+ add(null, "sellerAddress", "Seller address is required");
136
+ }
137
+ const registration = inv.buyerRegistrationType;
138
+ if (!isText(registration) || !REGISTRATION_TYPES.has(registration)) {
139
+ add(
140
+ "0012",
141
+ "buyerRegistrationType",
142
+ 'Buyer registration type must be "Registered" or "Unregistered"'
143
+ );
144
+ }
145
+ const buyerId = inv.buyerNTNCNIC;
146
+ if (!filled(buyerId)) {
147
+ if (registration !== "Unregistered") {
148
+ add("0009", "buyerNTNCNIC", "Buyer NTN or CNIC is empty");
149
+ }
150
+ } else if (!NTN_OR_CNIC.test(buyerId)) {
151
+ add("0402", "buyerNTNCNIC", "Buyer NTN or CNIC must be 7 or 13 digits");
152
+ } else if (buyerId === inv.sellerNTNCNIC) {
153
+ add(
154
+ "0058",
155
+ "buyerNTNCNIC",
156
+ "Buyer and seller must be different (self-invoicing is not allowed)"
157
+ );
158
+ }
159
+ if (!filled(inv.buyerBusinessName)) {
160
+ add("0010", "buyerBusinessName", "Buyer business name is empty");
161
+ }
162
+ if (!filled(inv.buyerProvince)) {
163
+ add("0074", "buyerProvince", "Buyer province is empty");
164
+ }
165
+ if (!filled(inv.buyerAddress)) {
166
+ add(null, "buyerAddress", "Buyer address is required");
167
+ }
168
+ if (filled(inv.invoiceRefNo)) {
169
+ if (!FBR_INVOICE_NUMBER.test(inv.invoiceRefNo.trim())) {
170
+ add(
171
+ null,
172
+ "invoiceRefNo",
173
+ 'Invoice reference number must be an FBR invoice number (NTN or CNIC, "DI", 13 digits)'
174
+ );
175
+ }
176
+ } else if (inv.invoiceType === "Debit Note") {
177
+ add(
178
+ "0026",
179
+ "invoiceRefNo",
180
+ "Invoice reference number is required for a debit note"
181
+ );
182
+ }
183
+ if (inv.scenarioId !== void 0 && inv.scenarioId !== null && inv.scenarioId !== "") {
184
+ if (!isText(inv.scenarioId) || !SCENARIO.test(inv.scenarioId)) {
185
+ add(null, "scenarioId", "Scenario ID must be SN001 to SN028");
186
+ }
187
+ }
188
+ if (!Array.isArray(inv.items) || inv.items.length === 0) {
189
+ add(null, "items", "The invoice needs at least one item");
190
+ return { valid: errors.length === 0, errors };
191
+ }
192
+ inv.items.forEach((raw, index) => {
193
+ const at = (key) => `items[${index}].${key}`;
194
+ if (!isObject(raw)) {
195
+ add(null, `items[${index}]`, "Each item must be an object");
196
+ return;
197
+ }
198
+ const item = raw;
199
+ if (!filled(item.hsCode)) add("0044", at("hsCode"), "HS code is empty");
200
+ if (!isText(item.productDescription)) {
201
+ add(null, at("productDescription"), "Product description is required");
202
+ }
203
+ if (!filled(item.rate)) add("0020", at("rate"), "Rate is empty");
204
+ if (!filled(item.uoM)) add(null, at("uoM"), "Unit of measure is required");
205
+ if (!filled(item.saleType))
206
+ add("0013", at("saleType"), "Sale type is empty");
207
+ const missingCodes = {
208
+ quantity: "0098",
209
+ valueSalesExcludingST: "0021",
210
+ salesTaxApplicable: "0023",
211
+ salesTaxWithheldAtSource: "0024",
212
+ totalValues: null,
213
+ fixedNotifiedValueOrRetailPrice: null
214
+ };
215
+ const numbersOk = {};
216
+ for (const key of [
217
+ ...Object.keys(missingCodes),
218
+ "extraTax",
219
+ "furtherTax",
220
+ "fedPayable",
221
+ "discount"
222
+ ]) {
223
+ const value = item[key];
224
+ const required = key in missingCodes;
225
+ if (value === void 0 || value === null || !required && value === "") {
226
+ if (required) {
227
+ add(missingCodes[key] ?? null, at(key), `${key} is required`);
228
+ }
229
+ continue;
230
+ }
231
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
232
+ add("0300", at(key), `${key} must be a number, not negative`);
233
+ continue;
234
+ }
235
+ const places = decimalPlaces(value);
236
+ const limit = key === "quantity" ? 4 : 2;
237
+ if (places > limit) {
238
+ add("0302", at(key), `${key} has more than ${limit} decimal places`);
239
+ continue;
240
+ }
241
+ numbersOk[key] = true;
242
+ }
243
+ const rate = isText(item.rate) ? item.rate.trim() : "";
244
+ if (filled(item.rate) && rate !== "18%" && !filled(item.sroScheduleNo)) {
245
+ add(
246
+ "0077",
247
+ at("sroScheduleNo"),
248
+ "SRO/schedule number is required when the rate is not 18%"
249
+ );
250
+ }
251
+ if (filled(item.sroScheduleNo) && !filled(item.sroItemSerialNo)) {
252
+ add(
253
+ "0078",
254
+ at("sroItemSerialNo"),
255
+ "Item serial number is required when an SRO/schedule number is given"
256
+ );
257
+ }
258
+ const saleType = saleTypeKey(item.saleType);
259
+ if (saleType === "3rd schedule goods" && numbersOk.fixedNotifiedValueOrRetailPrice === true && item.fixedNotifiedValueOrRetailPrice === 0) {
260
+ add(
261
+ "0090",
262
+ at("fixedNotifiedValueOrRetailPrice"),
263
+ "Retail price is required for Third Schedule goods"
264
+ );
265
+ }
266
+ if (saleType === "goods at reduced rate" && item.extraTax !== void 0 && item.extraTax !== null && item.extraTax !== "") {
267
+ add(
268
+ "0091",
269
+ at("extraTax"),
270
+ "Extra tax must be empty for goods at a reduced rate"
271
+ );
272
+ }
273
+ if (numbersOk.salesTaxApplicable === true) {
274
+ const percent = PERCENT_RATE.test(rate);
275
+ const perUnit = PER_UNIT_RATE.test(rate);
276
+ const baseKey = perUnit ? "quantity" : saleType === "3rd schedule goods" ? "fixedNotifiedValueOrRetailPrice" : "valueSalesExcludingST";
277
+ if ((percent || perUnit) && numbersOk[baseKey] === true) {
278
+ const expected = expectedSalesTax(item);
279
+ if (expected !== null) {
280
+ const actual = toUnits(item.salesTaxApplicable, 2);
281
+ const wanted = toUnits(expected, 2);
282
+ if (actual !== null && wanted !== null && Math.abs(actual - wanted) > 1) {
283
+ const code = perUnit ? "0105" : saleType === "3rd schedule goods" ? "0102" : "0104";
284
+ add(
285
+ code,
286
+ at("salesTaxApplicable"),
287
+ `Sales tax should be ${expected.toFixed(2)} for this rate`
288
+ );
289
+ }
290
+ }
291
+ }
292
+ }
293
+ });
294
+ return { valid: errors.length === 0, errors };
295
+ }
296
+
297
+ export { FBR_DI_SPEC_VERSION, buildFbrInvoice, expectedSalesTax, validateFbrInvoice };
@@ -1,4 +1,4 @@
1
- import { lazy, stripSeparators, toAsciiDigits } from './chunk-ENQ7O7VW.js';
1
+ import { stripSeparators, toAsciiDigits, lazy } from './chunk-ENQ7O7VW.js';
2
2
 
3
3
  // data/networks.json
4
4
  var networks_default = [
@@ -58,7 +58,7 @@ var networks_default = [
58
58
  ];
59
59
 
60
60
  // src/internal/phone-utils.ts
61
- var allocatedPrefixes = lazy(
61
+ var allocatedPrefixes = /* @__PURE__ */ lazy(
62
62
  () => new Set(
63
63
  networks_default.map((entry) => entry.prefix)
64
64
  )
@@ -1,18 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var chunk4VVFS6FN_cjs = require('./chunk-4VVFS6FN.cjs');
4
- var chunk34CJGJ67_cjs = require('./chunk-34CJGJ67.cjs');
3
+ var chunkI7UUPD3G_cjs = require('./chunk-I7UUPD3G.cjs');
4
+ var chunk33GOK7EE_cjs = require('./chunk-33GOK7EE.cjs');
5
+ var chunkE6GWBOKV_cjs = require('./chunk-E6GWBOKV.cjs');
5
6
  var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
6
7
 
7
8
  // src/address.ts
8
9
  function byLengthDesc(a, b) {
9
10
  return b.length - a.length;
10
11
  }
11
- var cityNames = chunkVPBMIYO2_cjs.lazy(
12
- () => chunk34CJGJ67_cjs.cities_default.map((entry) => entry.city).sort(byLengthDesc)
12
+ var cityNames = /* @__PURE__ */ chunkVPBMIYO2_cjs.lazy(
13
+ () => chunkE6GWBOKV_cjs.cities_default.map((entry) => entry.city).sort(byLengthDesc)
13
14
  );
14
- var districtNames = chunkVPBMIYO2_cjs.lazy(
15
- () => chunk34CJGJ67_cjs.districts_default.map((entry) => entry.district).sort(byLengthDesc)
15
+ var districtNames = /* @__PURE__ */ chunkVPBMIYO2_cjs.lazy(
16
+ () => chunk33GOK7EE_cjs.districts_default.map((entry) => entry.district).sort(byLengthDesc)
16
17
  );
17
18
  var PROVINCES = [
18
19
  "Islamabad Capital Territory",
@@ -80,9 +81,9 @@ function parseAddress(address) {
80
81
  city = district;
81
82
  }
82
83
  if (postalCode !== null && city === null) {
83
- city = chunk4VVFS6FN_cjs.getCityByPostalCode(postalCode);
84
+ city = chunkI7UUPD3G_cjs.getCityByPostalCode(postalCode);
84
85
  }
85
- const inferredProvince = city !== null ? chunk34CJGJ67_cjs.getProvince(city) ?? chunk34CJGJ67_cjs.getDistrictProvince(city) : district !== null ? chunk34CJGJ67_cjs.getDistrictProvince(district) : null;
86
+ const inferredProvince = city !== null ? chunk33GOK7EE_cjs.getProvince(city) ?? chunk33GOK7EE_cjs.getDistrictProvince(city) : district !== null ? chunk33GOK7EE_cjs.getDistrictProvince(district) : null;
86
87
  if (province === null) {
87
88
  province = inferredProvince;
88
89
  } else if (inferredProvince !== null && inferredProvince !== province) {
@@ -0,0 +1,22 @@
1
+ import { toAsciiDigits } from './chunk-ENQ7O7VW.js';
2
+
3
+ // src/vehicle.ts
4
+ var PLATE = /^([A-Z]{1,4})[-‐‑‒–— ]?(\d{1,4})(?:[-‐‑‒–— /]{1,3}(\d{2}))?$/;
5
+ function parseVehiclePlate(plate) {
6
+ const match = PLATE.exec(toAsciiDigits(plate.trim()).toUpperCase());
7
+ if (!match) {
8
+ return null;
9
+ }
10
+ const [, series, number, year] = match;
11
+ return {
12
+ series,
13
+ number,
14
+ year: year ?? null,
15
+ formatted: `${series}-${number}`
16
+ };
17
+ }
18
+ function validateVehiclePlate(plate) {
19
+ return parseVehiclePlate(plate) !== null;
20
+ }
21
+
22
+ export { parseVehiclePlate, validateVehiclePlate };
@@ -1,5 +1,5 @@
1
- import { getNetwork } from './chunk-AZV45DMG.js';
2
- import { normalizePhoneDigits } from './chunk-6IPPANNX.js';
1
+ import { getNetwork } from './chunk-V2XE3NCG.js';
2
+ import { normalizePhoneDigits } from './chunk-P7LVE2TF.js';
3
3
 
4
4
  // src/phone.ts
5
5
  function validatePhone(phone) {
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ // src/internal/money.ts
4
+ var MAX_AMOUNT = 1e12;
5
+ function toUnits(value, scale) {
6
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
7
+ if (value < 0 || value > MAX_AMOUNT) return null;
8
+ const match = /^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(value));
9
+ if (!match) return null;
10
+ const intPart = match[1];
11
+ const fracPart = match[2] ?? "";
12
+ const exponent = Number(match[3] ?? "0");
13
+ const digits = (intPart + fracPart).replace(/^0+(?=\d)/, "");
14
+ const point = intPart.length + exponent - (intPart + fracPart).length + digits.length;
15
+ const keep = point + scale;
16
+ if (keep <= 0) {
17
+ return keep === 0 && Number(digits[0]) >= 5 ? 1 : 0;
18
+ }
19
+ if (keep >= digits.length) {
20
+ return Number(digits + "0".repeat(keep - digits.length));
21
+ }
22
+ const whole = Number(digits.slice(0, keep));
23
+ return Number(digits[keep]) >= 5 ? whole + 1 : whole;
24
+ }
25
+ function fromPaisa(paisa) {
26
+ return paisa / 100;
27
+ }
28
+ function divideHalfUp(numerator, denominator) {
29
+ const quotient = numerator / denominator;
30
+ const remainder = numerator % denominator;
31
+ return Number(remainder * 2n >= denominator ? quotient + 1n : quotient);
32
+ }
33
+
34
+ // src/internal/date.ts
35
+ var pad = (n, width = 2) => String(n).padStart(width, "0");
36
+ function isoDate(input) {
37
+ if (input instanceof Date) {
38
+ if (Number.isNaN(input.getTime())) return null;
39
+ const year = input.getFullYear();
40
+ if (year < 0 || year > 9999) return null;
41
+ return `${pad(input.getFullYear(), 4)}-${pad(input.getMonth() + 1)}-${pad(input.getDate())}`;
42
+ }
43
+ if (typeof input !== "string") return null;
44
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(input.trim());
45
+ if (!match) return null;
46
+ const [y, m, d] = [Number(match[1]), Number(match[2]), Number(match[3])];
47
+ const leap = y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
48
+ const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
49
+ if (m < 1 || m > 12 || d < 1 || d > days[m - 1]) return null;
50
+ return `${match[1]}-${match[2]}-${match[3]}`;
51
+ }
52
+
53
+ exports.divideHalfUp = divideHalfUp;
54
+ exports.fromPaisa = fromPaisa;
55
+ exports.isoDate = isoDate;
56
+ exports.toUnits = toUnits;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
4
+
5
+ // src/vehicle.ts
6
+ var PLATE = /^([A-Z]{1,4})[-‐‑‒–— ]?(\d{1,4})(?:[-‐‑‒–— /]{1,3}(\d{2}))?$/;
7
+ function parseVehiclePlate(plate) {
8
+ const match = PLATE.exec(chunkVPBMIYO2_cjs.toAsciiDigits(plate.trim()).toUpperCase());
9
+ if (!match) {
10
+ return null;
11
+ }
12
+ const [, series, number, year] = match;
13
+ return {
14
+ series,
15
+ number,
16
+ year: year ?? null,
17
+ formatted: `${series}-${number}`
18
+ };
19
+ }
20
+ function validateVehiclePlate(plate) {
21
+ return parseVehiclePlate(plate) !== null;
22
+ }
23
+
24
+ exports.parseVehiclePlate = parseVehiclePlate;
25
+ exports.validateVehiclePlate = validateVehiclePlate;
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkNTD4JLDW_cjs = require('./chunk-NTD4JLDW.cjs');
3
+ var chunkYTLE5K7G_cjs = require('./chunk-YTLE5K7G.cjs');
4
4
 
5
5
  // src/whatsapp.ts
6
6
  function createWhatsAppLink(phone, message) {
7
- const digits = chunkNTD4JLDW_cjs.normalizePhoneDigits(phone);
7
+ const digits = chunkYTLE5K7G_cjs.normalizePhoneDigits(phone);
8
8
  if (digits === null) {
9
9
  return null;
10
10
  }
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkNTD4JLDW_cjs = require('./chunk-NTD4JLDW.cjs');
3
+ var chunkDHOP7LQX_cjs = require('./chunk-DHOP7LQX.cjs');
4
+ var chunkYTLE5K7G_cjs = require('./chunk-YTLE5K7G.cjs');
4
5
  var chunkHTCSHHOR_cjs = require('./chunk-HTCSHHOR.cjs');
5
- var chunk3IARSCO6_cjs = require('./chunk-3IARSCO6.cjs');
6
6
  var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
7
7
 
8
8
  // src/input.ts
@@ -62,7 +62,7 @@ function checkPhoneInput(value) {
62
62
  const { national } = split;
63
63
  if (national === "") return "incomplete";
64
64
  if (!national.startsWith("3")) return "invalid";
65
- if (national.length >= 3 && !chunkNTD4JLDW_cjs.isAllocatedPrefix(`0${national.slice(0, 3)}`)) {
65
+ if (national.length >= 3 && !chunkYTLE5K7G_cjs.isAllocatedPrefix(`0${national.slice(0, 3)}`)) {
66
66
  return "invalid";
67
67
  }
68
68
  if (national.length < 10) return "incomplete";
@@ -78,7 +78,7 @@ function checkIBANInput(value) {
78
78
  if (clean === "") return "empty";
79
79
  if (clean.length > 24 || !IBAN_SHAPE.test(clean)) return "invalid";
80
80
  if (clean.length < 24) return "incomplete";
81
- return chunk3IARSCO6_cjs.validateIBAN(clean) ? "valid" : "invalid";
81
+ return chunkDHOP7LQX_cjs.validateIBAN(clean) ? "valid" : "invalid";
82
82
  }
83
83
 
84
84
  exports.checkCNICInput = checkCNICInput;
@@ -0,0 +1,168 @@
1
+ import { analyzeNumber } from './chunk-LQHM3ADX.js';
2
+ import { parseAddress } from './chunk-B7DOQ5QF.js';
3
+ import { getPostOffice } from './chunk-33QMFE2Z.js';
4
+ import { normalizeWhitespace, toAsciiDigits } from './chunk-ENQ7O7VW.js';
5
+
6
+ // src/quality.ts
7
+ var ADDRESS_WEIGHTS = {
8
+ city: 30,
9
+ houseNumber: 20,
10
+ street: 15,
11
+ area: 10,
12
+ postalCode: 15,
13
+ landmark: 10
14
+ };
15
+ var UNKNOWN_POSTAL_CODE_POINTS = 5;
16
+ var MISMATCH_PENALTY = 15;
17
+ var LANDMARK_WORDS = [
18
+ "near",
19
+ "nr",
20
+ "opposite",
21
+ "opp",
22
+ "behind",
23
+ "beside",
24
+ "besides",
25
+ "adjacent",
26
+ "next to",
27
+ "in front of",
28
+ "facing",
29
+ "nazd",
30
+ "nazdeek",
31
+ "nazdik",
32
+ "qareeb",
33
+ "qarib",
34
+ "kareeb",
35
+ "samne",
36
+ "saamne",
37
+ "samnay",
38
+ "peeche",
39
+ "peechay",
40
+ "pichay",
41
+ "bil muqabil",
42
+ "bilmuqabil",
43
+ "muttasil",
44
+ "mutasil"
45
+ ];
46
+ var URDU_LANDMARK_WORDS = [
47
+ "\u0646\u0632\u062F",
48
+ "\u0646\u0632\u062F\u06CC\u06A9",
49
+ "\u0642\u0631\u06CC\u0628",
50
+ "\u0633\u0627\u0645\u0646\u06D2",
51
+ "\u067E\u06CC\u0686\u06BE\u06D2",
52
+ "\u0628\u0627\u0644\u0645\u0642\u0627\u0628\u0644",
53
+ "\u0645\u062A\u0635\u0644"
54
+ ];
55
+ var STREET_WORDS = [
56
+ "street",
57
+ "st",
58
+ "road",
59
+ "rd",
60
+ "lane",
61
+ "gali",
62
+ "avenue",
63
+ "ave",
64
+ "boulevard",
65
+ "blvd",
66
+ "chowk",
67
+ "bazar",
68
+ "bazaar",
69
+ "mohalla",
70
+ "muhalla"
71
+ ];
72
+ var URDU_STREET_WORDS = ["\u06AF\u0644\u06CC", "\u0633\u0691\u06A9", "\u0631\u0648\u0688", "\u0645\u062D\u0644\u06C1", "\u0686\u0648\u06A9", "\u0628\u0627\u0632\u0627\u0631"];
73
+ var AREA_WORDS = [
74
+ "block",
75
+ "sector",
76
+ "phase",
77
+ "town",
78
+ "colony",
79
+ "society",
80
+ "scheme",
81
+ "housing",
82
+ "garden",
83
+ "gardens",
84
+ "park",
85
+ "estate",
86
+ "abad",
87
+ "nagar",
88
+ "cantt",
89
+ "cantonment"
90
+ ];
91
+ var URDU_AREA_WORDS = ["\u0628\u0644\u0627\u06A9", "\u0633\u06CC\u06A9\u0679\u0631", "\u0641\u06CC\u0632", "\u0679\u0627\u0624\u0646", "\u06A9\u0627\u0644\u0648\u0646\u06CC", "\u0633\u0648\u0633\u0627\u0626\u0679\u06CC"];
92
+ function words(text) {
93
+ return ` ${toAsciiDigits(text).toLowerCase().replace(/[^a-z0-9؀-ۿ]+/g, " ").trim()} `;
94
+ }
95
+ function hasWord(haystack, list) {
96
+ return list.some((word) => haystack.includes(` ${word} `));
97
+ }
98
+ function hasUrdu(text, list) {
99
+ return list.some((word) => text.includes(word));
100
+ }
101
+ function scoreAddress(input) {
102
+ const text = typeof input === "string" ? normalizeWhitespace(input) : "";
103
+ const parsed = parseAddress(text);
104
+ const found = /* @__PURE__ */ new Set();
105
+ const lowered = words(text);
106
+ const postal = parsed.postalCode;
107
+ const rest = postal === null ? lowered : lowered.replace(` ${postal} `, " ");
108
+ if (parsed.city !== null) found.add("city");
109
+ if (/ \d+[a-z]{0,2} /.test(rest)) {
110
+ found.add("houseNumber");
111
+ }
112
+ if (hasWord(lowered, STREET_WORDS) || hasUrdu(text, URDU_STREET_WORDS)) {
113
+ found.add("street");
114
+ }
115
+ if (parsed.area !== null || hasWord(lowered, AREA_WORDS) || hasUrdu(text, URDU_AREA_WORDS)) {
116
+ found.add("area");
117
+ }
118
+ if (hasWord(lowered, LANDMARK_WORDS) || hasUrdu(text, URDU_LANDMARK_WORDS)) {
119
+ found.add("landmark");
120
+ }
121
+ let score = 0;
122
+ const warnings = [...parsed.warnings];
123
+ for (const part of found) score += ADDRESS_WEIGHTS[part];
124
+ if (postal !== null) {
125
+ const office = getPostOffice(postal);
126
+ if (office === null) {
127
+ score += UNKNOWN_POSTAL_CODE_POINTS;
128
+ } else {
129
+ found.add("postalCode");
130
+ score += ADDRESS_WEIGHTS.postalCode;
131
+ if (parsed.province !== null && office.province !== parsed.province) {
132
+ score -= MISMATCH_PENALTY;
133
+ warnings.push(
134
+ `Postal code ${postal} is in ${office.province}, but the address is in ${parsed.province}`
135
+ );
136
+ }
137
+ }
138
+ }
139
+ const missing = Object.keys(ADDRESS_WEIGHTS).filter(
140
+ (part) => !found.has(part)
141
+ );
142
+ return {
143
+ score: Math.max(0, Math.min(100, score)),
144
+ missing,
145
+ parsed: { ...parsed, warnings }
146
+ };
147
+ }
148
+ var ASCENDING = "01234567890";
149
+ var DESCENDING = "09876543210";
150
+ function phoneRiskSignals(input) {
151
+ const info = typeof input === "string" ? analyzeNumber(input) : null;
152
+ if (info === null) return ["invalid"];
153
+ if (info.type === "landline") return ["landline"];
154
+ if (info.type !== "mobile" || info.e164 === null) return ["not-mobile"];
155
+ const national = info.e164.slice(3);
156
+ const subscriber = national.slice(3);
157
+ const flags = [];
158
+ if (new Set(subscriber).size <= 2) flags.push("repeated-digits");
159
+ if (ASCENDING.includes(subscriber) || DESCENDING.includes(subscriber)) {
160
+ flags.push("sequential-digits");
161
+ }
162
+ if (subscriber === "1234567" || subscriber === "7654321" || national === "3123456789") {
163
+ flags.push("test-number");
164
+ }
165
+ return flags;
166
+ }
167
+
168
+ export { ADDRESS_WEIGHTS, phoneRiskSignals, scoreAddress };