@zelgadis87/utils-core 4.1.0 → 4.2.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/esbuild/index.mjs CHANGED
@@ -1,3 +1,167 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
28
+ var require_format = __commonJS({
29
+ "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports) {
30
+ "use strict";
31
+ Object.defineProperty(exports, "__esModule", {
32
+ value: true
33
+ });
34
+ exports["default"] = format2;
35
+ function ownKeys(object, enumerableOnly) {
36
+ var keys = Object.keys(object);
37
+ if (Object.getOwnPropertySymbols) {
38
+ var symbols = Object.getOwnPropertySymbols(object);
39
+ if (enumerableOnly) {
40
+ symbols = symbols.filter(function(sym) {
41
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
42
+ });
43
+ }
44
+ keys.push.apply(keys, symbols);
45
+ }
46
+ return keys;
47
+ }
48
+ function _objectSpread(target) {
49
+ for (var i = 1; i < arguments.length; i++) {
50
+ var source = arguments[i] != null ? arguments[i] : {};
51
+ if (i % 2) {
52
+ ownKeys(Object(source), true).forEach(function(key) {
53
+ _defineProperty(target, key, source[key]);
54
+ });
55
+ } else if (Object.getOwnPropertyDescriptors) {
56
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
57
+ } else {
58
+ ownKeys(Object(source)).forEach(function(key) {
59
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
60
+ });
61
+ }
62
+ }
63
+ return target;
64
+ }
65
+ function _defineProperty(obj, key, value) {
66
+ if (key in obj) {
67
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
68
+ } else {
69
+ obj[key] = value;
70
+ }
71
+ return obj;
72
+ }
73
+ var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
74
+ var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
75
+ var optionNames = {
76
+ y: "year",
77
+ M: "month",
78
+ d: "day",
79
+ D: "weekday",
80
+ S: "fractionalSecondDigits",
81
+ G: "era",
82
+ Z: "timeZoneName",
83
+ P: "dayPeriod",
84
+ a: "hour12",
85
+ h: "hour",
86
+ H: "hour",
87
+ m: "minute",
88
+ s: "second"
89
+ };
90
+ var values = {
91
+ y: ["numeric", "2-digit", void 0, "numeric"],
92
+ M: ["narrow", "2-digit", "short", "long"],
93
+ d: ["numeric", "2-digit"],
94
+ D: ["narrow", "short", "long"],
95
+ S: [1, 2, 3],
96
+ G: ["narrow", "short", "long"],
97
+ Z: ["short", "long"],
98
+ P: ["narrow", "short", "long"],
99
+ a: [true],
100
+ h: ["numeric", "2-digit"],
101
+ H: ["numeric", "2-digit"],
102
+ m: ["numeric", "2-digit"],
103
+ s: ["numeric", "2-digit"]
104
+ };
105
+ function padIf(condition, value, length) {
106
+ return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
107
+ }
108
+ function formatType(date, type, length) {
109
+ var _options;
110
+ var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
111
+ var option = optionNames[type];
112
+ var value = values[type][length - 1];
113
+ if (!value) {
114
+ return;
115
+ }
116
+ var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
117
+ if (type === "a") {
118
+ return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
119
+ hour: "numeric"
120
+ })).formatToParts(date).pop().value;
121
+ }
122
+ if (type === "G" || type === "Z") {
123
+ return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
124
+ }
125
+ if (type === "H" || type === "h") {
126
+ return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
127
+ hourCycle: type === "H" ? "h23" : "h11"
128
+ })).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
129
+ }
130
+ return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
131
+ }
132
+ function format2(date, pattern, config) {
133
+ return pattern.split(ESCAPE_REGEX).filter(function(sub) {
134
+ return sub !== void 0;
135
+ }).map(function(sub, index) {
136
+ if (index % 2 !== 0) {
137
+ return sub;
138
+ }
139
+ return sub.replace(PATTERN_REGEX, function(match) {
140
+ var type = match.charAt(0);
141
+ return formatType(date, type, match.length, config) || match;
142
+ });
143
+ }).join("");
144
+ }
145
+ }
146
+ });
147
+
148
+ // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
149
+ var require_lib = __commonJS({
150
+ "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports) {
151
+ "use strict";
152
+ Object.defineProperty(exports, "__esModule", {
153
+ value: true
154
+ });
155
+ exports.format = void 0;
156
+ var _format = require_format();
157
+ var _format2 = _interopRequireDefault(_format);
158
+ function _interopRequireDefault(obj) {
159
+ return obj && obj.__esModule ? obj : { "default": obj };
160
+ }
161
+ exports.format = _format2["default"];
162
+ }
163
+ });
164
+
1
165
  // src/types/arrays.ts
