pakdatakit 1.1.0 → 2.1.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/LICENSE +21 -21
- package/README.md +909 -666
- package/dist/address.cjs +17 -0
- package/dist/address.d.cts +36 -0
- package/dist/address.d.ts +36 -0
- package/dist/address.js +4 -0
- package/dist/chunk-3COX5FSL.cjs +1650 -0
- package/dist/chunk-432ZYMYV.js +31 -0
- package/dist/chunk-43ULDYUP.cjs +235 -0
- package/dist/chunk-44YRK7WO.js +231 -0
- package/dist/chunk-4EUKCSLW.js +221 -0
- package/dist/chunk-4VVFS6FN.cjs +715 -0
- package/dist/chunk-6TSKA2PH.js +38 -0
- package/dist/chunk-APXP7OK7.cjs +226 -0
- package/dist/chunk-AUATLZA5.cjs +168 -0
- package/dist/chunk-BSS4Z7NI.cjs +422 -0
- package/dist/chunk-CEPNSHIC.js +33 -0
- package/dist/chunk-CYJJ7KGC.cjs +108 -0
- package/dist/chunk-E47SNBWQ.cjs +224 -0
- package/dist/chunk-E7GAK72W.js +20 -0
- package/dist/chunk-EEVNLTB4.js +32 -0
- package/dist/chunk-ENQ7O7VW.js +32 -0
- package/dist/chunk-H6M6L26S.cjs +37 -0
- package/dist/chunk-HBOZIITD.js +351 -0
- package/dist/chunk-HTCSHHOR.cjs +35 -0
- package/dist/chunk-JKE4AMSZ.js +47 -0
- package/dist/chunk-JNP27XW2.cjs +22 -0
- package/dist/chunk-K6CZFCX6.js +1642 -0
- package/dist/chunk-KEHCTYLO.cjs +52 -0
- package/dist/chunk-KQKW2ZEK.cjs +18 -0
- package/dist/chunk-L2BDDM2W.js +165 -0
- package/dist/chunk-L45UXUWX.js +21 -0
- package/dist/chunk-LIYNKIKS.js +709 -0
- package/dist/chunk-LVHTH4P7.cjs +41 -0
- package/dist/chunk-P4CGOJEM.js +16 -0
- package/dist/chunk-PHHKIMO2.cjs +35 -0
- package/dist/chunk-QQQKISXT.js +223 -0
- package/dist/chunk-T3E4B5MJ.js +417 -0
- package/dist/chunk-VPBMIYO2.cjs +38 -0
- package/dist/chunk-XCXFGTHW.cjs +355 -0
- package/dist/chunk-Y6BUGLXU.js +95 -0
- package/dist/chunk-YLWZGSFY.cjs +99 -0
- package/dist/chunk-YS7MOLK2.cjs +23 -0
- package/dist/chunk-Z5JEIQVW.js +102 -0
- package/dist/cli.js +78 -2654
- package/dist/cnic.cjs +15 -0
- package/dist/cnic.d.cts +35 -0
- package/dist/cnic.d.ts +35 -0
- package/dist/cnic.js +2 -0
- package/dist/format.cjs +14 -0
- package/dist/format.d.cts +27 -0
- package/dist/format.d.ts +27 -0
- package/dist/format.js +1 -0
- package/dist/geo.cjs +27 -0
- package/dist/geo.d.cts +43 -0
- package/dist/geo.d.ts +43 -0
- package/dist/geo.js +2 -0
- package/dist/hijri.cjs +26 -0
- package/dist/hijri.d.cts +62 -0
- package/dist/hijri.d.ts +62 -0
- package/dist/hijri.js +1 -0
- package/dist/holidays.cjs +19 -0
- package/dist/holidays.d.cts +72 -0
- package/dist/holidays.d.ts +72 -0
- package/dist/holidays.js +2 -0
- package/dist/iban.cjs +15 -0
- package/dist/iban.d.cts +21 -0
- package/dist/iban.d.ts +21 -0
- package/dist/iban.js +2 -0
- package/dist/index.cjs +211 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -300
- package/dist/index.js +18 -2764
- package/dist/networks.cjs +12 -0
- package/dist/networks.d.cts +20 -0
- package/dist/networks.d.ts +20 -0
- package/dist/networks.js +3 -0
- package/dist/numbers.cjs +24 -0
- package/dist/numbers.d.cts +53 -0
- package/dist/numbers.d.ts +53 -0
- package/dist/numbers.js +3 -0
- package/dist/phone.cjs +29 -0
- package/dist/phone.d.cts +56 -0
- package/dist/phone.d.ts +56 -0
- package/dist/phone.js +4 -0
- package/dist/postal.cjs +27 -0
- package/dist/postal.d.cts +40 -0
- package/dist/postal.d.ts +40 -0
- package/dist/postal.js +2 -0
- package/dist/raast.cjs +20 -0
- package/dist/raast.d.cts +125 -0
- package/dist/raast.d.ts +125 -0
- package/dist/raast.js +3 -0
- package/dist/rules-GxgPiVws.d.cts +7 -0
- package/dist/rules-GxgPiVws.d.ts +7 -0
- package/dist/tax.cjs +20 -0
- package/dist/tax.d.cts +47 -0
- package/dist/tax.d.ts +47 -0
- package/dist/tax.js +3 -0
- package/dist/text.cjs +23 -0
- package/dist/text.d.cts +34 -0
- package/dist/text.d.ts +34 -0
- package/dist/text.js +2 -0
- package/dist/valibot.cjs +47 -0
- package/dist/valibot.d.cts +22 -0
- package/dist/valibot.d.ts +22 -0
- package/dist/valibot.js +25 -0
- package/dist/whatsapp.cjs +12 -0
- package/dist/whatsapp.d.cts +12 -0
- package/dist/whatsapp.d.ts +12 -0
- package/dist/whatsapp.js +3 -0
- package/dist/words.cjs +14 -0
- package/dist/words.d.cts +49 -0
- package/dist/words.d.ts +49 -0
- package/dist/words.js +1 -0
- package/dist/yup.cjs +32 -0
- package/dist/yup.d.cts +22 -0
- package/dist/yup.d.ts +22 -0
- package/dist/yup.js +30 -0
- package/dist/zod.cjs +27 -0
- package/dist/zod.d.cts +22 -0
- package/dist/zod.d.ts +22 -0
- package/dist/zod.js +25 -0
- package/package.json +309 -77
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/format.ts
|
|
2
|
+
var LAKH = 1e5;
|
|
3
|
+
var CRORE = 1e7;
|
|
4
|
+
var pkrFormatter = new Intl.NumberFormat("en-PK", {
|
|
5
|
+
maximumFractionDigits: 0
|
|
6
|
+
});
|
|
7
|
+
function assertFinite(amount) {
|
|
8
|
+
if (typeof amount !== "number" || !Number.isFinite(amount)) {
|
|
9
|
+
throw new RangeError(
|
|
10
|
+
`Amount must be a finite number, received ${String(amount)}`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function roundTo2(value) {
|
|
15
|
+
return Math.round(value * 100) / 100;
|
|
16
|
+
}
|
|
17
|
+
function formatPKR(amount) {
|
|
18
|
+
assertFinite(amount);
|
|
19
|
+
const rounded = Math.round(Math.abs(amount));
|
|
20
|
+
const sign = amount < 0 && rounded !== 0 ? "-" : "";
|
|
21
|
+
return `${sign}Rs. ${pkrFormatter.format(rounded)}`;
|
|
22
|
+
}
|
|
23
|
+
function formatLakh(amount) {
|
|
24
|
+
assertFinite(amount);
|
|
25
|
+
const sign = amount < 0 ? "-" : "";
|
|
26
|
+
const absolute = Math.abs(amount);
|
|
27
|
+
const crores = roundTo2(absolute / CRORE);
|
|
28
|
+
if (crores >= 1) {
|
|
29
|
+
return `${sign}${crores} Crore`;
|
|
30
|
+
}
|
|
31
|
+
const lakhs = roundTo2(absolute / LAKH);
|
|
32
|
+
if (lakhs >= 1) {
|
|
33
|
+
return `${sign}${lakhs} Lakh`;
|
|
34
|
+
}
|
|
35
|
+
return formatPKR(amount);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { formatLakh, formatPKR };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/words.ts
|
|
4
|
+
var SCALES = [
|
|
5
|
+
{ value: 1e11, en: "kharab", ur: "\u06A9\u06BE\u0631\u0628" },
|
|
6
|
+
{ value: 1e9, en: "arab", ur: "\u0627\u0631\u0628" },
|
|
7
|
+
{ value: 1e7, en: "crore", ur: "\u06A9\u0631\u0648\u0691" },
|
|
8
|
+
{ value: 1e5, en: "lakh", ur: "\u0644\u0627\u06A9\u06BE" },
|
|
9
|
+
{ value: 1e3, en: "thousand", ur: "\u06C1\u0632\u0627\u0631" },
|
|
10
|
+
{ value: 100, en: "hundred", ur: "\u0633\u0648" }
|
|
11
|
+
];
|
|
12
|
+
var EN_ONES = [
|
|
13
|
+
"zero",
|
|
14
|
+
"one",
|
|
15
|
+
"two",
|
|
16
|
+
"three",
|
|
17
|
+
"four",
|
|
18
|
+
"five",
|
|
19
|
+
"six",
|
|
20
|
+
"seven",
|
|
21
|
+
"eight",
|
|
22
|
+
"nine",
|
|
23
|
+
"ten",
|
|
24
|
+
"eleven",
|
|
25
|
+
"twelve",
|
|
26
|
+
"thirteen",
|
|
27
|
+
"fourteen",
|
|
28
|
+
"fifteen",
|
|
29
|
+
"sixteen",
|
|
30
|
+
"seventeen",
|
|
31
|
+
"eighteen",
|
|
32
|
+
"nineteen"
|
|
33
|
+
];
|
|
34
|
+
var EN_TENS = [
|
|
35
|
+
"",
|
|
36
|
+
"",
|
|
37
|
+
"twenty",
|
|
38
|
+
"thirty",
|
|
39
|
+
"forty",
|
|
40
|
+
"fifty",
|
|
41
|
+
"sixty",
|
|
42
|
+
"seventy",
|
|
43
|
+
"eighty",
|
|
44
|
+
"ninety"
|
|
45
|
+
];
|
|
46
|
+
var UR_0_TO_99 = [
|
|
47
|
+
"\u0635\u0641\u0631",
|
|
48
|
+
"\u0627\u06CC\u06A9",
|
|
49
|
+
"\u062F\u0648",
|
|
50
|
+
"\u062A\u06CC\u0646",
|
|
51
|
+
"\u0686\u0627\u0631",
|
|
52
|
+
"\u067E\u0627\u0646\u0686",
|
|
53
|
+
"\u0686\u06BE",
|
|
54
|
+
"\u0633\u0627\u062A",
|
|
55
|
+
"\u0622\u0679\u06BE",
|
|
56
|
+
"\u0646\u0648",
|
|
57
|
+
"\u062F\u0633",
|
|
58
|
+
"\u06AF\u06CC\u0627\u0631\u06C1",
|
|
59
|
+
"\u0628\u0627\u0631\u06C1",
|
|
60
|
+
"\u062A\u06CC\u0631\u06C1",
|
|
61
|
+
"\u0686\u0648\u062F\u06C1",
|
|
62
|
+
"\u067E\u0646\u062F\u0631\u06C1",
|
|
63
|
+
"\u0633\u0648\u0644\u06C1",
|
|
64
|
+
"\u0633\u062A\u0631\u06C1",
|
|
65
|
+
"\u0627\u0679\u06BE\u0627\u0631\u06C1",
|
|
66
|
+
"\u0627\u0646\u06CC\u0633",
|
|
67
|
+
"\u0628\u06CC\u0633",
|
|
68
|
+
"\u0627\u06A9\u06CC\u0633",
|
|
69
|
+
"\u0628\u0627\u0626\u06CC\u0633",
|
|
70
|
+
"\u062A\u0626\u06CC\u0633",
|
|
71
|
+
"\u0686\u0648\u0628\u06CC\u0633",
|
|
72
|
+
"\u067E\u0686\u06CC\u0633",
|
|
73
|
+
"\u0686\u06BE\u0628\u06CC\u0633",
|
|
74
|
+
"\u0633\u062A\u0627\u0626\u06CC\u0633",
|
|
75
|
+
"\u0627\u0679\u06BE\u0627\u0626\u06CC\u0633",
|
|
76
|
+
"\u0627\u0646\u062A\u06CC\u0633",
|
|
77
|
+
"\u062A\u06CC\u0633",
|
|
78
|
+
"\u0627\u06A9\u062A\u06CC\u0633",
|
|
79
|
+
"\u0628\u062A\u06CC\u0633",
|
|
80
|
+
"\u062A\u06CC\u0646\u062A\u06CC\u0633",
|
|
81
|
+
"\u0686\u0648\u0646\u062A\u06CC\u0633",
|
|
82
|
+
"\u067E\u06CC\u0646\u062A\u06CC\u0633",
|
|
83
|
+
"\u0686\u06BE\u062A\u06CC\u0633",
|
|
84
|
+
"\u0633\u06CC\u0646\u062A\u06CC\u0633",
|
|
85
|
+
"\u0627\u0691\u062A\u06CC\u0633",
|
|
86
|
+
"\u0627\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
87
|
+
"\u0686\u0627\u0644\u06CC\u0633",
|
|
88
|
+
"\u0627\u06A9\u062A\u0627\u0644\u06CC\u0633",
|
|
89
|
+
"\u0628\u06CC\u0627\u0644\u06CC\u0633",
|
|
90
|
+
"\u062A\u06CC\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
91
|
+
"\u0686\u0648\u0627\u0644\u06CC\u0633",
|
|
92
|
+
"\u067E\u06CC\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
93
|
+
"\u0686\u06BE\u06CC\u0627\u0644\u06CC\u0633",
|
|
94
|
+
"\u0633\u06CC\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
95
|
+
"\u0627\u0691\u062A\u0627\u0644\u06CC\u0633",
|
|
96
|
+
"\u0627\u0646\u0686\u0627\u0633",
|
|
97
|
+
"\u067E\u0686\u0627\u0633",
|
|
98
|
+
"\u0627\u06A9\u0627\u0648\u0646",
|
|
99
|
+
"\u0628\u0627\u0648\u0646",
|
|
100
|
+
"\u062A\u0631\u067E\u0646",
|
|
101
|
+
"\u0686\u0648\u0646",
|
|
102
|
+
"\u067E\u0686\u067E\u0646",
|
|
103
|
+
"\u0686\u06BE\u067E\u0646",
|
|
104
|
+
"\u0633\u062A\u0627\u0648\u0646",
|
|
105
|
+
"\u0627\u0679\u06BE\u0627\u0648\u0646",
|
|
106
|
+
"\u0627\u0646\u0633\u0679\u06BE",
|
|
107
|
+
"\u0633\u0627\u0679\u06BE",
|
|
108
|
+
"\u0627\u06A9\u0633\u0679\u06BE",
|
|
109
|
+
"\u0628\u0627\u0633\u0679\u06BE",
|
|
110
|
+
"\u062A\u0631\u0633\u0679\u06BE",
|
|
111
|
+
"\u0686\u0648\u0646\u0633\u0679\u06BE",
|
|
112
|
+
"\u067E\u06CC\u0646\u0633\u0679\u06BE",
|
|
113
|
+
"\u0686\u06BE\u06CC\u0627\u0633\u0679\u06BE",
|
|
114
|
+
"\u0633\u0691\u0633\u0679\u06BE",
|
|
115
|
+
"\u0627\u0691\u0633\u0679\u06BE",
|
|
116
|
+
"\u0627\u0646\u06C1\u062A\u0631",
|
|
117
|
+
"\u0633\u062A\u0631",
|
|
118
|
+
"\u0627\u06A9\u06C1\u062A\u0631",
|
|
119
|
+
"\u0628\u06C1\u062A\u0631",
|
|
120
|
+
"\u062A\u06C1\u062A\u0631",
|
|
121
|
+
"\u0686\u0648\u06C1\u062A\u0631",
|
|
122
|
+
"\u067E\u0686\u06BE\u062A\u0631",
|
|
123
|
+
"\u0686\u06BE\u06C1\u062A\u0631",
|
|
124
|
+
"\u0633\u062A\u062A\u0631",
|
|
125
|
+
"\u0627\u0679\u06BE\u06C1\u062A\u0631",
|
|
126
|
+
"\u0627\u0646\u0627\u0633\u06CC",
|
|
127
|
+
"\u0627\u0633\u06CC",
|
|
128
|
+
"\u0627\u06A9\u06CC\u0627\u0633\u06CC",
|
|
129
|
+
"\u0628\u06CC\u0627\u0633\u06CC",
|
|
130
|
+
"\u062A\u0631\u0627\u0633\u06CC",
|
|
131
|
+
"\u0686\u0648\u0631\u0627\u0633\u06CC",
|
|
132
|
+
"\u067E\u0686\u0627\u0633\u06CC",
|
|
133
|
+
"\u0686\u06BE\u06CC\u0627\u0633\u06CC",
|
|
134
|
+
"\u0633\u062A\u0627\u0633\u06CC",
|
|
135
|
+
"\u0627\u0679\u06BE\u0627\u0633\u06CC",
|
|
136
|
+
"\u0646\u0648\u0627\u0633\u06CC",
|
|
137
|
+
"\u0646\u0648\u06D2",
|
|
138
|
+
"\u0627\u06A9\u0627\u0646\u0648\u06D2",
|
|
139
|
+
"\u0628\u0627\u0646\u0648\u06D2",
|
|
140
|
+
"\u062A\u0631\u0627\u0646\u0648\u06D2",
|
|
141
|
+
"\u0686\u0648\u0631\u0627\u0646\u0648\u06D2",
|
|
142
|
+
"\u067E\u0686\u0627\u0646\u0648\u06D2",
|
|
143
|
+
"\u0686\u06BE\u06CC\u0627\u0646\u0648\u06D2",
|
|
144
|
+
"\u0633\u062A\u0627\u0646\u0648\u06D2",
|
|
145
|
+
"\u0627\u0679\u06BE\u0627\u0646\u0648\u06D2",
|
|
146
|
+
"\u0646\u0646\u0627\u0646\u0648\u06D2"
|
|
147
|
+
];
|
|
148
|
+
function underHundred(n, language) {
|
|
149
|
+
if (language === "ur") {
|
|
150
|
+
return UR_0_TO_99[n];
|
|
151
|
+
}
|
|
152
|
+
if (n < 20) {
|
|
153
|
+
return EN_ONES[n];
|
|
154
|
+
}
|
|
155
|
+
const tens = EN_TENS[Math.floor(n / 10)];
|
|
156
|
+
return n % 10 === 0 ? tens : `${tens}-${EN_ONES[n % 10]}`;
|
|
157
|
+
}
|
|
158
|
+
function convert(n, language) {
|
|
159
|
+
for (const scale of SCALES) {
|
|
160
|
+
if (n >= scale.value) {
|
|
161
|
+
const count = Math.floor(n / scale.value);
|
|
162
|
+
const rest = n % scale.value;
|
|
163
|
+
return [
|
|
164
|
+
...convert(count, language),
|
|
165
|
+
scale[language],
|
|
166
|
+
...rest > 0 ? convert(rest, language) : []
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return [underHundred(n, language)];
|
|
171
|
+
}
|
|
172
|
+
function numberToWords(n, options = {}) {
|
|
173
|
+
const language = options.language ?? "en";
|
|
174
|
+
if (!Number.isSafeInteger(n)) {
|
|
175
|
+
throw new RangeError(`Expected a safe integer, received ${String(n)}`);
|
|
176
|
+
}
|
|
177
|
+
if (n === 0) {
|
|
178
|
+
return underHundred(0, language);
|
|
179
|
+
}
|
|
180
|
+
const words = convert(Math.abs(n), language).join(" ");
|
|
181
|
+
if (n > 0) {
|
|
182
|
+
return words;
|
|
183
|
+
}
|
|
184
|
+
return language === "ur" ? `\u0645\u0646\u0641\u06CC ${words}` : `minus ${words}`;
|
|
185
|
+
}
|
|
186
|
+
function titleCase(text) {
|
|
187
|
+
return text.replace(
|
|
188
|
+
/(^|[\s-])([a-z])/g,
|
|
189
|
+
(_, sep, ch) => `${sep}${ch.toUpperCase()}`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
function amountInWords(amount, options = {}) {
|
|
193
|
+
const language = options.language ?? "en";
|
|
194
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
195
|
+
throw new RangeError(
|
|
196
|
+
`Amount must be a finite number of zero or more, received ${String(amount)}`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const totalPaisa = Math.round(amount * 100);
|
|
200
|
+
const rupees = Math.floor(totalPaisa / 100);
|
|
201
|
+
const paisa = totalPaisa % 100;
|
|
202
|
+
const rupeeWords = numberToWords(rupees, { language });
|
|
203
|
+
const paisaWords = paisa > 0 ? numberToWords(paisa, { language }) : null;
|
|
204
|
+
if (language === "ur") {
|
|
205
|
+
let text2 = `${rupeeWords} \u0631\u0648\u067E\u06D2`;
|
|
206
|
+
if (paisaWords !== null) {
|
|
207
|
+
text2 += ` \u0627\u0648\u0631 ${paisaWords} \u067E\u06CC\u0633\u06D2`;
|
|
208
|
+
}
|
|
209
|
+
return options.cheque ? `${text2} \u0635\u0631\u0641` : text2;
|
|
210
|
+
}
|
|
211
|
+
if (options.cheque) {
|
|
212
|
+
const paisaPart = paisaWords !== null ? ` and ${paisaWords} paisa` : "";
|
|
213
|
+
return titleCase(`rupees ${rupeeWords}${paisaPart} only`).replace(
|
|
214
|
+
" And ",
|
|
215
|
+
" and "
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
let text = `${rupeeWords} ${rupees === 1 ? "rupee" : "rupees"}`;
|
|
219
|
+
if (paisaWords !== null) {
|
|
220
|
+
text += ` and ${paisaWords} paisa`;
|
|
221
|
+
}
|
|
222
|
+
return text;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
exports.amountInWords = amountInWords;
|
|
226
|
+
exports.numberToWords = numberToWords;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4VVFS6FN_cjs = require('./chunk-4VVFS6FN.cjs');
|
|
4
|
+
var chunk3COX5FSL_cjs = require('./chunk-3COX5FSL.cjs');
|
|
5
|
+
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
6
|
+
|
|
7
|
+
// src/address.ts
|
|
8
|
+
function byLengthDesc(a, b) {
|
|
9
|
+
return b.length - a.length;
|
|
10
|
+
}
|
|
11
|
+
var cityNames = chunkVPBMIYO2_cjs.lazy(
|
|
12
|
+
() => chunk3COX5FSL_cjs.cities_default.map((entry) => entry.city).sort(byLengthDesc)
|
|
13
|
+
);
|
|
14
|
+
var districtNames = chunkVPBMIYO2_cjs.lazy(
|
|
15
|
+
() => chunk3COX5FSL_cjs.districts_default.map((entry) => entry.district).sort(byLengthDesc)
|
|
16
|
+
);
|
|
17
|
+
var PROVINCES = [
|
|
18
|
+
"Islamabad Capital Territory",
|
|
19
|
+
"Azad Jammu and Kashmir",
|
|
20
|
+
"Gilgit-Baltistan",
|
|
21
|
+
"Khyber Pakhtunkhwa",
|
|
22
|
+
"Balochistan",
|
|
23
|
+
"Punjab",
|
|
24
|
+
"Sindh"
|
|
25
|
+
];
|
|
26
|
+
var NON_POSTAL_PREFIX = /(?:\b(?:p\.?\s*o\.?\s*box|box|house|h\.?\s*no\.?|plot|street|st\.?|flat|shop|office|suite|no\.?)|#)\s*$/i;
|
|
27
|
+
function parseAddress(address) {
|
|
28
|
+
const raw = chunkVPBMIYO2_cjs.normalizeWhitespace(address);
|
|
29
|
+
if (raw.length === 0) {
|
|
30
|
+
return emptyParsedAddress(raw);
|
|
31
|
+
}
|
|
32
|
+
const warnings = [];
|
|
33
|
+
let working = raw;
|
|
34
|
+
const postalMatch = findPostalCode(working);
|
|
35
|
+
const postalCode = postalMatch?.code ?? null;
|
|
36
|
+
if (postalMatch) {
|
|
37
|
+
working = working.slice(0, postalMatch.index) + " " + working.slice(postalMatch.index + postalMatch.code.length);
|
|
38
|
+
}
|
|
39
|
+
const segments = working.split(",").map((part) => chunkVPBMIYO2_cjs.normalizeWhitespace(part)).filter((part) => part.length > 0);
|
|
40
|
+
let province = null;
|
|
41
|
+
let city = null;
|
|
42
|
+
let district = null;
|
|
43
|
+
for (let i = segments.length - 1; i >= 0; i -= 1) {
|
|
44
|
+
const segment = segments[i];
|
|
45
|
+
const matchedProvince = province === null ? matchExact(segment, PROVINCES) : null;
|
|
46
|
+
if (matchedProvince) {
|
|
47
|
+
province = matchedProvince;
|
|
48
|
+
segments[i] = "";
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const matchedCity = city === null ? matchExact(segment, cityNames()) : null;
|
|
52
|
+
if (matchedCity) {
|
|
53
|
+
city = matchedCity;
|
|
54
|
+
segments[i] = "";
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const matchedDistrict = district === null ? matchExact(segment, districtNames()) : null;
|
|
58
|
+
if (matchedDistrict) {
|
|
59
|
+
district = matchedDistrict;
|
|
60
|
+
segments[i] = "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (let i = segments.length - 1; i >= 0; i -= 1) {
|
|
64
|
+
if (province === null) {
|
|
65
|
+
const found = matchTrailing(segments[i], PROVINCES);
|
|
66
|
+
if (found) {
|
|
67
|
+
province = found.match;
|
|
68
|
+
segments[i] = found.rest;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (city === null) {
|
|
72
|
+
const found = matchTrailing(segments[i], cityNames());
|
|
73
|
+
if (found) {
|
|
74
|
+
city = found.match;
|
|
75
|
+
segments[i] = found.rest;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (city === null && district !== null) {
|
|
80
|
+
city = district;
|
|
81
|
+
}
|
|
82
|
+
if (postalCode !== null && city === null) {
|
|
83
|
+
city = chunk4VVFS6FN_cjs.getCityByPostalCode(postalCode);
|
|
84
|
+
}
|
|
85
|
+
const inferredProvince = city !== null ? chunk3COX5FSL_cjs.getProvince(city) ?? chunk3COX5FSL_cjs.getDistrictProvince(city) : district !== null ? chunk3COX5FSL_cjs.getDistrictProvince(district) : null;
|
|
86
|
+
if (province === null) {
|
|
87
|
+
province = inferredProvince;
|
|
88
|
+
} else if (inferredProvince !== null && inferredProvince !== province) {
|
|
89
|
+
warnings.push(
|
|
90
|
+
`${city ?? district} is in ${inferredProvince}, but the address says ${province}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const remaining = segments.filter((part) => part.length > 0);
|
|
94
|
+
const street = remaining[0] ?? null;
|
|
95
|
+
const area = remaining.length > 1 ? remaining.slice(1).join(", ") : null;
|
|
96
|
+
return {
|
|
97
|
+
raw,
|
|
98
|
+
street,
|
|
99
|
+
area,
|
|
100
|
+
city,
|
|
101
|
+
district,
|
|
102
|
+
province,
|
|
103
|
+
postalCode,
|
|
104
|
+
warnings
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function formatAddress(parts) {
|
|
108
|
+
const segments = [
|
|
109
|
+
parts.street,
|
|
110
|
+
parts.area,
|
|
111
|
+
parts.city ?? parts.district,
|
|
112
|
+
parts.province
|
|
113
|
+
].filter(
|
|
114
|
+
(part) => typeof part === "string" && part.length > 0
|
|
115
|
+
);
|
|
116
|
+
let formatted = segments.join(", ");
|
|
117
|
+
if (parts.postalCode) {
|
|
118
|
+
formatted = formatted.length > 0 ? `${formatted} ${parts.postalCode}` : parts.postalCode;
|
|
119
|
+
}
|
|
120
|
+
return formatted.length > 0 ? formatted : parts.raw ?? "";
|
|
121
|
+
}
|
|
122
|
+
function emptyParsedAddress(raw) {
|
|
123
|
+
return {
|
|
124
|
+
raw,
|
|
125
|
+
street: null,
|
|
126
|
+
area: null,
|
|
127
|
+
city: null,
|
|
128
|
+
district: null,
|
|
129
|
+
province: null,
|
|
130
|
+
postalCode: null,
|
|
131
|
+
warnings: []
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function findPostalCode(text) {
|
|
135
|
+
let result = null;
|
|
136
|
+
for (const match of text.matchAll(/(?<![\w#/-])([1-9]\d{4})(?![\w/-])/g)) {
|
|
137
|
+
const before = text.slice(0, match.index);
|
|
138
|
+
if (!NON_POSTAL_PREFIX.test(before)) {
|
|
139
|
+
result = { code: match[1], index: match.index };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
function matchExact(segment, options) {
|
|
145
|
+
const key = chunkVPBMIYO2_cjs.normalizeKey(segment);
|
|
146
|
+
if (key.length === 0) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return options.find((option) => chunkVPBMIYO2_cjs.normalizeKey(option) === key) ?? null;
|
|
150
|
+
}
|
|
151
|
+
function matchTrailing(segment, options) {
|
|
152
|
+
const key = chunkVPBMIYO2_cjs.normalizeKey(segment);
|
|
153
|
+
for (const option of options) {
|
|
154
|
+
const optionKey = chunkVPBMIYO2_cjs.normalizeKey(option);
|
|
155
|
+
if (key.endsWith(` ${optionKey}`)) {
|
|
156
|
+
return {
|
|
157
|
+
match: option,
|
|
158
|
+
rest: chunkVPBMIYO2_cjs.normalizeWhitespace(
|
|
159
|
+
segment.slice(0, segment.length - option.length)
|
|
160
|
+
)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
exports.formatAddress = formatAddress;
|
|
168
|
+
exports.parseAddress = parseAddress;
|