@catbee/utils 2.0.3 → 2.0.4

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/config/index.cjs CHANGED
@@ -94,11 +94,6 @@ var defaultServerConfig = {
94
94
  exposeHeader: env.Env.getBoolean("SERVER_REQUEST_ID_EXPOSE_HEADER", true),
95
95
  generator: /* @__PURE__ */ __name(() => id.uuid(), "generator")
96
96
  },
97
- metrics: {
98
- enable: env.Env.getBoolean("SERVER_METRICS_ENABLE", false),
99
- path: env.Env.get("SERVER_METRICS_PATH", "/metrics"),
100
- withGlobalPrefix: env.Env.getBoolean("SERVER_METRICS_WITH_GLOBAL_PREFIX", false)
101
- },
102
97
  serviceVersion: {
103
98
  enable: env.Env.getBoolean("SERVER_SERVICE_VERSION_ENABLE", false),
104
99
  headerName: env.Env.get("SERVER_SERVICE_VERSION_HEADER_NAME", "x-service-version"),
package/config/index.mjs CHANGED
@@ -92,11 +92,6 @@ var defaultServerConfig = {
92
92
  exposeHeader: Env.getBoolean("SERVER_REQUEST_ID_EXPOSE_HEADER", true),
93
93
  generator: /* @__PURE__ */ __name(() => uuid(), "generator")
94
94
  },
95
- metrics: {
96
- enable: Env.getBoolean("SERVER_METRICS_ENABLE", false),
97
- path: Env.get("SERVER_METRICS_PATH", "/metrics"),
98
- withGlobalPrefix: Env.getBoolean("SERVER_METRICS_WITH_GLOBAL_PREFIX", false)
99
- },
100
95
  serviceVersion: {
101
96
  enable: Env.getBoolean("SERVER_SERVICE_VERSION_ENABLE", false),
102
97
  headerName: Env.get("SERVER_SERVICE_VERSION_HEADER_NAME", "x-service-version"),
package/crypto/index.cjs CHANGED
@@ -457,8 +457,16 @@ function generateNonce(byteLength = 16, encoding = "hex") {
457
457
  }
458
458
  __name(generateNonce, "generateNonce");
459
459
  function secureRandomInt(min, max) {
460
- if (min > max) throw new Error("min must be less than or equal to max");
460
+ if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
461
+ throw new TypeError("min and max must be safe integers");
462
+ }
463
+ if (min > max) {
464
+ throw new RangeError("min must be less than or equal to max");
465
+ }
461
466
  const range = max - min + 1;
467
+ if (!Number.isSafeInteger(range) || range <= 0) {
468
+ throw new RangeError("Range is too large");
469
+ }
462
470
  const bytesNeeded = Math.ceil(Math.log2(range) / 8);
463
471
  const maxValid = Math.floor(256 ** bytesNeeded / range) * range;
464
472
  let randomValue;
package/crypto/index.mjs CHANGED
@@ -455,8 +455,16 @@ function generateNonce(byteLength = 16, encoding = "hex") {
455
455
  }
456
456
  __name(generateNonce, "generateNonce");
457
457
  function secureRandomInt(min, max) {
458
- if (min > max) throw new Error("min must be less than or equal to max");
458
+ if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
459
+ throw new TypeError("min and max must be safe integers");
460
+ }
461
+ if (min > max) {
462
+ throw new RangeError("min must be less than or equal to max");
463
+ }
459
464
  const range = max - min + 1;
465
+ if (!Number.isSafeInteger(range) || range <= 0) {
466
+ throw new RangeError("Range is too large");
467
+ }
460
468
  const bytesNeeded = Math.ceil(Math.log2(range) / 8);
461
469
  const maxValid = Math.floor(256 ** bytesNeeded / range) * range;
462
470
  let randomValue;
package/date/index.cjs CHANGED
@@ -575,6 +575,278 @@ function getTimeZoneParts(date, timeZone) {
575
575
  };
576
576
  }
577
577
  __name(getTimeZoneParts, "getTimeZoneParts");
578
+ var COUNTRY_CODES = [
579
+ "AD",
580
+ "AE",
581
+ "AF",
582
+ "AG",
583
+ "AI",
584
+ "AL",
585
+ "AM",
586
+ "AO",
587
+ "AQ",
588
+ "AR",
589
+ "AS",
590
+ "AT",
591
+ "AU",
592
+ "AW",
593
+ "AX",
594
+ "AZ",
595
+ "BA",
596
+ "BB",
597
+ "BD",
598
+ "BE",
599
+ "BF",
600
+ "BG",
601
+ "BH",
602
+ "BI",
603
+ "BJ",
604
+ "BL",
605
+ "BM",
606
+ "BN",
607
+ "BO",
608
+ "BQ",
609
+ "BR",
610
+ "BS",
611
+ "BT",
612
+ "BV",
613
+ "BW",
614
+ "BY",
615
+ "BZ",
616
+ "CA",
617
+ "CC",
618
+ "CD",
619
+ "CF",
620
+ "CG",
621
+ "CH",
622
+ "CI",
623
+ "CK",
624
+ "CL",
625
+ "CM",
626
+ "CN",
627
+ "CO",
628
+ "CR",
629
+ "CU",
630
+ "CV",
631
+ "CW",
632
+ "CX",
633
+ "CY",
634
+ "CZ",
635
+ "DE",
636
+ "DJ",
637
+ "DK",
638
+ "DM",
639
+ "DO",
640
+ "DZ",
641
+ "EC",
642
+ "EE",
643
+ "EG",
644
+ "EH",
645
+ "ER",
646
+ "ES",
647
+ "ET",
648
+ "FI",
649
+ "FJ",
650
+ "FK",
651
+ "FM",
652
+ "FO",
653
+ "FR",
654
+ "GA",
655
+ "GB",
656
+ "GD",
657
+ "GE",
658
+ "GF",
659
+ "GG",
660
+ "GH",
661
+ "GI",
662
+ "GL",
663
+ "GM",
664
+ "GN",
665
+ "GP",
666
+ "GQ",
667
+ "GR",
668
+ "GS",
669
+ "GT",
670
+ "GU",
671
+ "GW",
672
+ "GY",
673
+ "HK",
674
+ "HM",
675
+ "HN",
676
+ "HR",
677
+ "HT",
678
+ "HU",
679
+ "ID",
680
+ "IE",
681
+ "IL",
682
+ "IM",
683
+ "IN",
684
+ "IO",
685
+ "IQ",
686
+ "IR",
687
+ "IS",
688
+ "IT",
689
+ "JE",
690
+ "JM",
691
+ "JO",
692
+ "JP",
693
+ "KE",
694
+ "KG",
695
+ "KH",
696
+ "KI",
697
+ "KM",
698
+ "KN",
699
+ "KP",
700
+ "KR",
701
+ "KW",
702
+ "KY",
703
+ "KZ",
704
+ "LA",
705
+ "LB",
706
+ "LC",
707
+ "LI",
708
+ "LK",
709
+ "LR",
710
+ "LS",
711
+ "LT",
712
+ "LU",
713
+ "LV",
714
+ "LY",
715
+ "MA",
716
+ "MC",
717
+ "MD",
718
+ "ME",
719
+ "MF",
720
+ "MG",
721
+ "MH",
722
+ "MK",
723
+ "ML",
724
+ "MM",
725
+ "MN",
726
+ "MO",
727
+ "MP",
728
+ "MQ",
729
+ "MR",
730
+ "MS",
731
+ "MT",
732
+ "MU",
733
+ "MV",
734
+ "MW",
735
+ "MX",
736
+ "MY",
737
+ "MZ",
738
+ "NA",
739
+ "NC",
740
+ "NE",
741
+ "NF",
742
+ "NG",
743
+ "NI",
744
+ "NL",
745
+ "NO",
746
+ "NP",
747
+ "NR",
748
+ "NU",
749
+ "NZ",
750
+ "OM",
751
+ "PA",
752
+ "PE",
753
+ "PF",
754
+ "PG",
755
+ "PH",
756
+ "PK",
757
+ "PL",
758
+ "PM",
759
+ "PN",
760
+ "PR",
761
+ "PS",
762
+ "PT",
763
+ "PW",
764
+ "PY",
765
+ "QA",
766
+ "RE",
767
+ "RO",
768
+ "RS",
769
+ "RU",
770
+ "RW",
771
+ "SA",
772
+ "SB",
773
+ "SC",
774
+ "SD",
775
+ "SE",
776
+ "SG",
777
+ "SH",
778
+ "SI",
779
+ "SJ",
780
+ "SK",
781
+ "SL",
782
+ "SM",
783
+ "SN",
784
+ "SO",
785
+ "SR",
786
+ "SS",
787
+ "ST",
788
+ "SV",
789
+ "SX",
790
+ "SY",
791
+ "SZ",
792
+ "TC",
793
+ "TD",
794
+ "TF",
795
+ "TG",
796
+ "TH",
797
+ "TJ",
798
+ "TK",
799
+ "TL",
800
+ "TM",
801
+ "TN",
802
+ "TO",
803
+ "TR",
804
+ "TT",
805
+ "TV",
806
+ "TW",
807
+ "TZ",
808
+ "UA",
809
+ "UG",
810
+ "UM",
811
+ "US",
812
+ "UY",
813
+ "UZ",
814
+ "VA",
815
+ "VC",
816
+ "VE",
817
+ "VG",
818
+ "VI",
819
+ "VN",
820
+ "VU",
821
+ "WF",
822
+ "WS",
823
+ "YE",
824
+ "YT",
825
+ "ZA",
826
+ "ZM",
827
+ "ZW"
828
+ ];
829
+ function getCountries(locale = "en") {
830
+ const regionNames = new Intl.DisplayNames([
831
+ locale
832
+ ], {
833
+ type: "region"
834
+ });
835
+ return COUNTRY_CODES.map((code) => ({
836
+ code,
837
+ name: regionNames.of(code)
838
+ }));
839
+ }
840
+ __name(getCountries, "getCountries");
841
+ var SUPPORTED_TIMEZONE_NAMES = Intl.supportedValuesOf("timeZone");
842
+ var TIMEZONE_NAMES = SUPPORTED_TIMEZONE_NAMES.includes("UTC") ? SUPPORTED_TIMEZONE_NAMES : [
843
+ ...SUPPORTED_TIMEZONE_NAMES,
844
+ "UTC"
845
+ ].sort((a, b) => a.localeCompare(b));
846
+ function getTimezones() {
847
+ return TIMEZONE_NAMES;
848
+ }
849
+ __name(getTimezones, "getTimezones");
578
850
 
579
851
  // src/date/date.builder.ts
580
852
  var DateBuilder = class _DateBuilder {
@@ -1179,7 +1451,9 @@ var DateBuilder = class _DateBuilder {
1179
1451
  }
1180
1452
  };
1181
1453
 
1454
+ exports.COUNTRY_CODES = COUNTRY_CODES;
1182
1455
  exports.DateBuilder = DateBuilder;
1456
+ exports.TIMEZONE_NAMES = TIMEZONE_NAMES;
1183
1457
  exports.addDays = addDays;
1184
1458
  exports.addMonths = addMonths;
1185
1459
  exports.addToDate = addToDate;
@@ -1192,9 +1466,11 @@ exports.formatDate = formatDate;
1192
1466
  exports.formatDateInTimeZone = formatDateInTimeZone;
1193
1467
  exports.formatDuration = formatDuration;
1194
1468
  exports.formatRelativeTime = formatRelativeTime;
1469
+ exports.getCountries = getCountries;
1195
1470
  exports.getDateFromDuration = getDateFromDuration;
1196
1471
  exports.getTimezoneAbbreviation = getTimezoneAbbreviation;
1197
1472
  exports.getTimezoneOffset = getTimezoneOffset;
1473
+ exports.getTimezones = getTimezones;
1198
1474
  exports.isBetween = isBetween;
1199
1475
  exports.isDST = isDST;
1200
1476
  exports.isFuture = isFuture;
package/date/index.d.ts CHANGED
@@ -441,6 +441,49 @@ declare function isDST(timeZone: string, date?: Date | number): boolean;
441
441
  * ```
442
442
  */
443
443
  declare function getTimezoneAbbreviation(timeZone: string, date?: Date | number, locale?: string): string;
444
+ /**
445
+ * List of ISO 3166-1 alpha-2 country codes for use in timezone utilities.
446
+ * This list is used to generate country names and filter timezones by country.
447
+ */
448
+ declare const COUNTRY_CODES: string[];
449
+ type Country = {
450
+ code: string;
451
+ name: string;
452
+ };
453
+ /**
454
+ * Get a list of countries with their ISO codes and localized names.
455
+ * Uses Intl.DisplayNames to get the country names based on the provided locale.
456
+ *
457
+ * @param locale - Locale code for country names (default: 'en')
458
+ * @returns Array of country objects with code and name
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * getCountries('en');
463
+ * // [ { code: 'US', name: 'United States' }, { code: 'DE', name: 'Germany' }, ... ]
464
+ *
465
+ * getCountries('fr');
466
+ * // [ { code: 'US', name: 'États-Unis' }, { code: 'DE', name: 'Allemagne' }, ... ]
467
+ * ```
468
+ */
469
+ declare function getCountries(locale?: string): Country[];
470
+ /**
471
+ * List of all IANA timezone identifiers supported by the environment.
472
+ * This can be used to populate dropdowns or validate timezone inputs.
473
+ */
474
+ declare const TIMEZONE_NAMES: string[];
475
+ /**
476
+ * Get a list of all IANA timezone identifiers supported by the environment.
477
+ * This can be used to populate dropdowns or validate timezone inputs.
478
+ *
479
+ * @returns Array of timezone identifiers (e.g., 'America/New_York', 'Europe/Berlin')
480
+ * @example
481
+ * ```typescript
482
+ * getTimezones();
483
+ * // [ 'Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', ... ]
484
+ * ```
485
+ */
486
+ declare function getTimezones(): string[];
444
487
 
445
488
  /**
446
489
  * DateBuilder class for fluent date manipulation and building.
@@ -867,5 +910,5 @@ declare class DateBuilder {
867
910
  getTimezoneAbbreviation(timeZone: string): string;
868
911
  }
869
912
 
870
- export { DateBuilder, addDays, addMonths, addToDate, addYears, dateDiff, dateDiffDaysTZ, daysInMonth, endOf, formatDate, formatDateInTimeZone, formatDuration, formatRelativeTime, getDateFromDuration, getTimezoneAbbreviation, getTimezoneOffset, isBetween, isDST, isFuture, isLeapYear, isPast, isToday, isWeekend, parseDate, parseDuration, quarterOf, startOf, toTimeZone, weekOfYear };
913
+ export { COUNTRY_CODES, DateBuilder, TIMEZONE_NAMES, addDays, addMonths, addToDate, addYears, dateDiff, dateDiffDaysTZ, daysInMonth, endOf, formatDate, formatDateInTimeZone, formatDuration, formatRelativeTime, getCountries, getDateFromDuration, getTimezoneAbbreviation, getTimezoneOffset, getTimezones, isBetween, isDST, isFuture, isLeapYear, isPast, isToday, isWeekend, parseDate, parseDuration, quarterOf, startOf, toTimeZone, weekOfYear };
871
914
  export type { DateFormatOptions, DateFormatPreset };
package/date/index.mjs CHANGED
@@ -573,6 +573,278 @@ function getTimeZoneParts(date, timeZone) {
573
573
  };
574
574
  }
575
575
  __name(getTimeZoneParts, "getTimeZoneParts");
576
+ var COUNTRY_CODES = [
577
+ "AD",
578
+ "AE",
579
+ "AF",
580
+ "AG",
581
+ "AI",
582
+ "AL",
583
+ "AM",
584
+ "AO",
585
+ "AQ",
586
+ "AR",
587
+ "AS",
588
+ "AT",
589
+ "AU",
590
+ "AW",
591
+ "AX",
592
+ "AZ",
593
+ "BA",
594
+ "BB",
595
+ "BD",
596
+ "BE",
597
+ "BF",
598
+ "BG",
599
+ "BH",
600
+ "BI",
601
+ "BJ",
602
+ "BL",
603
+ "BM",
604
+ "BN",
605
+ "BO",
606
+ "BQ",
607
+ "BR",
608
+ "BS",
609
+ "BT",
610
+ "BV",
611
+ "BW",
612
+ "BY",
613
+ "BZ",
614
+ "CA",
615
+ "CC",
616
+ "CD",
617
+ "CF",
618
+ "CG",
619
+ "CH",
620
+ "CI",
621
+ "CK",
622
+ "CL",
623
+ "CM",
624
+ "CN",
625
+ "CO",
626
+ "CR",
627
+ "CU",
628
+ "CV",
629
+ "CW",
630
+ "CX",
631
+ "CY",
632
+ "CZ",
633
+ "DE",
634
+ "DJ",
635
+ "DK",
636
+ "DM",
637
+ "DO",
638
+ "DZ",
639
+ "EC",
640
+ "EE",
641
+ "EG",
642
+ "EH",
643
+ "ER",
644
+ "ES",
645
+ "ET",
646
+ "FI",
647
+ "FJ",
648
+ "FK",
649
+ "FM",
650
+ "FO",
651
+ "FR",
652
+ "GA",
653
+ "GB",
654
+ "GD",
655
+ "GE",
656
+ "GF",
657
+ "GG",
658
+ "GH",
659
+ "GI",
660
+ "GL",
661
+ "GM",
662
+ "GN",
663
+ "GP",
664
+ "GQ",
665
+ "GR",
666
+ "GS",
667
+ "GT",
668
+ "GU",
669
+ "GW",
670
+ "GY",
671
+ "HK",
672
+ "HM",
673
+ "HN",
674
+ "HR",
675
+ "HT",
676
+ "HU",
677
+ "ID",
678
+ "IE",
679
+ "IL",
680
+ "IM",
681
+ "IN",
682
+ "IO",
683
+ "IQ",
684
+ "IR",
685
+ "IS",
686
+ "IT",
687
+ "JE",
688
+ "JM",
689
+ "JO",
690
+ "JP",
691
+ "KE",
692
+ "KG",
693
+ "KH",
694
+ "KI",
695
+ "KM",
696
+ "KN",
697
+ "KP",
698
+ "KR",
699
+ "KW",
700
+ "KY",
701
+ "KZ",
702
+ "LA",
703
+ "LB",
704
+ "LC",
705
+ "LI",
706
+ "LK",
707
+ "LR",
708
+ "LS",
709
+ "LT",
710
+ "LU",
711
+ "LV",
712
+ "LY",
713
+ "MA",
714
+ "MC",
715
+ "MD",
716
+ "ME",
717
+ "MF",
718
+ "MG",
719
+ "MH",
720
+ "MK",
721
+ "ML",
722
+ "MM",
723
+ "MN",
724
+ "MO",
725
+ "MP",
726
+ "MQ",
727
+ "MR",
728
+ "MS",
729
+ "MT",
730
+ "MU",
731
+ "MV",
732
+ "MW",
733
+ "MX",
734
+ "MY",
735
+ "MZ",
736
+ "NA",
737
+ "NC",
738
+ "NE",
739
+ "NF",
740
+ "NG",
741
+ "NI",
742
+ "NL",
743
+ "NO",
744
+ "NP",
745
+ "NR",
746
+ "NU",
747
+ "NZ",
748
+ "OM",
749
+ "PA",
750
+ "PE",
751
+ "PF",
752
+ "PG",
753
+ "PH",
754
+ "PK",
755
+ "PL",
756
+ "PM",
757
+ "PN",
758
+ "PR",
759
+ "PS",
760
+ "PT",
761
+ "PW",
762
+ "PY",
763
+ "QA",
764
+ "RE",
765
+ "RO",
766
+ "RS",
767
+ "RU",
768
+ "RW",
769
+ "SA",
770
+ "SB",
771
+ "SC",
772
+ "SD",
773
+ "SE",
774
+ "SG",
775
+ "SH",
776
+ "SI",
777
+ "SJ",
778
+ "SK",
779
+ "SL",
780
+ "SM",
781
+ "SN",
782
+ "SO",
783
+ "SR",
784
+ "SS",
785
+ "ST",
786
+ "SV",
787
+ "SX",
788
+ "SY",
789
+ "SZ",
790
+ "TC",
791
+ "TD",
792
+ "TF",
793
+ "TG",
794
+ "TH",
795
+ "TJ",
796
+ "TK",
797
+ "TL",
798
+ "TM",
799
+ "TN",
800
+ "TO",
801
+ "TR",
802
+ "TT",
803
+ "TV",
804
+ "TW",
805
+ "TZ",
806
+ "UA",
807
+ "UG",
808
+ "UM",
809
+ "US",
810
+ "UY",
811
+ "UZ",
812
+ "VA",
813
+ "VC",
814
+ "VE",
815
+ "VG",
816
+ "VI",
817
+ "VN",
818
+ "VU",
819
+ "WF",
820
+ "WS",
821
+ "YE",
822
+ "YT",
823
+ "ZA",
824
+ "ZM",
825
+ "ZW"
826
+ ];
827
+ function getCountries(locale = "en") {
828
+ const regionNames = new Intl.DisplayNames([
829
+ locale
830
+ ], {
831
+ type: "region"
832
+ });
833
+ return COUNTRY_CODES.map((code) => ({
834
+ code,
835
+ name: regionNames.of(code)
836
+ }));
837
+ }
838
+ __name(getCountries, "getCountries");
839
+ var SUPPORTED_TIMEZONE_NAMES = Intl.supportedValuesOf("timeZone");
840
+ var TIMEZONE_NAMES = SUPPORTED_TIMEZONE_NAMES.includes("UTC") ? SUPPORTED_TIMEZONE_NAMES : [
841
+ ...SUPPORTED_TIMEZONE_NAMES,
842
+ "UTC"
843
+ ].sort((a, b) => a.localeCompare(b));
844
+ function getTimezones() {
845
+ return TIMEZONE_NAMES;
846
+ }
847
+ __name(getTimezones, "getTimezones");
576
848
 
577
849
  // src/date/date.builder.ts
578
850
  var DateBuilder = class _DateBuilder {
@@ -1177,4 +1449,4 @@ var DateBuilder = class _DateBuilder {
1177
1449
  }
1178
1450
  };
1179
1451
 
1180
- export { DateBuilder, addDays, addMonths, addToDate, addYears, dateDiff, dateDiffDaysTZ, daysInMonth, endOf, formatDate, formatDateInTimeZone, formatDuration, formatRelativeTime, getDateFromDuration, getTimezoneAbbreviation, getTimezoneOffset, isBetween, isDST, isFuture, isLeapYear, isPast, isToday, isWeekend, parseDate, parseDuration, quarterOf, startOf, toTimeZone, weekOfYear };
1452
+ export { COUNTRY_CODES, DateBuilder, TIMEZONE_NAMES, addDays, addMonths, addToDate, addYears, dateDiff, dateDiffDaysTZ, daysInMonth, endOf, formatDate, formatDateInTimeZone, formatDuration, formatRelativeTime, getCountries, getDateFromDuration, getTimezoneAbbreviation, getTimezoneOffset, getTimezones, isBetween, isDST, isFuture, isLeapYear, isPast, isToday, isWeekend, parseDate, parseDuration, quarterOf, startOf, toTimeZone, weekOfYear };