pakdatakit 1.0.2 → 1.1.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/dist/index.js CHANGED
@@ -2456,10 +2456,309 @@ function searchPostalCodes(query) {
2456
2456
  }).map((entry) => entry.postalCode);
2457
2457
  return [...new Set(matches)].sort((a, b) => a.localeCompare(b));
2458
2458
  }
2459
+ function getPostalAreas(city) {
2460
+ const key = normalizeKey(city);
2461
+ if (key.length === 0) {
2462
+ return [];
2463
+ }
2464
+ return POSTAL_ENTRIES.filter(
2465
+ (entry) => normalizeKey(entry.city) === key && entry.area
2466
+ ).map((entry) => entry.area).sort((a, b) => a.localeCompare(b));
2467
+ }
2459
2468
  function stripPostalCode(postalCode) {
2460
2469
  return postalCode.trim().replace(/\s+/g, "");
2461
2470
  }
2462
2471
 
2463
- export { analyzePhone, createWhatsAppLink, formatLakh, formatPKR, formatPhone, getBankFromIBAN, getCityByPostalCode, getDistrictProvince, getDistrictsByProvince, getNetwork, getPostalCode, getPostalCodes, getProvince, searchCities, searchDistricts, searchPostalCodes, validateCNIC, validateIBAN, validatePhone };
2472
+ // src/address.ts
2473
+ var CITY_NAMES = cities_default.map((entry) => entry.city).sort((a, b) => b.length - a.length);
2474
+ var DISTRICT_NAMES = districts_default.map((entry) => entry.district).sort((a, b) => b.length - a.length);
2475
+ var PROVINCES = [
2476
+ "Islamabad Capital Territory",
2477
+ "Azad Jammu and Kashmir",
2478
+ "Gilgit-Baltistan",
2479
+ "Khyber Pakhtunkhwa",
2480
+ "Balochistan",
2481
+ "Punjab",
2482
+ "Sindh"
2483
+ ];
2484
+ function parseAddress(address) {
2485
+ const raw = normalizeWhitespace(address);
2486
+ if (raw.length === 0) {
2487
+ return emptyParsedAddress(raw);
2488
+ }
2489
+ let working = raw;
2490
+ let postalCode = null;
2491
+ const postalMatch = working.match(/\b(\d{5})\b/);
2492
+ if (postalMatch?.[1]) {
2493
+ postalCode = postalMatch[1];
2494
+ working = working.replace(postalMatch[0], " ").trim();
2495
+ }
2496
+ const segments = working.split(",").map((part) => normalizeWhitespace(part)).filter((part) => part.length > 0);
2497
+ const consumed = /* @__PURE__ */ new Set();
2498
+ let province = null;
2499
+ let city = null;
2500
+ let district = null;
2501
+ for (let i = segments.length - 1; i >= 0; i -= 1) {
2502
+ const segment = segments[i];
2503
+ if (segment === void 0 || consumed.has(i)) {
2504
+ continue;
2505
+ }
2506
+ if (province === null) {
2507
+ const matchedProvince = matchFromList(segment, PROVINCES);
2508
+ if (matchedProvince) {
2509
+ province = matchedProvince;
2510
+ consumed.add(i);
2511
+ continue;
2512
+ }
2513
+ }
2514
+ if (city === null) {
2515
+ const matchedCity = matchFromList(segment, CITY_NAMES);
2516
+ if (matchedCity) {
2517
+ city = matchedCity;
2518
+ consumed.add(i);
2519
+ continue;
2520
+ }
2521
+ }
2522
+ if (district === null) {
2523
+ const matchedDistrict = matchFromList(segment, DISTRICT_NAMES);
2524
+ if (matchedDistrict) {
2525
+ district = matchedDistrict;
2526
+ if (city === null) {
2527
+ city = matchedDistrict;
2528
+ }
2529
+ consumed.add(i);
2530
+ }
2531
+ }
2532
+ }
2533
+ if (postalCode !== null && city === null) {
2534
+ city = getCityByPostalCode(postalCode);
2535
+ }
2536
+ if (city !== null && province === null) {
2537
+ province = getProvince(city) ?? getDistrictProvince(city);
2538
+ }
2539
+ if (district !== null && province === null) {
2540
+ province = getDistrictProvince(district);
2541
+ }
2542
+ const remaining = segments.filter((_, index) => !consumed.has(index));
2543
+ const street = remaining.length > 0 ? remaining[0] ?? null : null;
2544
+ const area = remaining.length > 1 ? remaining.slice(1).join(", ") : null;
2545
+ return {
2546
+ raw,
2547
+ street,
2548
+ area,
2549
+ city,
2550
+ district,
2551
+ province,
2552
+ postalCode
2553
+ };
2554
+ }
2555
+ function formatAddress(parts) {
2556
+ const segments = [];
2557
+ if (parts.street) {
2558
+ segments.push(parts.street);
2559
+ }
2560
+ if (parts.area) {
2561
+ segments.push(parts.area);
2562
+ }
2563
+ if (parts.city) {
2564
+ segments.push(parts.city);
2565
+ } else if (parts.district) {
2566
+ segments.push(parts.district);
2567
+ }
2568
+ if (parts.province) {
2569
+ segments.push(parts.province);
2570
+ }
2571
+ let formatted = segments.join(", ");
2572
+ const postal = parts.postalCode ?? (parts.city ? getPostalCode(parts.city) : null);
2573
+ if (postal) {
2574
+ formatted = formatted.length > 0 ? `${formatted} ${postal}` : postal;
2575
+ }
2576
+ return formatted.length > 0 ? formatted : parts.raw;
2577
+ }
2578
+ function emptyParsedAddress(raw) {
2579
+ return {
2580
+ raw,
2581
+ street: null,
2582
+ area: null,
2583
+ city: null,
2584
+ district: null,
2585
+ province: null,
2586
+ postalCode: null
2587
+ };
2588
+ }
2589
+ function matchFromList(segment, options) {
2590
+ const key = normalizeKey(segment);
2591
+ for (const option of options) {
2592
+ if (normalizeKey(option) === key) {
2593
+ return option;
2594
+ }
2595
+ }
2596
+ return null;
2597
+ }
2598
+
2599
+ // src/text.ts
2600
+ var URDU_DIGITS = ["\u06F0", "\u06F1", "\u06F2", "\u06F3", "\u06F4", "\u06F5", "\u06F6", "\u06F7", "\u06F8", "\u06F9"];
2601
+ var ENGLISH_DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
2602
+ var ARABIC_INDIC_DIGITS = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
2603
+ var ROMAN_URDU_REPLACEMENTS = [
2604
+ [/\bkia\b/gi, "kya"],
2605
+ [/\bker\b/gi, "kar"],
2606
+ [/\bkr\b/gi, "kar"],
2607
+ [/\bhai\b/gi, "hai"],
2608
+ [/\bhy\b/gi, "hai"],
2609
+ [/\bmujhe\b/gi, "mujhe"],
2610
+ [/\bmujhay\b/gi, "mujhe"],
2611
+ [/\bap\b/gi, "aap"],
2612
+ [/\btum\b/gi, "tum"],
2613
+ [/\bshukria\b/gi, "shukriya"],
2614
+ [/\bmein\b/gi, "main"],
2615
+ [/\bmen\b/gi, "main"],
2616
+ [/\bnahi\b/gi, "nahi"],
2617
+ [/\bnhi\b/gi, "nahi"],
2618
+ [/\bassalamu alaikum\b/gi, "assalamualaikum"],
2619
+ [/\bassalam o alaikum\b/gi, "assalamualaikum"],
2620
+ [/\bkhuda hafiz\b/gi, "khuda hafiz"],
2621
+ [/\ballah hafiz\b/gi, "allah hafiz"]
2622
+ ];
2623
+ function normalizeText(text) {
2624
+ return normalizeWhitespace(text.normalize("NFC"));
2625
+ }
2626
+ function normalizeRomanUrdu(text) {
2627
+ let result = normalizeText(toEnglishDigits(text));
2628
+ for (const [pattern, replacement] of ROMAN_URDU_REPLACEMENTS) {
2629
+ result = result.replace(pattern, replacement);
2630
+ }
2631
+ return result;
2632
+ }
2633
+ function toUrduDigits(text) {
2634
+ return replaceDigitSets(text, ENGLISH_DIGITS, URDU_DIGITS, ARABIC_INDIC_DIGITS);
2635
+ }
2636
+ function toEnglishDigits(text) {
2637
+ let result = text;
2638
+ for (let i = 0; i < URDU_DIGITS.length; i += 1) {
2639
+ const urdu = URDU_DIGITS[i];
2640
+ const english = ENGLISH_DIGITS[i];
2641
+ if (urdu !== void 0 && english !== void 0) {
2642
+ result = result.replaceAll(urdu, english);
2643
+ }
2644
+ }
2645
+ for (let i = 0; i < ARABIC_INDIC_DIGITS.length; i += 1) {
2646
+ const arabic = ARABIC_INDIC_DIGITS[i];
2647
+ const english = ENGLISH_DIGITS[i];
2648
+ if (arabic !== void 0 && english !== void 0) {
2649
+ result = result.replaceAll(arabic, english);
2650
+ }
2651
+ }
2652
+ return result;
2653
+ }
2654
+ function replaceDigitSets(text, fromEnglish, toUrdu, fromArabic) {
2655
+ let result = text;
2656
+ for (let i = 0; i < fromEnglish.length; i += 1) {
2657
+ const english = fromEnglish[i];
2658
+ const urdu = toUrdu[i];
2659
+ if (english !== void 0 && urdu !== void 0) {
2660
+ result = result.replaceAll(english, urdu);
2661
+ }
2662
+ }
2663
+ for (let i = 0; i < fromArabic.length; i += 1) {
2664
+ const arabic = fromArabic[i];
2665
+ const urdu = toUrdu[i];
2666
+ if (arabic !== void 0 && urdu !== void 0) {
2667
+ result = result.replaceAll(arabic, urdu);
2668
+ }
2669
+ }
2670
+ return result;
2671
+ }
2672
+
2673
+ // src/hijri.ts
2674
+ var HIJRI_MONTHS = [
2675
+ "Muharram",
2676
+ "Safar",
2677
+ "Rabi al-Awwal",
2678
+ "Rabi al-Thani",
2679
+ "Jumada al-Awwal",
2680
+ "Jumada al-Thani",
2681
+ "Rajab",
2682
+ "Shaaban",
2683
+ "Ramadan",
2684
+ "Shawwal",
2685
+ "Dhu al-Qadah",
2686
+ "Dhu al-Hijjah"
2687
+ ];
2688
+ function toHijri(date) {
2689
+ const jd = gregorianToJulianDay(
2690
+ date.getFullYear(),
2691
+ date.getMonth() + 1,
2692
+ date.getDate()
2693
+ );
2694
+ return julianDayToHijri(jd);
2695
+ }
2696
+ function fromHijri(hijri) {
2697
+ const jd = hijriToJulianDay(hijri.year, hijri.month, hijri.day);
2698
+ const { year, month, day } = julianDayToGregorian(jd);
2699
+ return new Date(year, month - 1, day);
2700
+ }
2701
+ function formatHijri(date) {
2702
+ const hijri = toHijri(date);
2703
+ const monthName = getHijriMonthName(hijri.month);
2704
+ return `${hijri.day} ${monthName} ${hijri.year}`;
2705
+ }
2706
+ function getHijriMonthName(month) {
2707
+ if (month < 1 || month > 12) {
2708
+ return "";
2709
+ }
2710
+ return HIJRI_MONTHS[month - 1] ?? "";
2711
+ }
2712
+ function isRamadan(date) {
2713
+ return toHijri(date).month === 9;
2714
+ }
2715
+ function gregorianToJulianDay(year, month, day) {
2716
+ let y = year;
2717
+ let m = month;
2718
+ if (m <= 2) {
2719
+ y -= 1;
2720
+ m += 12;
2721
+ }
2722
+ const A = Math.floor(y / 100);
2723
+ const B = 2 - A + Math.floor(A / 4);
2724
+ return Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m + 1)) + day + B - 1524.5;
2725
+ }
2726
+ function julianDayToGregorian(jd) {
2727
+ const Z = Math.floor(jd + 0.5);
2728
+ const F = jd + 0.5 - Z;
2729
+ let A = Z;
2730
+ if (Z >= 2299161) {
2731
+ const alpha = Math.floor((Z - 186721625e-2) / 36524.25);
2732
+ A = Z + 1 + alpha - Math.floor(alpha / 4);
2733
+ }
2734
+ const B = A + 1524;
2735
+ const C = Math.floor((B - 122.1) / 365.25);
2736
+ const D = Math.floor(365.25 * C);
2737
+ const E = Math.floor((B - D) / 30.6001);
2738
+ const day = B - D - Math.floor(30.6001 * E) + F;
2739
+ const month = E < 14 ? E - 1 : E - 13;
2740
+ const year = month > 2 ? C - 4716 : C - 4715;
2741
+ return {
2742
+ year: Math.floor(year),
2743
+ month,
2744
+ day: Math.floor(day)
2745
+ };
2746
+ }
2747
+ function julianDayToHijri(jd) {
2748
+ const l = Math.floor(jd - 1948440 + 10632);
2749
+ const n = Math.floor((l - 1) / 10631);
2750
+ const l2 = l - 10631 * n + 354;
2751
+ const j = Math.floor((10985 - l2) / 5316) * Math.floor(50 * l2 / 17719) + Math.floor(l2 / 5670) * Math.floor(43 * l2 / 15238);
2752
+ const l3 = l2 - Math.floor((30 - j) / 15) * Math.floor(17719 * j / 50) - Math.floor(j / 16) * Math.floor(15238 * j / 43) + 29;
2753
+ const month = Math.floor(24 * l3 / 709);
2754
+ const day = l3 - Math.floor(709 * month / 24);
2755
+ const year = 30 * n + j - 30;
2756
+ return { year, month, day };
2757
+ }
2758
+ function hijriToJulianDay(year, month, day) {
2759
+ return Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month - Math.floor((month - 1) / 2) + day + 1948440 - 385;
2760
+ }
2761
+
2762
+ export { analyzePhone, createWhatsAppLink, formatAddress, formatHijri, formatLakh, formatPKR, formatPhone, fromHijri, getBankFromIBAN, getCityByPostalCode, getDistrictProvince, getDistrictsByProvince, getHijriMonthName, getNetwork, getPostalAreas, getPostalCode, getPostalCodes, getProvince, isRamadan, normalizeRomanUrdu, normalizeText, parseAddress, searchCities, searchDistricts, searchPostalCodes, toEnglishDigits, toHijri, toUrduDigits, validateCNIC, validateIBAN, validatePhone };
2464
2763
  //# sourceMappingURL=index.js.map
2465
2764
  //# sourceMappingURL=index.js.map