2
166
  function ensureArray(t) {
3
167
  return t instanceof Array ? t : [t];
@@ -85,6 +249,16 @@ function isFunction(t) {
85
249
  return typeof t === "function";
86
250
  }
87
251
 
252
+ // src/types/json.ts
253
+ function tryToParseJson(jsonContent) {
254
+ try {
255
+ const data = JSON.parse(jsonContent);
256
+ return [data, null];
257
+ } catch (err) {
258
+ return [null, asError(err)];
259
+ }
260
+ }
261
+
88
262
  // src/types/nulls.ts
89
263
  function ensureDefined(v, name = "value") {
90
264
  if (isDefined(v))
@@ -431,8 +605,132 @@ var LazyAsync = class _LazyAsync {
431
605
  }
432
606
  };
433
607
 
608
+ // src/time/TimeInstant.ts
609
+ var import_small_date = __toESM(require_lib());
610
+
611
+ // src/time/TimeUnit.ts
612
+ var TimeUnit = class _TimeUnit {
613
+ constructor(multiplier) {
614
+ this.multiplier = multiplier;
615
+ }
616
+ toUnit(value, unit) {
617
+ return value * (this.multiplier / unit.multiplier);
618
+ }
619
+ toMs(value) {
620
+ return this.toUnit(value, _TimeUnit.MILLISECONDS);
621
+ }
622
+ toSeconds(value) {
623
+ return this.toUnit(value, _TimeUnit.SECONDS);
624
+ }
625
+ toMinutes(value) {
626
+ return this.toUnit(value, _TimeUnit.MINUTES);
627
+ }
628
+ toHours(value) {
629
+ return this.toUnit(value, _TimeUnit.HOURS);
630
+ }
631
+ toDays(value) {
632
+ return this.toUnit(value, _TimeUnit.DAYS);
633
+ }
634
+ toWeeks(value) {
635
+ return this.toUnit(value, _TimeUnit.WEEKS);
636
+ }
637
+ static MILLISECONDS = new _TimeUnit(1);
638
+ static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
639
+ static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
640
+ static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
641
+ static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
642
+ static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
643
+ };
644
+
645
+ // src/time/TimeBase.ts
646
+ var TimeBase = class {
647
+ _ms;
648
+ constructor(value, unit) {
649
+ this._ms = unit.toMs(value);
650
+ }
651
+ get ms() {
652
+ return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
653
+ }
654
+ get seconds() {
655
+ return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
656
+ }
657
+ get minutes() {
658
+ return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
659
+ }
660
+ get hours() {
661
+ return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
662
+ }
663
+ get days() {
664
+ return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
665
+ }
666
+ addMs(milliseconds) {
667
+ return this.addUnits(milliseconds, TimeUnit.MILLISECONDS);
668
+ }
669
+ addSeconds(seconds) {
670
+ return this.addUnits(seconds, TimeUnit.SECONDS);
671
+ }
672
+ addMinutes(minutes) {
673
+ return this.addUnits(minutes, TimeUnit.MINUTES);
674
+ }
675
+ addHours(hours) {
676
+ return this.addUnits(hours, TimeUnit.HOURS);
677
+ }
678
+ addDays(days) {
679
+ return this.addUnits(days, TimeUnit.DAYS);
680
+ }
681
+ removeDays(days) {
682
+ return this.removeUnits(days, TimeUnit.DAYS);
683
+ }
684
+ addUnits(n, unit) {
685
+ return this.create(this._ms + unit.toMs(n), TimeUnit.MILLISECONDS);
686
+ }
687
+ removeMs(milliseconds) {
688
+ return this.addUnits(-milliseconds, TimeUnit.MILLISECONDS);
689
+ }
690
+ removeSeconds(seconds) {
691
+ return this.addUnits(-seconds, TimeUnit.SECONDS);
692
+ }
693
+ removeMinutes(minutes) {
694
+ return this.addUnits(-minutes, TimeUnit.MINUTES);
695
+ }
696
+ removeHours(hours) {
697
+ return this.addUnits(-hours, TimeUnit.HOURS);
698
+ }
699
+ removeUnits(n, unit) {
700
+ return this.addUnits(-n, unit);
701
+ }
702
+ getUnit(unit) {
703
+ return this._ms / unit.multiplier;
704
+ }
705
+ toUnits() {
706
+ return {
707
+ days: Math.floor(this._ms / TimeUnit.DAYS.multiplier),
708
+ hours: Math.floor(this._ms / TimeUnit.HOURS.multiplier % 24),
709
+ minutes: Math.floor(this._ms / TimeUnit.MINUTES.multiplier % 60),
710
+ seconds: Math.floor(this._ms / TimeUnit.SECONDS.multiplier % 60)
711
+ };
712
+ }
713
+ static toMs(units) {
714
+ if (!units)
715
+ throw new Error("Invalid units given");
716
+ let ms = 0;
717
+ ms += units.ms ?? 0 * TimeUnit.MILLISECONDS.multiplier;
718
+ ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
719
+ ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
720
+ ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
721
+ ms += (units.days ?? 0) * TimeUnit.DAYS.multiplier;
722
+ return ms;
723
+ }
724
+ toJSON() {
725
+ return this._ms;
726
+ }
727
+ };
728
+
434
729
  // src/async/Deferred.ts
435
730
  var DeferredCanceledError = class extends Error {
731
+ constructor() {
732
+ super("Execution canceled");
733
+ }
436
734
  };
437
735
  var Deferred = class {
438
736
  _pending;
@@ -449,15 +747,37 @@ var Deferred = class {
449
747
  this._internals = this.createInternals();
450
748
  }
451
749
  resolve(val) {
452
- if (!this._pending) throw new Error("Illegal state exception");
750
+ if (!this._pending)
751
+ throw new Error("Illegal state exception");
752
+ this.resolveIfPending(val);
753
+ }
754
+ reject(reason) {
755
+ if (!this._pending)
756
+ throw new Error("Illegal state exception");
757
+ this.rejectIfPending(reason);
758
+ }
759
+ cancel() {
760
+ if (!this._pending)
761
+ throw new Error("Illegal state exception");
762
+ this.cancelIfPending();
763
+ }
764
+ resolveIfPending(val) {
765
+ if (!this._pending)
766
+ return;
453
767
  this._pending = false;
454
768
  this._internals.resolve(val);
455
769
  }
456
- reject(reason) {
457
- if (!this._pending) throw new Error("Illegal state exception");
770
+ rejectIfPending(reason) {
771
+ if (!this._pending)
772
+ return;
458
773
  this._pending = false;
459
774
  this._internals.reject(reason);
460
775
  }
776
+ cancelIfPending() {
777
+ if (!this._pending)
778
+ return;
779
+ this.reject(new DeferredCanceledError());
780
+ }
461
781
  then(onFulfilled, onRejected) {
462
782
  return this._internals.promise.then(onFulfilled, onRejected);
463
783
  }
@@ -467,10 +787,6 @@ var Deferred = class {
467
787
  finally(onfinally) {
468
788
  return this._internals.promise.finally(onfinally);
469
789
  }
470
- cancel() {
471
- if (!this._pending) throw new Error("Illegal state exception");
472
- this._internals.reject(new DeferredCanceledError("Execution aborted by the user"));
473
- }
474
790
  get asPromise() {
475
791
  return this;
476
792
  }
@@ -495,6 +811,16 @@ var Deferred = class {
495
811
  };
496
812
  var Deferred_default = Deferred;
497
813
 
814
+ // src/random/randomInterval.ts
815
+ function randomInterval(min2, max2) {
816
+ return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
817
+ }
818
+
819
+ // src/random/randomPercentage.ts
820
+ function randomPercentage(min2, max2) {
821
+ return randomInterval(min2, max2) / 100;
822
+ }
823
+
498
824
  // src/utils/bindThis.ts
499
825
  function bindThis(fn, _this) {
500
826
  return fn.bind(_this);
@@ -775,25 +1101,28 @@ var RateThrottler = class {
775
1101
  var Semaphore = class {
776
1102
  constructor(_availableSlots = 1) {
777
1103
  this._availableSlots = _availableSlots;
778
- this._waitingRequests = [];
1104
+ this._queuedRequests = [];
779
1105
  }
780
- _waitingRequests;
1106
+ _queuedRequests;
1107
+ _inProgress = 0;
781
1108
  async _awaitSlot() {
782
1109
  if (this._availableSlots > 0) {
783
1110
  this._availableSlots -= 1;
1111
+ this._inProgress += 1;
784
1112
  return void 0;
785
1113
  } else {
786
1114
  const deferred = new Deferred_default();
787
- this._waitingRequests.push(deferred);
1115
+ this._queuedRequests.push(deferred);
788
1116
  return deferred.asPromise;
789
1117
  }
790
1118
  }
791
1119
  _releaseSlot() {
792
- const waitingSlotToResolve = this._waitingRequests.shift();
1120
+ const waitingSlotToResolve = this._queuedRequests.shift();
793
1121
  if (waitingSlotToResolve) {
794
1122
  waitingSlotToResolve.resolve();
795
1123
  } else {
796
1124
  this._availableSlots += 1;
1125
+ this._inProgress -= 1;
797
1126
  }
798
1127
  }
799
1128
  async execute(fn, cooldown = TimeDuration.ZERO) {
@@ -801,6 +1130,15 @@ var Semaphore = class {
801
1130
  void cooldown.promise().then(() => this._releaseSlot());
802
1131
  });
803
1132
  }
1133
+ get availableSlots() {
1134
+ return this._availableSlots;
1135
+ }
1136
+ get queueSize() {
1137
+ return this._queuedRequests.length;
1138
+ }
1139
+ get inProgressSize() {
1140
+ return this._inProgress;
1141
+ }
804
1142
  };
805
1143
 
806
1144
  // src/utils/throttle.ts
@@ -855,134 +1193,6 @@ function wrap(str, delimiter) {
855
1193
  return delimiter + str + delimiter;
856
1194
  }
857
1195
 
858
- // src/time/TimeUnit.ts
859
- var TimeUnit = class _TimeUnit {
860
- constructor(multiplier) {
861
- this.multiplier = multiplier;
862
- }
863
- toUnit(value, unit) {
864
- return value * (this.multiplier / unit.multiplier);
865
- }
866
- toMs(value) {
867
- return this.toUnit(value, _TimeUnit.MILLISECONDS);
868
- }
869
- toSeconds(value) {
870
- return this.toUnit(value, _TimeUnit.SECONDS);
871
- }
872
- toMinutes(value) {
873
- return this.toUnit(value, _TimeUnit.MINUTES);
874
- }
875
- toHours(value) {
876
- return this.toUnit(value, _TimeUnit.HOURS);
877
- }
878
- toDays(value) {
879
- return this.toUnit(value, _TimeUnit.DAYS);
880
- }
881
- toWeeks(value) {
882
- return this.toUnit(value, _TimeUnit.WEEKS);
883
- }
884
- static MILLISECONDS = new _TimeUnit(1);
885
- static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
886
- static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
887
- static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
888
- static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
889
- static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
890
- };
891
-
892
- // src/time/TimeBase.ts
893
- var TimeBase = class {
894
- _ms;
895
- constructor(value, unit) {
896
- this._ms = unit.toMs(value);
897
- }
898
- get ms() {
899
- return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
900
- }
901
- get seconds() {
902
- return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
903
- }
904
- get minutes() {
905
- return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
906
- }
907
- get hours() {
908
- return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
909
- }
910
- get days() {
911
- return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
912
- }
913
- addMs(milliseconds) {
914
- return this.addUnits(milliseconds, TimeUnit.MILLISECONDS);
915
- }
916
- addSeconds(seconds) {
917
- return this.addUnits(seconds, TimeUnit.SECONDS);
918
- }
919
- addMinutes(minutes) {
920
- return this.addUnits(minutes, TimeUnit.MINUTES);
921
- }
922
- addHours(hours) {
923
- return this.addUnits(hours, TimeUnit.HOURS);
924
- }
925
- addDays(days) {
926
- return this.addUnits(days, TimeUnit.DAYS);
927
- }
928
- removeDays(days) {
929
- return this.removeUnits(days, TimeUnit.DAYS);
930
- }
931
- addUnits(n, unit) {
932
- return this.create(this._ms + unit.toMs(n), TimeUnit.MILLISECONDS);
933
- }
934
- removeMs(milliseconds) {
935
- return this.addUnits(-milliseconds, TimeUnit.MILLISECONDS);
936
- }
937
- removeSeconds(seconds) {
938
- return this.addUnits(-seconds, TimeUnit.SECONDS);
939
- }
940
- removeMinutes(minutes) {
941
- return this.addUnits(-minutes, TimeUnit.MINUTES);
942
- }
943
- removeHours(hours) {
944
- return this.addUnits(-hours, TimeUnit.HOURS);
945
- }
946
- removeUnits(n, unit) {
947
- return this.addUnits(-n, unit);
948
- }
949
- getUnit(unit) {
950
- return this._ms / unit.multiplier;
951
- }
952
- toUnits() {
953
- return {
954
- days: Math.floor(this._ms / TimeUnit.DAYS.multiplier),
955
- hours: Math.floor(this._ms / TimeUnit.HOURS.multiplier % 24),
956
- minutes: Math.floor(this._ms / TimeUnit.MINUTES.multiplier % 60),
957
- seconds: Math.floor(this._ms / TimeUnit.SECONDS.multiplier % 60)
958
- };
959
- }
960
- static toMs(units) {
961
- if (!units)
962
- throw new Error("Invalid units given");
963
- let ms = 0;
964
- ms += units.ms ?? 0 * TimeUnit.MILLISECONDS.multiplier;
965
- ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
966
- ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
967
- ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
968
- ms += (units.days ?? 0) * TimeUnit.DAYS.multiplier;
969
- return ms;
970
- }
971
- toJSON() {
972
- return this._ms;
973
- }
974
- };
975
-
976
- // src/random/randomInterval.ts
977
- function randomInterval(min2, max2) {
978
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
979
- }
980
-
981
- // src/random/randomPercentage.ts
982
- function randomPercentage(min2, max2) {
983
- return randomInterval(min2, max2) / 100;
984
- }
985
-
986
1196
  // src/time/TimeDuration.ts
987
1197
  var TimeDuration = class _TimeDuration extends TimeBase {
988
1198
  constructor(value, unit) {
@@ -1023,14 +1233,14 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1023
1233
  * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1024
1234
  */
1025
1235
  get formatted() {
1026
- const format = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1236
+ const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1027
1237
  const units = this.toUnits();
1028
1238
  if (units.days >= 1)
1029
- return format(units.days, "d", units.hours, "h");
1239
+ return format2(units.days, "d", units.hours, "h");
1030
1240
  else if (units.hours >= 1)
1031
- return format(units.hours, "h", units.minutes, "m");
1241
+ return format2(units.hours, "h", units.minutes, "m");
1032
1242
  else if (units.minutes >= 1)
1033
- return format(units.minutes, "m", units.seconds, "s");
1243
+ return format2(units.minutes, "m", units.seconds, "s");
1034
1244
  else if (units.seconds >= 0)
1035
1245
  return units.seconds.toString() + "s";
1036
1246
  else if (units.seconds > -60)
@@ -1063,8 +1273,10 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1063
1273
  const deferred = this.promise();
1064
1274
  void deferred.then(() => {
1065
1275
  cb();
1066
- }, (_err) => {
1067
- return;
1276
+ }, (err) => {
1277
+ if (err instanceof DeferredCanceledError)
1278
+ return;
1279
+ throw err;
1068
1280
  });
1069
1281
  return { cancel: () => deferred.cancel() };
1070
1282
  }
@@ -1263,7 +1475,7 @@ var timeInstantResolveValue = (getFromDate2, referenceDate, x) => {
1263
1475
  if (relativeTo === void 0 || relativeTo === "now") {
1264
1476
  return getFromDate2(referenceDate) + relative;
1265
1477
  } else {
1266
- return getFromDate2(relativeTo.asDateUTC()) + relative;
1478
+ return getFromDate2(relativeTo.toDate()) + relative;
1267
1479
  }
1268
1480
  } else if ("absolute" in x) {
1269
1481
  return x.absolute;
@@ -1282,7 +1494,7 @@ var getFromDate = {
1282
1494
  };
1283
1495
  var toReferenceDate = (x) => {
1284
1496
  ensureDefined(x);
1285
- if (isTimeInstant(x)) return x.asDateUTC();
1497
+ if (isTimeInstant(x)) return x.toDate();
1286
1498
  return x;
1287
1499
  };
1288
1500
  function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
@@ -1302,7 +1514,7 @@ function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInsta
1302
1514
  return TimeInstant.fromUnixTimestamp(timestamp2);
1303
1515
  }
1304
1516
  function timeInstantBuilder() {
1305
- let referenceDate = TimeInstant.now().asDateUTC();
1517
+ let referenceDate = TimeInstant.now().toDate();
1306
1518
  const value = { ...defaultTimeInstantCreationParameters };
1307
1519
  const ret = {
1308
1520
  year: (x) => {
@@ -1378,157 +1590,103 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1378
1590
  atEndOfDay() {
1379
1591
  return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
1380
1592
  }
1381
- /** @deprecated[2024-10-24]: Use #promise() instead. */
1382
- timeout(cb) {
1383
- if (!this.isInTheFuture) {
1384
- throw new Error("Instant is in the past");
1385
- } else {
1386
- return this.distanceFromNow().timeout(() => cb());
1387
- }
1388
- }
1389
1593
  promise() {
1390
- const deferred = new Deferred_default();
1391
- if (!this.isInTheFuture) {
1392
- deferred.resolve();
1393
- } else {
1394
- this.distanceFromNow().timeout(() => deferred.resolve());
1395
- }
1396
- return deferred.asCancelablePromise;
1594
+ this.ensureInTheFuture();
1595
+ return this.distanceFromNow().promise();
1397
1596
  }
1398
1597
  delay(cb) {
1399
- const deferred = this.promise();
1400
- void deferred.then(() => {
1401
- cb();
1402
- }, (_err) => {
1403
- return;
1404
- });
1405
- return { cancel: () => deferred.cancel() };
1598
+ this.ensureInTheFuture();
1599
+ return this.distanceFromNow().delay(cb);
1600
+ }
1601
+ ensureInTheFuture() {
1602
+ if (!this.isInTheFuture)
1603
+ throw new Error("Instant is in the past");
1604
+ }
1605
+ ensureInThePast() {
1606
+ if (!this.isInThePast)
1607
+ throw new Error("Instant is in the future");
1406
1608
  }
1407
1609
  isToday() {
1408
1610
  return Math.floor(this.days) === Math.floor(_TimeInstant.now().days);
1409
1611
  }
1612
+ /**
1613
+ * @returns the time as HH:mm:ss
1614
+ * @deprecated [2024-12-11] this method is too ambigous and should be removed.
1615
+ */
1410
1616
  asTimeString() {
1411
- const date = this.asDate();
1412
- return `${this.doGetTwoDigitsHours(date)}:${this.doGetTwoDigitsMinutes(date)}:${this.doGetTwoDigitsSeconds(date)}`;
1617
+ return this.format("HH:mm:ss");
1413
1618
  }
1619
+ /**
1620
+ * @returns the date as dd/MM/yyyy
1621
+ * @deprecated [2024-12-11] this method is too ambigous and should be removed.
1622
+ */
1414
1623
  asDateString() {
1415
- const date = this.asDate();
1416
- return `${this.doGetTwoDigitsDays(date)}/${this.doGetTwoDigitsMonths(date)}/${this.doGetFourDigitsYears(date)}`;
1624
+ return this.format("dd/MM/yyyy");
1417
1625
  }
1418
1626
  /**
1419
- * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024+0200). The format is meant to always be realiable.
1420
- */
1421
- asIso8601() {
1422
- const dash = "-", colon = ".", doublecolon = ":", T = "T", date = this.asDate();
1423
- return this.doGetFourDigitsYears(date) + dash + this.doGetTwoDigitsMonths(date) + dash + this.doGetTwoDigitsDays(date) + T + this.doGetTwoDigitsHours(date) + doublecolon + this.doGetTwoDigitsMinutes(date) + doublecolon + this.doGetTwoDigitsSeconds(date) + colon + this.doGetThreeDigitsMilliseconds(date) + this.doGetFourDigitsTimezoneOffset(date);
1627
+ * Formats this instant using the given pattern. The pattern can contain the following tokens:
1628
+ *
1629
+ * | Token | Description | Example |
1630
+ * |:------|:--------------------------------|:------------------------------|
1631
+ * | D | Weekday, 1 letter | W |
1632
+ * | DD | Weekday, 3 letters | Wed |
1633
+ * | DDD | Weekday, long | Wednesday |
1634
+ * | d | Day of the month, no padding | 3 |
1635
+ * | dd | Day of the month, padded to 2 | 03 |
1636
+ * | M | Month, numeric | 3 |
1637
+ * | MM | Month, 2 digits | 03 |
1638
+ * | MMM | Month, 3 letters | Mar |
1639
+ * | MMMM | Month, long | March |
1640
+ * | y | Year, numeric | 2021 |
1641
+ * | yy | Year, 2 digits | 21 |
1642
+ * | yyyy | Year, numeric | 2021 |
1643
+ * | h | Hours, no padding | 6 |
1644
+ * | hh | Hours, padded to 2 | 06 |
1645
+ * | H | Hours in 24-format, no padding | 18 |
1646
+ * | HH | Hours in 24-format, padded to 2 | 18 |
1647
+ * | m | Minutes, no padding | 7 |
1648
+ * | m | Minutes, padded to 2 | 07 |
1649
+ * | s | Seconds, no padding | 8 |
1650
+ * | ss | Seconds, padded to 2 | 08 |
1651
+ * | S | Milliseconds, no padding | 9 |
1652
+ * | SS | Milliseconds, padded to 2 | 09 |
1653
+ * | SSS | Milliseconds, padded to 3 | 009 |
1654
+ * | G | Era, narrow | A |
1655
+ * | GG | Era, short | AD |
1656
+ * | GGG | Era, long | Anno Domino |
1657
+ * | Z | Time zone, short | GMT+1 |
1658
+ * | ZZ | Time short, long C | entral European Standard Time |
1659
+ * | P | Period of the day, narrow | in the morning |
1660
+ * | PP | Period of the day, short | in the morning |
1661
+ * | PPP | Period of the day, long | in the morning |
1662
+ * | a | Meridiem | pm |
1663
+ * @param pattern The pattern to use. Refer to the token table above for details.
1664
+ * @param config An optional locale and timeZone definition to use during the format.
1665
+ * @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
1666
+ */
1667
+ format(pattern, config = {}) {
1668
+ return (0, import_small_date.format)(this.toDate(), pattern, config);
1424
1669
  }
1425
1670
  /**
1426
- * @returns this instant, in ISO 8601 format and UTC time zone (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
1427
- */
1428
- asIso8601UTC() {
1429
- const dash = "-", colon = ".", doublecolon = ":", T = "T", utcDate = this.asDateUTC();
1430
- return this.doGetFourDigitsYears(utcDate) + dash + this.doGetTwoDigitsMonths(utcDate) + dash + this.doGetTwoDigitsDays(utcDate) + T + this.doGetTwoDigitsHours(utcDate) + doublecolon + this.doGetTwoDigitsMinutes(utcDate) + doublecolon + this.doGetTwoDigitsSeconds(utcDate) + colon + this.doGetThreeDigitsMilliseconds(utcDate) + "Z";
1671
+ * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
1672
+ */
1673
+ asIso8601() {
1674
+ return this.format('yyyy-MM-dd"T"HH:mm:ss.SSS"Z"', { timeZone: "UTC" });
1431
1675
  }
1432
1676
  /**
1433
1677
  * @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
1678
+ * @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
1434
1679
  */
1435
1680
  asHumanTimestamp() {
1436
- const dash = "-", doublecolon = ":", space = " ", T = "T", date = this.asDate();
1437
- return this.doGetFourDigitsYears(date) + dash + this.doGetTwoDigitsMonths(date) + dash + this.doGetTwoDigitsDays(date) + space + this.doGetTwoDigitsHours(date) + doublecolon + this.doGetTwoDigitsMinutes(date) + doublecolon + this.doGetTwoDigitsSeconds(date);
1438
- }
1439
- // Please do not use this method internally, as it is not optimized for continued usage.
1440
- get twoDigitsDays() {
1441
- return this.doGetTwoDigitsDays(this.asDate());
1442
- }
1443
- // Please do not use this method internally, as it is not optimized for continued usage.
1444
- get twoDigitsMonths() {
1445
- return this.doGetTwoDigitsMonths(this.asDate());
1446
- }
1447
- // Please do not use this method internally, as it is not optimized for continued usage.
1448
- get fourDigitsYears() {
1449
- return this.doGetFourDigitsYears(this.asDate());
1450
- }
1451
- // Please do not use this method internally, as it is not optimized for continued usage.
1452
- get twoDigitsHours() {
1453
- return this.doGetTwoDigitsHours(this.asDate());
1454
- }
1455
- // Please do not use this method internally, as it is not optimized for continued usage.
1456
- get twoDigitsMinutes() {
1457
- return this.doGetTwoDigitsMinutes(this.asDate());
1458
- }
1459
- // Please do not use this method internally, as it is not optimized for continued usage.
1460
- get twoDigitsSeconds() {
1461
- return this.doGetTwoDigitsSeconds(this.asDate());
1462
- }
1463
- // Please do not use this method internally, as it is not optimized for continued usage.
1464
- get threeDigitsMilliseconds() {
1465
- return this.doGetThreeDigitsMilliseconds(this.asDate());
1466
- }
1467
- // Please do not use this method internally, as it is not optimized for continued usage.
1468
- get twoDigitsDaysUTC() {
1469
- return this.doGetTwoDigitsDays(this.asDateUTC());
1470
- }
1471
- // Please do not use this method internally, as it is not optimized for continued usage.
1472
- get twoDigitsMonthsUTC() {
1473
- return this.doGetTwoDigitsMonths(this.asDateUTC());
1474
- }
1475
- // Please do not use this method internally, as it is not optimized for continued usage.
1476
- get fourDigitsYearsUTC() {
1477
- return this.doGetFourDigitsYears(this.asDateUTC());
1478
- }
1479
- // Please do not use this method internally, as it is not optimized for continued usage.
1480
- get twoDigitsHoursUTC() {
1481
- return this.doGetTwoDigitsHours(this.asDateUTC());
1482
- }
1483
- // Please do not use this method internally, as it is not optimized for continued usage.
1484
- get twoDigitsMinutesUTC() {
1485
- return this.doGetTwoDigitsMinutes(this.asDateUTC());
1486
- }
1487
- // Please do not use this method internally, as it is not optimized for continued usage.
1488
- get twoDigitsSecondsUTC() {
1489
- return this.doGetTwoDigitsSeconds(this.asDateUTC());
1490
- }
1491
- // Please do not use this method internally, as it is not optimized for continued usage.
1492
- get threeDigitsMillisecondsUTC() {
1493
- return this.doGetThreeDigitsMilliseconds(this.asDateUTC());
1494
- }
1495
- // Please do not use this method internally, as it is not optimized for continued usage.
1496
- get fourDigitsTimezoneOffset() {
1497
- const offset = this.asDate().getTimezoneOffset();
1498
- return (offset >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(offset) / 60).toString(), 2, "0") + pad((Math.abs(offset) % 60).toString(), 2, "0");
1499
- }
1500
- doGetTwoDigitsDays(date) {
1501
- return pad(date.getDate().toString(), 2, "0");
1502
- }
1503
- doGetTwoDigitsMonths(date) {
1504
- return pad((date.getMonth() + 1).toString(), 2, "0");
1505
- }
1506
- doGetFourDigitsYears(date) {
1507
- return pad(date.getFullYear().toString(), 4, "0");
1508
- }
1509
- doGetTwoDigitsHours(date) {
1510
- return pad(date.getHours().toString(), 2, "0");
1511
- }
1512
- doGetTwoDigitsMinutes(date) {
1513
- return pad(date.getMinutes().toString(), 2, "0");
1514
- }
1515
- doGetTwoDigitsSeconds(date) {
1516
- return pad(date.getSeconds().toString(), 2, "0");
1517
- }
1518
- doGetThreeDigitsMilliseconds(date) {
1519
- return pad(date.getMilliseconds().toString(), 3, "0");
1520
- }
1521
- doGetFourDigitsTimezoneOffset(date) {
1522
- const offset = date.getTimezoneOffset();
1523
- return (offset >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(offset) / 60).toString(), 2, "0") + pad((Math.abs(offset) % 60).toString(), 2, "0");
1681
+ return this.format("yyyy-MM-dd HH:mm:ss");
1524
1682
  }
1525
- asUnixTimestamp() {
1683
+ toUnixTimestamp() {
1526
1684
  return this.ms;
1527
1685
  }
1528
- asDate() {
1686
+ toDate() {
1529
1687
  return new Date(this.ms);
1530
1688
  }
1531
- asDateUTC() {
1689
+ toDateUTC() {
1532
1690
  return new Date(this.ms + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3);
1533
1691
  }
1534
1692
  get isInThePast() {
@@ -1649,23 +1807,23 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1649
1807
  return _TimeInstant.fromUnixTimestamp(timestamp2);
1650
1808
  }
1651
1809
  get dayOfMonth() {
1652
- return this.asDate().getDate();
1810
+ return this.toDate().getDate();
1653
1811
  }
1654
1812
  get dayOfWeek() {
1655
- return this.asDate().getDay() + 1;
1813
+ return this.toDate().getDay() + 1;
1656
1814
  }
1657
1815
  get month() {
1658
- return this.asDate().getMonth() + 1;
1816
+ return this.toDate().getMonth() + 1;
1659
1817
  }
1660
1818
  get year() {
1661
- return this.asDate().getFullYear();
1819
+ return this.toDate().getFullYear();
1662
1820
  }
1663
1821
  /**
1664
1822
  * Returns the week number represented by this instant, according to the ISO 8601 standard.
1665
1823
  * Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
1666
1824
  */
1667
1825
  get weekNumber() {
1668
- const date = this.asDate();
1826
+ const date = this.toDate();
1669
1827
  const oneDay = 1e3 * 60 * 60 * 24;
1670
1828
  const thursdayOfThisWeek = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 4 - (date.getDay() || 7), 14, 0, 0);
1671
1829
  const firstOfJanuary = new Date(thursdayOfThisWeek.getFullYear(), 0, 1, 14, 0, 0);
@@ -2517,6 +2675,7 @@ export {
2517
2675
  sum,
2518
2676
  sumBy,
2519
2677
  throttle,
2678
+ tryToParseJson,
2520
2679
  uniq,
2521
2680
  uniqBy,
2522
2681
  uniqByKey,