urdu-text-utils 0.3.1 → 0.4.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/CHANGELOG.md +23 -0
- package/README.md +41 -1
- package/dist/index.cjs +367 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +174 -6
- package/dist/index.d.ts +174 -6
- package/dist/index.iife.js +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +359 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -191,8 +191,23 @@ function parseUrduNumber(input) {
|
|
|
191
191
|
if (!/^[+-]?(\d+(\.\d*)?|\.\d+)$/u.test(ascii)) return NaN;
|
|
192
192
|
return Number(ascii);
|
|
193
193
|
}
|
|
194
|
-
var
|
|
195
|
-
|
|
194
|
+
var SEPARATORS = {
|
|
195
|
+
urdu: { group: "\u066C", decimal: "\u066B" },
|
|
196
|
+
english: { group: ",", decimal: "." }
|
|
197
|
+
};
|
|
198
|
+
var URDU_ONES = [
|
|
199
|
+
"",
|
|
200
|
+
"\u0627\u06CC\u06A9",
|
|
201
|
+
"\u062F\u0648",
|
|
202
|
+
"\u062A\u06CC\u0646",
|
|
203
|
+
"\u0686\u0627\u0631",
|
|
204
|
+
"\u067E\u0627\u0646\u0686",
|
|
205
|
+
"\u0686\u06BE",
|
|
206
|
+
"\u0633\u0627\u062A",
|
|
207
|
+
"\u0622\u0679\u06BE",
|
|
208
|
+
"\u0646\u0648"
|
|
209
|
+
];
|
|
210
|
+
var URDU_TEENS_AND_TENS = {
|
|
196
211
|
10: "\u062F\u0633",
|
|
197
212
|
11: "\u06AF\u06CC\u0627\u0631\u06C1",
|
|
198
213
|
12: "\u0628\u0627\u0631\u06C1",
|
|
@@ -213,20 +228,104 @@ var TEENS_AND_TENS = {
|
|
|
213
228
|
90: "\u0646\u0648\u06D2",
|
|
214
229
|
100: "\u0633\u0648"
|
|
215
230
|
};
|
|
231
|
+
var URDU_TENS_UNITS = {
|
|
232
|
+
21: "\u0627\u06A9\u06CC\u0633",
|
|
233
|
+
22: "\u0628\u0627\u0626\u06CC\u0633",
|
|
234
|
+
23: "\u062A\u0626\u06CC\u0633",
|
|
235
|
+
24: "\u0686\u0648\u0628\u06CC\u0633",
|
|
236
|
+
25: "\u067E\u0686\u06CC\u0633",
|
|
237
|
+
26: "\u0686\u06BE\u0628\u06CC\u0633",
|
|
238
|
+
27: "\u0633\u062A\u0627\u0626\u06CC\u0633",
|
|
239
|
+
28: "\u0627\u0679\u06BE\u0627\u0626\u06CC\u0633",
|
|
240
|
+
29: "\u0627\u0646\u062A\u06CC\u0633",
|
|
241
|
+
31: "\u0627\u06A9\u062A\u06CC\u0633",
|
|
242
|
+
32: "\u0628\u062A\u06CC\u0633",
|
|
243
|
+
33: "\u062A\u06CC\u0646\u062A\u06CC\u0633",
|
|
244
|
+
34: "\u0686\u0648\u0646\u062A\u06CC\u0633",
|
|
245
|
+
35: "\u067E\u06CC\u0646\u062A\u06CC\u0633",
|
|
246
|
+
36: "\u0686\u06BE\u062A\u06CC\u0633",
|
|
247
|
+
37: "\u0633\u06CC\u0646\u062A\u06CC\u0633",
|
|
248
|
+
38: "\u0627\u0691\u062A\u06CC\u0633",
|
|
249
|
+
39: "\u0627\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
250
|
+
41: "\u0627\u06A9\u062A\u0627\u0644\u06CC\u0633",
|
|
251
|
+
42: "\u0628\u06CC\u0627\u0644\u06CC\u0633",
|
|
252
|
+
43: "\u062A\u06CC\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
253
|
+
44: "\u0686\u0648\u0627\u0644\u06CC\u0633",
|
|
254
|
+
45: "\u067E\u06CC\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
255
|
+
46: "\u0686\u06BE\u06CC\u0627\u0644\u06CC\u0633",
|
|
256
|
+
47: "\u0633\u06CC\u0646\u062A\u0627\u0644\u06CC\u0633",
|
|
257
|
+
48: "\u0627\u0691\u062A\u0627\u0644\u06CC\u0633",
|
|
258
|
+
49: "\u0627\u0646\u0686\u0627\u0633",
|
|
259
|
+
51: "\u0627\u06A9\u06CC\u0627\u0648\u0646",
|
|
260
|
+
52: "\u0628\u0627\u0648\u0646",
|
|
261
|
+
53: "\u062A\u0631\u067E\u0646",
|
|
262
|
+
54: "\u0686\u0648\u0646",
|
|
263
|
+
55: "\u067E\u0686\u067E\u0646",
|
|
264
|
+
56: "\u0686\u06BE\u067E\u0646",
|
|
265
|
+
57: "\u0633\u062A\u0627\u0648\u0646",
|
|
266
|
+
58: "\u0627\u0679\u06BE\u0627\u0648\u0646",
|
|
267
|
+
59: "\u0627\u0646\u0633\u0679\u06BE",
|
|
268
|
+
61: "\u0627\u06A9\u0633\u0679\u06BE",
|
|
269
|
+
62: "\u0628\u0627\u0633\u0679\u06BE",
|
|
270
|
+
63: "\u062A\u0631\u0633\u0679\u06BE",
|
|
271
|
+
64: "\u0686\u0648\u0646\u0633\u0679\u06BE",
|
|
272
|
+
65: "\u067E\u06CC\u0646\u0633\u0679\u06BE",
|
|
273
|
+
66: "\u0686\u06BE\u06CC\u0627\u0633\u0679\u06BE",
|
|
274
|
+
67: "\u0633\u0691\u0633\u0679\u06BE",
|
|
275
|
+
68: "\u0627\u0691\u0633\u0679\u06BE",
|
|
276
|
+
69: "\u0627\u0646\u06C1\u062A\u0631",
|
|
277
|
+
71: "\u0627\u06A9\u06C1\u062A\u0631",
|
|
278
|
+
72: "\u0628\u06C1\u062A\u0631",
|
|
279
|
+
73: "\u062A\u06C1\u062A\u0631",
|
|
280
|
+
74: "\u0686\u0648\u06C1\u062A\u0631",
|
|
281
|
+
75: "\u067E\u0686\u06C1\u062A\u0631",
|
|
282
|
+
76: "\u0686\u06BE\u06C1\u062A\u0631",
|
|
283
|
+
77: "\u0633\u062A\u062A\u0631",
|
|
284
|
+
78: "\u0627\u0679\u06BE\u06C1\u062A\u0631",
|
|
285
|
+
79: "\u0627\u0646\u0627\u0633\u06CC",
|
|
286
|
+
81: "\u0627\u06A9\u06CC\u0627\u0633\u06CC",
|
|
287
|
+
82: "\u0628\u06CC\u0627\u0633\u06CC",
|
|
288
|
+
83: "\u062A\u0631\u0627\u0633\u06CC",
|
|
289
|
+
84: "\u0686\u0648\u0631\u0627\u0633\u06CC",
|
|
290
|
+
85: "\u067E\u0686\u0627\u0633\u06CC",
|
|
291
|
+
86: "\u0686\u06BE\u06CC\u0627\u0633\u06CC",
|
|
292
|
+
87: "\u0633\u062A\u0627\u0633\u06CC",
|
|
293
|
+
88: "\u0627\u0679\u06BE\u0627\u0633\u06CC",
|
|
294
|
+
89: "\u0646\u0648\u0627\u0633\u06CC",
|
|
295
|
+
91: "\u0627\u06A9\u0627\u0646\u0648\u06D2",
|
|
296
|
+
92: "\u0628\u0627\u0646\u0648\u06D2",
|
|
297
|
+
93: "\u062A\u0631\u0627\u0646\u0648\u06D2",
|
|
298
|
+
94: "\u0686\u0648\u0631\u0627\u0646\u0648\u06D2",
|
|
299
|
+
95: "\u067E\u0686\u0627\u0646\u0648\u06D2",
|
|
300
|
+
96: "\u0686\u06BE\u06CC\u0627\u0646\u0648\u06D2",
|
|
301
|
+
97: "\u0633\u062A\u0627\u0646\u0648\u06D2",
|
|
302
|
+
98: "\u0627\u0679\u06BE\u0627\u0646\u0648\u06D2",
|
|
303
|
+
99: "\u0646\u0627\u0646\u0648\u06D2"
|
|
304
|
+
};
|
|
305
|
+
var URDU_SCALES = [
|
|
306
|
+
[1e11, "\u06A9\u06BE\u0631\u0628"],
|
|
307
|
+
[1e9, "\u0627\u0631\u0628"],
|
|
308
|
+
[1e7, "\u06A9\u0631\u0648\u0691"],
|
|
309
|
+
[1e5, "\u0644\u0627\u06A9\u06BE"],
|
|
310
|
+
[1e3, "\u06C1\u0632\u0627\u0631"],
|
|
311
|
+
[100, "\u0633\u0648"]
|
|
312
|
+
];
|
|
313
|
+
var URDU_ORDINAL_IRREGULARS = {
|
|
314
|
+
1: { masculine: "\u067E\u06C1\u0644\u0627", feminine: "\u067E\u06C1\u0644\u06CC" },
|
|
315
|
+
2: { masculine: "\u062F\u0648\u0633\u0631\u0627", feminine: "\u062F\u0648\u0633\u0631\u06CC" },
|
|
316
|
+
3: { masculine: "\u062A\u06CC\u0633\u0631\u0627", feminine: "\u062A\u06CC\u0633\u0631\u06CC" },
|
|
317
|
+
4: { masculine: "\u0686\u0648\u062A\u06BE\u0627", feminine: "\u0686\u0648\u062A\u06BE\u06CC" },
|
|
318
|
+
5: { masculine: "\u067E\u0627\u0646\u0686\u0648\u0627\u06BA", feminine: "\u067E\u0627\u0646\u0686\u0648\u06CC\u06BA" },
|
|
319
|
+
6: { masculine: "\u0686\u06BE\u0679\u0627", feminine: "\u0686\u06BE\u0679\u06CC" }
|
|
320
|
+
};
|
|
216
321
|
function numberToUrduWords(value) {
|
|
217
322
|
if (!Number.isFinite(value)) return "";
|
|
218
323
|
if (!Number.isInteger(value)) throw new TypeError("numberToUrduWords expects an integer");
|
|
219
324
|
if (value < 0) return `\u0645\u0646\u0641\u06CC ${numberToUrduWords(-value)}`;
|
|
220
325
|
if (value === 0) return "\u0635\u0641\u0631";
|
|
221
|
-
const scales = [
|
|
222
|
-
[1e7, "\u06A9\u0631\u0648\u0691"],
|
|
223
|
-
[1e5, "\u0644\u0627\u06A9\u06BE"],
|
|
224
|
-
[1e3, "\u06C1\u0632\u0627\u0631"],
|
|
225
|
-
[100, "\u0633\u0648"]
|
|
226
|
-
];
|
|
227
326
|
const parts = [];
|
|
228
327
|
let rest = value;
|
|
229
|
-
for (const [size, name] of
|
|
328
|
+
for (const [size, name] of URDU_SCALES) {
|
|
230
329
|
if (rest >= size) {
|
|
231
330
|
const count = Math.floor(rest / size);
|
|
232
331
|
rest %= size;
|
|
@@ -234,17 +333,83 @@ function numberToUrduWords(value) {
|
|
|
234
333
|
}
|
|
235
334
|
}
|
|
236
335
|
if (rest > 0) {
|
|
237
|
-
|
|
238
|
-
|
|
336
|
+
const irregular = URDU_TENS_UNITS[rest];
|
|
337
|
+
if (irregular !== void 0) {
|
|
338
|
+
parts.push(irregular);
|
|
339
|
+
} else if (URDU_TEENS_AND_TENS[rest]) {
|
|
340
|
+
parts.push(URDU_TEENS_AND_TENS[rest]);
|
|
239
341
|
} else if (rest < 10) {
|
|
240
|
-
parts.push(
|
|
342
|
+
parts.push(URDU_ONES[rest]);
|
|
241
343
|
} else {
|
|
242
344
|
const tens = Math.floor(rest / 10) * 10;
|
|
243
|
-
parts.push(`${
|
|
345
|
+
parts.push(`${URDU_TEENS_AND_TENS[tens] ?? ""} ${URDU_ONES[rest % 10] ?? ""}`.trim());
|
|
244
346
|
}
|
|
245
347
|
}
|
|
246
348
|
return parts.join(" ").replace(/\s+/gu, " ").trim();
|
|
247
349
|
}
|
|
350
|
+
function toDigitString(n) {
|
|
351
|
+
const plain = String(n);
|
|
352
|
+
const exponential = /^(\d)(?:\.(\d+))?e\+(\d+)$/u.exec(plain);
|
|
353
|
+
if (!exponential) return plain;
|
|
354
|
+
const lead = exponential[1];
|
|
355
|
+
const fraction = exponential[2] ?? "";
|
|
356
|
+
const zeros = Number(exponential[3]) - fraction.length;
|
|
357
|
+
return `${lead}${fraction}${"0".repeat(zeros)}`;
|
|
358
|
+
}
|
|
359
|
+
function groupDigits(intStr, grouping, separator) {
|
|
360
|
+
if (grouping === "none" || separator === "") return intStr;
|
|
361
|
+
if (grouping === "western") {
|
|
362
|
+
return intStr.replace(/\B(?=(\d{3})+(?!\d))/gu, separator);
|
|
363
|
+
}
|
|
364
|
+
const lastThree = intStr.slice(-3);
|
|
365
|
+
const rest = intStr.slice(0, -3);
|
|
366
|
+
return rest === "" ? lastThree : `${rest.replace(/\B(?=(\d{2})+(?!\d))/gu, separator)}${separator}${lastThree}`;
|
|
367
|
+
}
|
|
368
|
+
function formatUrduNumber(value, options = {}) {
|
|
369
|
+
if (!Number.isFinite(value)) return "";
|
|
370
|
+
const digits = options.digits ?? "urdu";
|
|
371
|
+
const grouping = options.grouping ?? "southAsian";
|
|
372
|
+
const decimals = Math.min(15, Math.max(0, Math.floor(options.decimals ?? 2)));
|
|
373
|
+
const separators = SEPARATORS[digits];
|
|
374
|
+
const negative = value < 0;
|
|
375
|
+
const abs = Math.abs(value);
|
|
376
|
+
const scale = 10 ** decimals;
|
|
377
|
+
let intPart = Math.floor(abs);
|
|
378
|
+
let scaledFraction = Math.floor((abs - intPart) * scale + 0.5);
|
|
379
|
+
if (scaledFraction >= scale) {
|
|
380
|
+
intPart += 1;
|
|
381
|
+
scaledFraction -= scale;
|
|
382
|
+
}
|
|
383
|
+
const intStr = groupDigits(toDigitString(intPart), grouping, separators.group);
|
|
384
|
+
const fraction = String(scaledFraction).padStart(decimals, "0").replace(/0+$/u, "");
|
|
385
|
+
const body = fraction === "" ? intStr : `${intStr}${separators.decimal}${fraction}`;
|
|
386
|
+
const sign = negative ? "-" : "";
|
|
387
|
+
return digits === "urdu" ? `${sign}${toUrduDigits(body)}` : `${sign}${body}`;
|
|
388
|
+
}
|
|
389
|
+
function formatUrduCurrency(value, options = {}) {
|
|
390
|
+
if (!Number.isFinite(value)) return "";
|
|
391
|
+
const style = options.style ?? "digits";
|
|
392
|
+
const unit = options.unit ?? "\u0631\u0648\u067E\u06D2";
|
|
393
|
+
const singularUnit = options.singularUnit ?? "\u0631\u0648\u067E\u06CC\u06C1";
|
|
394
|
+
const amount = style === "words" ? numberToUrduWords(value) : formatUrduNumber(value, options);
|
|
395
|
+
if (amount === "") return "";
|
|
396
|
+
return `${amount} ${Math.abs(value) === 1 ? singularUnit : unit}`;
|
|
397
|
+
}
|
|
398
|
+
function toUrduOrdinal(value, options = {}) {
|
|
399
|
+
if (!Number.isFinite(value)) return "";
|
|
400
|
+
if (!Number.isInteger(value)) throw new TypeError("toUrduOrdinal expects an integer");
|
|
401
|
+
const gender = options.gender ?? "masculine";
|
|
402
|
+
if (value < 0) return `\u0645\u0646\u0641\u06CC ${toUrduOrdinal(-value, options)}`;
|
|
403
|
+
if (value === 0) return "\u0635\u0641\u0631";
|
|
404
|
+
const irregular = URDU_ORDINAL_IRREGULARS[value];
|
|
405
|
+
if (irregular) return irregular[gender];
|
|
406
|
+
const words = numberToUrduWords(value).split(" ");
|
|
407
|
+
const last = words.pop();
|
|
408
|
+
const stem = last.endsWith("\u0648") ? last.slice(0, -1) : last;
|
|
409
|
+
const ordinated = `${stem}${gender === "feminine" ? "\u0648\u06CC\u06BA" : "\u0648\u0627\u06BA"}`;
|
|
410
|
+
const prefix = words.length === 1 && words[0] === "\u0627\u06CC\u06A9" ? [] : words;
|
|
411
|
+
return [...prefix, ordinated].join(" ");
|
|
412
|
+
}
|
|
248
413
|
|
|
249
414
|
// src/detect.ts
|
|
250
415
|
function urduRatio(input) {
|
|
@@ -4076,6 +4241,186 @@ function timeAgoUrdu(date, relativeTo = /* @__PURE__ */ new Date(), options = {}
|
|
|
4076
4241
|
if (!addSuffix) return `${count} \u0633\u0627\u0644`;
|
|
4077
4242
|
return isPast ? `${count} \u0633\u0627\u0644 \u067E\u06C1\u0644\u06D2` : `${count} \u0633\u0627\u0644 \u0628\u0639\u062F`;
|
|
4078
4243
|
}
|
|
4244
|
+
var ENGLISH_MONTH_NAMES = [
|
|
4245
|
+
"january",
|
|
4246
|
+
"february",
|
|
4247
|
+
"march",
|
|
4248
|
+
"april",
|
|
4249
|
+
"may",
|
|
4250
|
+
"june",
|
|
4251
|
+
"july",
|
|
4252
|
+
"august",
|
|
4253
|
+
"september",
|
|
4254
|
+
"october",
|
|
4255
|
+
"november",
|
|
4256
|
+
"december"
|
|
4257
|
+
];
|
|
4258
|
+
var ENGLISH_WEEKDAY_NAMES = [
|
|
4259
|
+
"sunday",
|
|
4260
|
+
"monday",
|
|
4261
|
+
"tuesday",
|
|
4262
|
+
"wednesday",
|
|
4263
|
+
"thursday",
|
|
4264
|
+
"friday",
|
|
4265
|
+
"saturday"
|
|
4266
|
+
];
|
|
4267
|
+
var MONTH_LOOKUP = (() => {
|
|
4268
|
+
const lookup = /* @__PURE__ */ Object.create(null);
|
|
4269
|
+
URDU_MONTHS_GREGORIAN.forEach((name, index) => {
|
|
4270
|
+
lookup[name] = index;
|
|
4271
|
+
});
|
|
4272
|
+
ENGLISH_MONTH_NAMES.forEach((name, index) => {
|
|
4273
|
+
lookup[name] = index;
|
|
4274
|
+
lookup[name.slice(0, 3)] = index;
|
|
4275
|
+
});
|
|
4276
|
+
return lookup;
|
|
4277
|
+
})();
|
|
4278
|
+
var WEEKDAY_TOKENS = /* @__PURE__ */ new Set();
|
|
4279
|
+
for (const name of URDU_WEEKDAYS) WEEKDAY_TOKENS.add(name);
|
|
4280
|
+
for (const name of ENGLISH_WEEKDAY_NAMES) {
|
|
4281
|
+
WEEKDAY_TOKENS.add(name);
|
|
4282
|
+
WEEKDAY_TOKENS.add(name.slice(0, 3));
|
|
4283
|
+
}
|
|
4284
|
+
var URDU_PERIODS = Object.assign(
|
|
4285
|
+
/* @__PURE__ */ Object.create(null),
|
|
4286
|
+
{
|
|
4287
|
+
\u0635\u0628\u062D: "morning",
|
|
4288
|
+
\u062F\u0648\u067E\u06C1\u0631: "afternoon",
|
|
4289
|
+
\u0634\u0627\u0645: "evening",
|
|
4290
|
+
\u0631\u0627\u062A: "night"
|
|
4291
|
+
}
|
|
4292
|
+
);
|
|
4293
|
+
function resolveHour(hour, period) {
|
|
4294
|
+
switch (period) {
|
|
4295
|
+
case "am":
|
|
4296
|
+
case "morning":
|
|
4297
|
+
return hour === 12 ? 0 : hour;
|
|
4298
|
+
case "pm":
|
|
4299
|
+
case "afternoon":
|
|
4300
|
+
case "evening":
|
|
4301
|
+
return hour < 12 ? hour + 12 : hour;
|
|
4302
|
+
case "night":
|
|
4303
|
+
if (hour === 12) return 0;
|
|
4304
|
+
return hour >= 8 && hour <= 11 ? hour + 12 : hour;
|
|
4305
|
+
default:
|
|
4306
|
+
return hour;
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
function buildLocalDate(year, month, day, hour, minute, second) {
|
|
4310
|
+
if (!Number.isInteger(year) || year < 100) return null;
|
|
4311
|
+
if (!Number.isInteger(month) || month < 0 || month > 11) return null;
|
|
4312
|
+
if (!Number.isInteger(day) || day < 1 || day > 31) return null;
|
|
4313
|
+
if (!Number.isInteger(hour) || hour < 0 || hour > 23) return null;
|
|
4314
|
+
if (!Number.isInteger(minute) || minute < 0 || minute > 59) return null;
|
|
4315
|
+
if (!Number.isInteger(second) || second < 0 || second > 59) return null;
|
|
4316
|
+
const date = new Date(year, month, day, hour, minute, second);
|
|
4317
|
+
if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day || date.getHours() !== hour) {
|
|
4318
|
+
return null;
|
|
4319
|
+
}
|
|
4320
|
+
return date;
|
|
4321
|
+
}
|
|
4322
|
+
function expandYear(year) {
|
|
4323
|
+
if (year >= 100) return year;
|
|
4324
|
+
return year < 70 ? 2e3 + year : 1900 + year;
|
|
4325
|
+
}
|
|
4326
|
+
var INVISIBLE_CHARS_RE = /[\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/gu;
|
|
4327
|
+
function parseNumericDate(input) {
|
|
4328
|
+
const iso = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[T ](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/u.exec(input);
|
|
4329
|
+
if (iso) {
|
|
4330
|
+
return buildLocalDate(
|
|
4331
|
+
Number(iso[1]),
|
|
4332
|
+
Number(iso[2]) - 1,
|
|
4333
|
+
Number(iso[3]),
|
|
4334
|
+
iso[4] === void 0 ? 0 : Number(iso[4]),
|
|
4335
|
+
iso[5] === void 0 ? 0 : Number(iso[5]),
|
|
4336
|
+
iso[6] === void 0 ? 0 : Number(iso[6])
|
|
4337
|
+
);
|
|
4338
|
+
}
|
|
4339
|
+
const dayFirst = /^(\d{1,2})[/\-.](\d{1,2})[/\-.](\d{2,4})(?:[ ,T]+(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/u.exec(input);
|
|
4340
|
+
if (dayFirst) {
|
|
4341
|
+
return buildLocalDate(
|
|
4342
|
+
expandYear(Number(dayFirst[3])),
|
|
4343
|
+
Number(dayFirst[2]) - 1,
|
|
4344
|
+
Number(dayFirst[1]),
|
|
4345
|
+
dayFirst[4] === void 0 ? 0 : Number(dayFirst[4]),
|
|
4346
|
+
dayFirst[5] === void 0 ? 0 : Number(dayFirst[5]),
|
|
4347
|
+
dayFirst[6] === void 0 ? 0 : Number(dayFirst[6])
|
|
4348
|
+
);
|
|
4349
|
+
}
|
|
4350
|
+
return null;
|
|
4351
|
+
}
|
|
4352
|
+
function parseUrduDate(input, options = {}) {
|
|
4353
|
+
if (!input) return null;
|
|
4354
|
+
const normalized = toEnglishDigits(input).replace(INVISIBLE_CHARS_RE, "").replace(/[،۔]/gu, " ").replace(/\s+/gu, " ").trim();
|
|
4355
|
+
if (normalized === "") return null;
|
|
4356
|
+
const numeric = parseNumericDate(normalized);
|
|
4357
|
+
if (numeric) return numeric;
|
|
4358
|
+
let month = null;
|
|
4359
|
+
let hour = null;
|
|
4360
|
+
let minute = 0;
|
|
4361
|
+
let second = 0;
|
|
4362
|
+
let period;
|
|
4363
|
+
const numbers = [];
|
|
4364
|
+
for (const rawToken of normalized.split(" ")) {
|
|
4365
|
+
const token = rawToken.replace(/^[^\p{L}\p{N}]+/u, "").replace(/[^\p{L}\p{N}]+$/u, "");
|
|
4366
|
+
if (token === "") continue;
|
|
4367
|
+
const urduPeriod = URDU_PERIODS[token];
|
|
4368
|
+
if (urduPeriod) {
|
|
4369
|
+
period = urduPeriod;
|
|
4370
|
+
continue;
|
|
4371
|
+
}
|
|
4372
|
+
const lower = token.toLowerCase();
|
|
4373
|
+
if (lower === "am" || lower === "pm") {
|
|
4374
|
+
period = lower;
|
|
4375
|
+
continue;
|
|
4376
|
+
}
|
|
4377
|
+
if (WEEKDAY_TOKENS.has(token) || WEEKDAY_TOKENS.has(lower)) continue;
|
|
4378
|
+
const time = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/u.exec(token);
|
|
4379
|
+
if (time) {
|
|
4380
|
+
hour = Number(time[1]);
|
|
4381
|
+
minute = Number(time[2]);
|
|
4382
|
+
second = time[3] === void 0 ? 0 : Number(time[3]);
|
|
4383
|
+
continue;
|
|
4384
|
+
}
|
|
4385
|
+
const monthIndex = MONTH_LOOKUP[token] ?? MONTH_LOOKUP[lower];
|
|
4386
|
+
if (monthIndex !== void 0) {
|
|
4387
|
+
month = monthIndex;
|
|
4388
|
+
continue;
|
|
4389
|
+
}
|
|
4390
|
+
if (/^\d+$/u.test(token)) numbers.push(Number(token));
|
|
4391
|
+
}
|
|
4392
|
+
if (month === null || numbers.length === 0) return null;
|
|
4393
|
+
let day;
|
|
4394
|
+
let year;
|
|
4395
|
+
if (numbers.length === 1) {
|
|
4396
|
+
const only = numbers[0];
|
|
4397
|
+
if (only > 31) {
|
|
4398
|
+
day = 1;
|
|
4399
|
+
year = only;
|
|
4400
|
+
} else {
|
|
4401
|
+
day = only;
|
|
4402
|
+
year = options.defaultYear ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
4403
|
+
}
|
|
4404
|
+
} else {
|
|
4405
|
+
const first = numbers[0];
|
|
4406
|
+
const last = numbers[numbers.length - 1];
|
|
4407
|
+
if (first > 31 && last <= 31) {
|
|
4408
|
+
day = last;
|
|
4409
|
+
year = first;
|
|
4410
|
+
} else {
|
|
4411
|
+
day = first;
|
|
4412
|
+
year = last;
|
|
4413
|
+
}
|
|
4414
|
+
}
|
|
4415
|
+
return buildLocalDate(
|
|
4416
|
+
expandYear(year),
|
|
4417
|
+
month,
|
|
4418
|
+
day,
|
|
4419
|
+
hour === null ? 0 : resolveHour(hour, period),
|
|
4420
|
+
minute,
|
|
4421
|
+
second
|
|
4422
|
+
);
|
|
4423
|
+
}
|
|
4079
4424
|
|
|
4080
4425
|
// src/stemmer.ts
|
|
4081
4426
|
var URDU_PREFIXES = [
|
|
@@ -4710,6 +5055,6 @@ function extractNameParts(fullName) {
|
|
|
4710
5055
|
return { honorific, firstName, familyName, suffix };
|
|
4711
5056
|
}
|
|
4712
5057
|
|
|
4713
|
-
export { ENGLISH_NAME_ALIASES, HONORIFICS, NAME_PREFIXES, PROTECTED_WORDS, SENTENCE_ABBREVIATIONS, URDU_FAMILY_NAMES, URDU_FIRST_NAMES, URDU_MONTHS_GREGORIAN, URDU_MONTHS_HIJRI, URDU_PREFIXES, URDU_STOP_WORDS, URDU_SUFFIXES, URDU_WEEKDAYS, analyzeUrdu, compareUrdu, convertNumbers, countSentences, countWords, editDistance, extractNameParts, filterStopWords, foldUrdu, formatUrduDate, getAffixes, getUrduMonthName, getUrduWeekdayName, hasUrduSpecificLetters, highlightUrdu, isStopWord, isUrdu, normalizeUrdu, numberToUrduWords, parseUrduNumber, removeDiacritics, removeStopWords, romanToUrdu, romanize, searchUrdu, searchUrduRanked, sortUrdu, splitSentences, splitWords, stemUrdu, stemUrduText, timeAgoUrdu, toArabicIndicDigits, toEnglishDigits, toUrduDigits, transliterateNameToEnglish, transliterateNameToUrdu, urduRatio, urduSlug };
|
|
5058
|
+
export { ENGLISH_NAME_ALIASES, HONORIFICS, NAME_PREFIXES, PROTECTED_WORDS, SENTENCE_ABBREVIATIONS, URDU_FAMILY_NAMES, URDU_FIRST_NAMES, URDU_MONTHS_GREGORIAN, URDU_MONTHS_HIJRI, URDU_ONES, URDU_ORDINAL_IRREGULARS, URDU_PREFIXES, URDU_SCALES, URDU_STOP_WORDS, URDU_SUFFIXES, URDU_TEENS_AND_TENS, URDU_TENS_UNITS, URDU_WEEKDAYS, analyzeUrdu, compareUrdu, convertNumbers, countSentences, countWords, editDistance, extractNameParts, filterStopWords, foldUrdu, formatUrduCurrency, formatUrduDate, formatUrduNumber, getAffixes, getUrduMonthName, getUrduWeekdayName, hasUrduSpecificLetters, highlightUrdu, isStopWord, isUrdu, normalizeUrdu, numberToUrduWords, parseUrduDate, parseUrduNumber, removeDiacritics, removeStopWords, romanToUrdu, romanize, searchUrdu, searchUrduRanked, sortUrdu, splitSentences, splitWords, stemUrdu, stemUrduText, timeAgoUrdu, toArabicIndicDigits, toEnglishDigits, toUrduDigits, toUrduOrdinal, transliterateNameToEnglish, transliterateNameToUrdu, urduRatio, urduSlug };
|
|
4714
5059
|
//# sourceMappingURL=index.js.map
|
|
4715
5060
|
//# sourceMappingURL=index.js.map
|