@zelgadis87/utils-core 4.1.1 → 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.cjs CHANGED
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,8 +20,154 @@ var __copyProps = (to, from, except, desc) => {
15
20
  }
16
21
  return to;
17
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
18
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
32
 
33
+ // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
34
+ var require_format = __commonJS({
35
+ "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports2) {
36
+ "use strict";
37
+ Object.defineProperty(exports2, "__esModule", {
38
+ value: true
39
+ });
40
+ exports2["default"] = format2;
41
+ function ownKeys(object, enumerableOnly) {
42
+ var keys = Object.keys(object);
43
+ if (Object.getOwnPropertySymbols) {
44
+ var symbols = Object.getOwnPropertySymbols(object);
45
+ if (enumerableOnly) {
46
+ symbols = symbols.filter(function(sym) {
47
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
48
+ });
49
+ }
50
+ keys.push.apply(keys, symbols);
51
+ }
52
+ return keys;
53
+ }
54
+ function _objectSpread(target) {
55
+ for (var i = 1; i < arguments.length; i++) {
56
+ var source = arguments[i] != null ? arguments[i] : {};
57
+ if (i % 2) {
58
+ ownKeys(Object(source), true).forEach(function(key) {
59
+ _defineProperty(target, key, source[key]);
60
+ });
61
+ } else if (Object.getOwnPropertyDescriptors) {
62
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
63
+ } else {
64
+ ownKeys(Object(source)).forEach(function(key) {
65
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
66
+ });
67
+ }
68
+ }
69
+ return target;
70
+ }
71
+ function _defineProperty(obj, key, value) {
72
+ if (key in obj) {
73
+ Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
74
+ } else {
75
+ obj[key] = value;
76
+ }
77
+ return obj;
78
+ }
79
+ var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
80
+ var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
81
+ var optionNames = {
82
+ y: "year",
83
+ M: "month",
84
+ d: "day",
85
+ D: "weekday",
86
+ S: "fractionalSecondDigits",
87
+ G: "era",
88
+ Z: "timeZoneName",
89
+ P: "dayPeriod",
90
+ a: "hour12",
91
+ h: "hour",
92
+ H: "hour",
93
+ m: "minute",
94
+ s: "second"
95
+ };
96
+ var values = {
97
+ y: ["numeric", "2-digit", void 0, "numeric"],
98
+ M: ["narrow", "2-digit", "short", "long"],
99
+ d: ["numeric", "2-digit"],
100
+ D: ["narrow", "short", "long"],
101
+ S: [1, 2, 3],
102
+ G: ["narrow", "short", "long"],
103
+ Z: ["short", "long"],
104
+ P: ["narrow", "short", "long"],
105
+ a: [true],
106
+ h: ["numeric", "2-digit"],
107
+ H: ["numeric", "2-digit"],
108
+ m: ["numeric", "2-digit"],
109
+ s: ["numeric", "2-digit"]
110
+ };
111
+ function padIf(condition, value, length) {
112
+ return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
113
+ }
114
+ function formatType(date, type, length) {
115
+ var _options;
116
+ var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
117
+ var option = optionNames[type];
118
+ var value = values[type][length - 1];
119
+ if (!value) {
120
+ return;
121
+ }
122
+ var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
123
+ if (type === "a") {
124
+ return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
125
+ hour: "numeric"
126
+ })).formatToParts(date).pop().value;
127
+ }
128
+ if (type === "G" || type === "Z") {
129
+ return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
130
+ }
131
+ if (type === "H" || type === "h") {
132
+ return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
133
+ hourCycle: type === "H" ? "h23" : "h11"
134
+ })).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
135
+ }
136
+ return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
137
+ }
138
+ function format2(date, pattern, config) {
139
+ return pattern.split(ESCAPE_REGEX).filter(function(sub) {
140
+ return sub !== void 0;
141
+ }).map(function(sub, index) {
142
+ if (index % 2 !== 0) {
143
+ return sub;
144
+ }
145
+ return sub.replace(PATTERN_REGEX, function(match) {
146
+ var type = match.charAt(0);
147
+ return formatType(date, type, match.length, config) || match;
148
+ });
149
+ }).join("");
150
+ }
151
+ }
152
+ });
153
+
154
+ // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
155
+ var require_lib = __commonJS({
156
+ "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports2) {
157
+ "use strict";
158
+ Object.defineProperty(exports2, "__esModule", {
159
+ value: true
160
+ });
161
+ exports2.format = void 0;
162
+ var _format = require_format();
163
+ var _format2 = _interopRequireDefault(_format);
164
+ function _interopRequireDefault(obj) {
165
+ return obj && obj.__esModule ? obj : { "default": obj };
166
+ }
167
+ exports2.format = _format2["default"];
168
+ }
169
+ });
170
+
20
171
  // src/index.ts
21
172
  var src_exports = {};
22
173
  __export(src_exports, {
@@ -139,6 +290,7 @@ __export(src_exports, {
139
290
  sum: () => sum,
140
291
  sumBy: () => sumBy,
141
292
  throttle: () => throttle,
293
+ tryToParseJson: () => tryToParseJson,
142
294
  uniq: () => uniq,
143
295
  uniqBy: () => uniqBy,
144
296
  uniqByKey: () => uniqByKey,
@@ -236,6 +388,16 @@ function isFunction(t) {
236
388
  return typeof t === "function";
237
389
  }
238
390
 
391
+ // src/types/json.ts
392
+ function tryToParseJson(jsonContent) {
393
+ try {
394
+ const data = JSON.parse(jsonContent);
395
+ return [data, null];
396
+ } catch (err) {
397
+ return [null, asError(err)];
398
+ }
399
+ }
400
+
239
401
  // src/types/nulls.ts
240
402
  function ensureDefined(v, name = "value") {
241
403
  if (isDefined(v))
@@ -582,6 +744,127 @@ var LazyAsync = class _LazyAsync {
582
744
  }
583
745
  };
584
746
 
747
+ // src/time/TimeInstant.ts
748
+ var import_small_date = __toESM(require_lib());
749
+
750
+ // src/time/TimeUnit.ts
751
+ var TimeUnit = class _TimeUnit {
752
+ constructor(multiplier) {
753
+ this.multiplier = multiplier;
754
+ }
755
+ toUnit(value, unit) {
756
+ return value * (this.multiplier / unit.multiplier);
757
+ }
758
+ toMs(value) {
759
+ return this.toUnit(value, _TimeUnit.MILLISECONDS);
760
+ }
761
+ toSeconds(value) {
762
+ return this.toUnit(value, _TimeUnit.SECONDS);
763
+ }
764
+ toMinutes(value) {
765
+ return this.toUnit(value, _TimeUnit.MINUTES);
766
+ }
767
+ toHours(value) {
768
+ return this.toUnit(value, _TimeUnit.HOURS);
769
+ }
770
+ toDays(value) {
771
+ return this.toUnit(value, _TimeUnit.DAYS);
772
+ }
773
+ toWeeks(value) {
774
+ return this.toUnit(value, _TimeUnit.WEEKS);
775
+ }
776
+ static MILLISECONDS = new _TimeUnit(1);
777
+ static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
778
+ static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
779
+ static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
780
+ static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
781
+ static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
782
+ };
783
+
784
+ // src/time/TimeBase.ts
785
+ var TimeBase = class {
786
+ _ms;
787
+ constructor(value, unit) {
788
+ this._ms = unit.toMs(value);
789
+ }
790
+ get ms() {
791
+ return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
792
+ }
793
+ get seconds() {
794
+ return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
795
+ }
796
+ get minutes() {
797
+ return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
798
+ }
799
+ get hours() {
800
+ return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
801
+ }
802
+ get days() {
803
+ return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
804
+ }
805
+ addMs(milliseconds) {
806
+ return this.addUnits(milliseconds, TimeUnit.MILLISECONDS);
807
+ }
808
+ addSeconds(seconds) {
809
+ return this.addUnits(seconds, TimeUnit.SECONDS);
810
+ }
811
+ addMinutes(minutes) {
812
+ return this.addUnits(minutes, TimeUnit.MINUTES);
813
+ }
814
+ addHours(hours) {
815
+ return this.addUnits(hours, TimeUnit.HOURS);
816
+ }
817
+ addDays(days) {
818
+ return this.addUnits(days, TimeUnit.DAYS);
819
+ }
820
+ removeDays(days) {
821
+ return this.removeUnits(days, TimeUnit.DAYS);
822
+ }
823
+ addUnits(n, unit) {
824
+ return this.create(this._ms + unit.toMs(n), TimeUnit.MILLISECONDS);
825
+ }
826
+ removeMs(milliseconds) {
827
+ return this.addUnits(-milliseconds, TimeUnit.MILLISECONDS);
828
+ }
829
+ removeSeconds(seconds) {
830
+ return this.addUnits(-seconds, TimeUnit.SECONDS);
831
+ }
832
+ removeMinutes(minutes) {
833
+ return this.addUnits(-minutes, TimeUnit.MINUTES);
834
+ }
835
+ removeHours(hours) {
836
+ return this.addUnits(-hours, TimeUnit.HOURS);
837
+ }
838
+ removeUnits(n, unit) {
839
+ return this.addUnits(-n, unit);
840
+ }
841
+ getUnit(unit) {
842
+ return this._ms / unit.multiplier;
843
+ }
844
+ toUnits() {
845
+ return {
846
+ days: Math.floor(this._ms / TimeUnit.DAYS.multiplier),
847
+ hours: Math.floor(this._ms / TimeUnit.HOURS.multiplier % 24),
848
+ minutes: Math.floor(this._ms / TimeUnit.MINUTES.multiplier % 60),
849
+ seconds: Math.floor(this._ms / TimeUnit.SECONDS.multiplier % 60)
850
+ };
851
+ }
852
+ static toMs(units) {
853
+ if (!units)
854
+ throw new Error("Invalid units given");
855
+ let ms = 0;
856
+ ms += units.ms ?? 0 * TimeUnit.MILLISECONDS.multiplier;
857
+ ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
858
+ ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
859
+ ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
860
+ ms += (units.days ?? 0) * TimeUnit.DAYS.multiplier;
861
+ return ms;
862
+ }
863
+ toJSON() {
864
+ return this._ms;
865
+ }
866
+ };
867
+
585
868
  // src/async/Deferred.ts
586
869
  var DeferredCanceledError = class extends Error {
587
870
  constructor() {
@@ -667,6 +950,16 @@ var Deferred = class {
667
950
  };
668
951
  var Deferred_default = Deferred;
669
952
 
953
+ // src/random/randomInterval.ts
954
+ function randomInterval(min2, max2) {
955
+ return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
956
+ }
957
+
958
+ // src/random/randomPercentage.ts
959
+ function randomPercentage(min2, max2) {
960
+ return randomInterval(min2, max2) / 100;
961
+ }
962
+
670
963
  // src/utils/bindThis.ts
671
964
  function bindThis(fn, _this) {
672
965
  return fn.bind(_this);
@@ -1039,134 +1332,6 @@ function wrap(str, delimiter) {
1039
1332
  return delimiter + str + delimiter;
1040
1333
  }
1041
1334
 
1042
- // src/time/TimeUnit.ts
1043
- var TimeUnit = class _TimeUnit {
1044
- constructor(multiplier) {
1045
- this.multiplier = multiplier;
1046
- }
1047
- toUnit(value, unit) {
1048
- return value * (this.multiplier / unit.multiplier);
1049
- }
1050
- toMs(value) {
1051
- return this.toUnit(value, _TimeUnit.MILLISECONDS);
1052
- }
1053
- toSeconds(value) {
1054
- return this.toUnit(value, _TimeUnit.SECONDS);
1055
- }
1056
- toMinutes(value) {
1057
- return this.toUnit(value, _TimeUnit.MINUTES);
1058
- }
1059
- toHours(value) {
1060
- return this.toUnit(value, _TimeUnit.HOURS);
1061
- }
1062
- toDays(value) {
1063
- return this.toUnit(value, _TimeUnit.DAYS);
1064
- }
1065
- toWeeks(value) {
1066
- return this.toUnit(value, _TimeUnit.WEEKS);
1067
- }
1068
- static MILLISECONDS = new _TimeUnit(1);
1069
- static SECONDS = new _TimeUnit(1e3 * _TimeUnit.MILLISECONDS.multiplier);
1070
- static MINUTES = new _TimeUnit(60 * _TimeUnit.SECONDS.multiplier);
1071
- static HOURS = new _TimeUnit(60 * _TimeUnit.MINUTES.multiplier);
1072
- static DAYS = new _TimeUnit(24 * _TimeUnit.HOURS.multiplier);
1073
- static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
1074
- };
1075
-
1076
- // src/time/TimeBase.ts
1077
- var TimeBase = class {
1078
- _ms;
1079
- constructor(value, unit) {
1080
- this._ms = unit.toMs(value);
1081
- }
1082
- get ms() {
1083
- return Math.floor(this._ms / TimeUnit.MILLISECONDS.multiplier);
1084
- }
1085
- get seconds() {
1086
- return Math.floor(this._ms / TimeUnit.SECONDS.multiplier);
1087
- }
1088
- get minutes() {
1089
- return Math.floor(this._ms / TimeUnit.MINUTES.multiplier);
1090
- }
1091
- get hours() {
1092
- return Math.floor(this._ms / TimeUnit.HOURS.multiplier);
1093
- }
1094
- get days() {
1095
- return Math.floor(this._ms / TimeUnit.DAYS.multiplier);
1096
- }
1097
- addMs(milliseconds) {
1098
- return this.addUnits(milliseconds, TimeUnit.MILLISECONDS);
1099
- }
1100
- addSeconds(seconds) {
1101
- return this.addUnits(seconds, TimeUnit.SECONDS);
1102
- }
1103
- addMinutes(minutes) {
1104
- return this.addUnits(minutes, TimeUnit.MINUTES);
1105
- }
1106
- addHours(hours) {
1107
- return this.addUnits(hours, TimeUnit.HOURS);
1108
- }
1109
- addDays(days) {
1110
- return this.addUnits(days, TimeUnit.DAYS);
1111
- }
1112
- removeDays(days) {
1113
- return this.removeUnits(days, TimeUnit.DAYS);
1114
- }
1115
- addUnits(n, unit) {
1116
- return this.create(this._ms + unit.toMs(n), TimeUnit.MILLISECONDS);
1117
- }
1118
- removeMs(milliseconds) {
1119
- return this.addUnits(-milliseconds, TimeUnit.MILLISECONDS);
1120
- }
1121
- removeSeconds(seconds) {
1122
- return this.addUnits(-seconds, TimeUnit.SECONDS);
1123
- }
1124
- removeMinutes(minutes) {
1125
- return this.addUnits(-minutes, TimeUnit.MINUTES);
1126
- }
1127
- removeHours(hours) {
1128
- return this.addUnits(-hours, TimeUnit.HOURS);
1129
- }
1130
- removeUnits(n, unit) {
1131
- return this.addUnits(-n, unit);
1132
- }
1133
- getUnit(unit) {
1134
- return this._ms / unit.multiplier;
1135
- }
1136
- toUnits() {
1137
- return {
1138
- days: Math.floor(this._ms / TimeUnit.DAYS.multiplier),
1139
- hours: Math.floor(this._ms / TimeUnit.HOURS.multiplier % 24),
1140
- minutes: Math.floor(this._ms / TimeUnit.MINUTES.multiplier % 60),
1141
- seconds: Math.floor(this._ms / TimeUnit.SECONDS.multiplier % 60)
1142
- };
1143
- }
1144
- static toMs(units) {
1145
- if (!units)
1146
- throw new Error("Invalid units given");
1147
- let ms = 0;
1148
- ms += units.ms ?? 0 * TimeUnit.MILLISECONDS.multiplier;
1149
- ms += (units.seconds ?? 0) * TimeUnit.SECONDS.multiplier;
1150
- ms += (units.minutes ?? 0) * TimeUnit.MINUTES.multiplier;
1151
- ms += (units.hours ?? 0) * TimeUnit.HOURS.multiplier;
1152
- ms += (units.days ?? 0) * TimeUnit.DAYS.multiplier;
1153
- return ms;
1154
- }
1155
- toJSON() {
1156
- return this._ms;
1157
- }
1158
- };
1159
-
1160
- // src/random/randomInterval.ts
1161
- function randomInterval(min2, max2) {
1162
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
1163
- }
1164
-
1165
- // src/random/randomPercentage.ts
1166
- function randomPercentage(min2, max2) {
1167
- return randomInterval(min2, max2) / 100;
1168
- }
1169
-
1170
1335
  // src/time/TimeDuration.ts
1171
1336
  var TimeDuration = class _TimeDuration extends TimeBase {
1172
1337
  constructor(value, unit) {
@@ -1207,14 +1372,14 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1207
1372
  * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1208
1373
  */
1209
1374
  get formatted() {
1210
- const format = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1375
+ const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1211
1376
  const units = this.toUnits();
1212
1377
  if (units.days >= 1)
1213
- return format(units.days, "d", units.hours, "h");
1378
+ return format2(units.days, "d", units.hours, "h");
1214
1379
  else if (units.hours >= 1)
1215
- return format(units.hours, "h", units.minutes, "m");
1380
+ return format2(units.hours, "h", units.minutes, "m");
1216
1381
  else if (units.minutes >= 1)
1217
- return format(units.minutes, "m", units.seconds, "s");
1382
+ return format2(units.minutes, "m", units.seconds, "s");
1218
1383
  else if (units.seconds >= 0)
1219
1384
  return units.seconds.toString() + "s";
1220
1385
  else if (units.seconds > -60)
@@ -1247,8 +1412,10 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1247
1412
  const deferred = this.promise();
1248
1413
  void deferred.then(() => {
1249
1414
  cb();
1250
- }, (_err) => {
1251
- return;
1415
+ }, (err) => {
1416
+ if (err instanceof DeferredCanceledError)
1417
+ return;
1418
+ throw err;
1252
1419
  });
1253
1420
  return { cancel: () => deferred.cancel() };
1254
1421
  }
@@ -1447,7 +1614,7 @@ var timeInstantResolveValue = (getFromDate2, referenceDate, x) => {
1447
1614
  if (relativeTo === void 0 || relativeTo === "now") {
1448
1615
  return getFromDate2(referenceDate) + relative;
1449
1616
  } else {
1450
- return getFromDate2(relativeTo.asDateUTC()) + relative;
1617
+ return getFromDate2(relativeTo.toDate()) + relative;
1451
1618
  }
1452
1619
  } else if ("absolute" in x) {
1453
1620
  return x.absolute;
@@ -1466,7 +1633,7 @@ var getFromDate = {
1466
1633
  };
1467
1634
  var toReferenceDate = (x) => {
1468
1635
  ensureDefined(x);
1469
- if (isTimeInstant(x)) return x.asDateUTC();
1636
+ if (isTimeInstant(x)) return x.toDate();
1470
1637
  return x;
1471
1638
  };
1472
1639
  function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
@@ -1486,7 +1653,7 @@ function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInsta
1486
1653
  return TimeInstant.fromUnixTimestamp(timestamp2);
1487
1654
  }
1488
1655
  function timeInstantBuilder() {
1489
- let referenceDate = TimeInstant.now().asDateUTC();
1656
+ let referenceDate = TimeInstant.now().toDate();
1490
1657
  const value = { ...defaultTimeInstantCreationParameters };
1491
1658
  const ret = {
1492
1659
  year: (x) => {
@@ -1562,157 +1729,103 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1562
1729
  atEndOfDay() {
1563
1730
  return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
1564
1731
  }
1565
- /** @deprecated[2024-10-24]: Use #promise() instead. */
1566
- timeout(cb) {
1567
- if (!this.isInTheFuture) {
1568
- throw new Error("Instant is in the past");
1569
- } else {
1570
- return this.distanceFromNow().timeout(() => cb());
1571
- }
1572
- }
1573
1732
  promise() {
1574
- const deferred = new Deferred_default();
1575
- if (!this.isInTheFuture) {
1576
- deferred.resolve();
1577
- } else {
1578
- this.distanceFromNow().timeout(() => deferred.resolve());
1579
- }
1580
- return deferred.asCancelablePromise;
1733
+ this.ensureInTheFuture();
1734
+ return this.distanceFromNow().promise();
1581
1735
  }
1582
1736
  delay(cb) {
1583
- const deferred = this.promise();
1584
- void deferred.then(() => {
1585
- cb();
1586
- }, (_err) => {
1587
- return;
1588
- });
1589
- return { cancel: () => deferred.cancel() };
1737
+ this.ensureInTheFuture();
1738
+ return this.distanceFromNow().delay(cb);
1739
+ }
1740
+ ensureInTheFuture() {
1741
+ if (!this.isInTheFuture)
1742
+ throw new Error("Instant is in the past");
1743
+ }
1744
+ ensureInThePast() {
1745
+ if (!this.isInThePast)
1746
+ throw new Error("Instant is in the future");
1590
1747
  }
1591
1748
  isToday() {
1592
1749
  return Math.floor(this.days) === Math.floor(_TimeInstant.now().days);
1593
1750
  }
1751
+ /**
1752
+ * @returns the time as HH:mm:ss
1753
+ * @deprecated [2024-12-11] this method is too ambigous and should be removed.
1754
+ */
1594
1755
  asTimeString() {
1595
- const date = this.asDate();
1596
- return `${this.doGetTwoDigitsHours(date)}:${this.doGetTwoDigitsMinutes(date)}:${this.doGetTwoDigitsSeconds(date)}`;
1756
+ return this.format("HH:mm:ss");
1597
1757
  }
1758
+ /**
1759
+ * @returns the date as dd/MM/yyyy
1760
+ * @deprecated [2024-12-11] this method is too ambigous and should be removed.
1761
+ */
1598
1762
  asDateString() {
1599
- const date = this.asDate();
1600
- return `${this.doGetTwoDigitsDays(date)}/${this.doGetTwoDigitsMonths(date)}/${this.doGetFourDigitsYears(date)}`;
1763
+ return this.format("dd/MM/yyyy");
1601
1764
  }
1602
1765
  /**
1603
- * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024+0200). The format is meant to always be realiable.
1604
- */
1605
- asIso8601() {
1606
- const dash = "-", colon = ".", doublecolon = ":", T = "T", date = this.asDate();
1607
- 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);
1766
+ * Formats this instant using the given pattern. The pattern can contain the following tokens:
1767
+ *
1768
+ * | Token | Description | Example |
1769
+ * |:------|:--------------------------------|:------------------------------|
1770
+ * | D | Weekday, 1 letter | W |
1771
+ * | DD | Weekday, 3 letters | Wed |
1772
+ * | DDD | Weekday, long | Wednesday |
1773
+ * | d | Day of the month, no padding | 3 |
1774
+ * | dd | Day of the month, padded to 2 | 03 |
1775
+ * | M | Month, numeric | 3 |
1776
+ * | MM | Month, 2 digits | 03 |
1777
+ * | MMM | Month, 3 letters | Mar |
1778
+ * | MMMM | Month, long | March |
1779
+ * | y | Year, numeric | 2021 |
1780
+ * | yy | Year, 2 digits | 21 |
1781
+ * | yyyy | Year, numeric | 2021 |
1782
+ * | h | Hours, no padding | 6 |
1783
+ * | hh | Hours, padded to 2 | 06 |
1784
+ * | H | Hours in 24-format, no padding | 18 |
1785
+ * | HH | Hours in 24-format, padded to 2 | 18 |
1786
+ * | m | Minutes, no padding | 7 |
1787
+ * | m | Minutes, padded to 2 | 07 |
1788
+ * | s | Seconds, no padding | 8 |
1789
+ * | ss | Seconds, padded to 2 | 08 |
1790
+ * | S | Milliseconds, no padding | 9 |
1791
+ * | SS | Milliseconds, padded to 2 | 09 |
1792
+ * | SSS | Milliseconds, padded to 3 | 009 |
1793
+ * | G | Era, narrow | A |
1794
+ * | GG | Era, short | AD |
1795
+ * | GGG | Era, long | Anno Domino |
1796
+ * | Z | Time zone, short | GMT+1 |
1797
+ * | ZZ | Time short, long C | entral European Standard Time |
1798
+ * | P | Period of the day, narrow | in the morning |
1799
+ * | PP | Period of the day, short | in the morning |
1800
+ * | PPP | Period of the day, long | in the morning |
1801
+ * | a | Meridiem | pm |
1802
+ * @param pattern The pattern to use. Refer to the token table above for details.
1803
+ * @param config An optional locale and timeZone definition to use during the format.
1804
+ * @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
1805
+ */
1806
+ format(pattern, config = {}) {
1807
+ return (0, import_small_date.format)(this.toDate(), pattern, config);
1608
1808
  }
1609
1809
  /**
1610
- * @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.
1611
- */
1612
- asIso8601UTC() {
1613
- const dash = "-", colon = ".", doublecolon = ":", T = "T", utcDate = this.asDateUTC();
1614
- 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";
1810
+ * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
1811
+ */
1812
+ asIso8601() {
1813
+ return this.format('yyyy-MM-dd"T"HH:mm:ss.SSS"Z"', { timeZone: "UTC" });
1615
1814
  }
1616
1815
  /**
1617
1816
  * @returns this instant, in a human readable format. The format COULD change in the future, do NOT use this method for consistent outputs.
1817
+ * @deprecated [2024-12-11] this method is too broad and ambigous and should be removed.
1618
1818
  */
1619
1819
  asHumanTimestamp() {
1620
- const dash = "-", doublecolon = ":", space = " ", T = "T", date = this.asDate();
1621
- return this.doGetFourDigitsYears(date) + dash + this.doGetTwoDigitsMonths(date) + dash + this.doGetTwoDigitsDays(date) + space + this.doGetTwoDigitsHours(date) + doublecolon + this.doGetTwoDigitsMinutes(date) + doublecolon + this.doGetTwoDigitsSeconds(date);
1622
- }
1623
- // Please do not use this method internally, as it is not optimized for continued usage.
1624
- get twoDigitsDays() {
1625
- return this.doGetTwoDigitsDays(this.asDate());
1626
- }
1627
- // Please do not use this method internally, as it is not optimized for continued usage.
1628
- get twoDigitsMonths() {
1629
- return this.doGetTwoDigitsMonths(this.asDate());
1630
- }
1631
- // Please do not use this method internally, as it is not optimized for continued usage.
1632
- get fourDigitsYears() {
1633
- return this.doGetFourDigitsYears(this.asDate());
1634
- }
1635
- // Please do not use this method internally, as it is not optimized for continued usage.
1636
- get twoDigitsHours() {
1637
- return this.doGetTwoDigitsHours(this.asDate());
1638
- }
1639
- // Please do not use this method internally, as it is not optimized for continued usage.
1640
- get twoDigitsMinutes() {
1641
- return this.doGetTwoDigitsMinutes(this.asDate());
1642
- }
1643
- // Please do not use this method internally, as it is not optimized for continued usage.
1644
- get twoDigitsSeconds() {
1645
- return this.doGetTwoDigitsSeconds(this.asDate());
1646
- }
1647
- // Please do not use this method internally, as it is not optimized for continued usage.
1648
- get threeDigitsMilliseconds() {
1649
- return this.doGetThreeDigitsMilliseconds(this.asDate());
1650
- }
1651
- // Please do not use this method internally, as it is not optimized for continued usage.
1652
- get twoDigitsDaysUTC() {
1653
- return this.doGetTwoDigitsDays(this.asDateUTC());
1654
- }
1655
- // Please do not use this method internally, as it is not optimized for continued usage.
1656
- get twoDigitsMonthsUTC() {
1657
- return this.doGetTwoDigitsMonths(this.asDateUTC());
1658
- }
1659
- // Please do not use this method internally, as it is not optimized for continued usage.
1660
- get fourDigitsYearsUTC() {
1661
- return this.doGetFourDigitsYears(this.asDateUTC());
1662
- }
1663
- // Please do not use this method internally, as it is not optimized for continued usage.
1664
- get twoDigitsHoursUTC() {
1665
- return this.doGetTwoDigitsHours(this.asDateUTC());
1666
- }
1667
- // Please do not use this method internally, as it is not optimized for continued usage.
1668
- get twoDigitsMinutesUTC() {
1669
- return this.doGetTwoDigitsMinutes(this.asDateUTC());
1670
- }
1671
- // Please do not use this method internally, as it is not optimized for continued usage.
1672
- get twoDigitsSecondsUTC() {
1673
- return this.doGetTwoDigitsSeconds(this.asDateUTC());
1674
- }
1675
- // Please do not use this method internally, as it is not optimized for continued usage.
1676
- get threeDigitsMillisecondsUTC() {
1677
- return this.doGetThreeDigitsMilliseconds(this.asDateUTC());
1678
- }
1679
- // Please do not use this method internally, as it is not optimized for continued usage.
1680
- get fourDigitsTimezoneOffset() {
1681
- const offset = this.asDate().getTimezoneOffset();
1682
- return (offset >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(offset) / 60).toString(), 2, "0") + pad((Math.abs(offset) % 60).toString(), 2, "0");
1683
- }
1684
- doGetTwoDigitsDays(date) {
1685
- return pad(date.getDate().toString(), 2, "0");
1686
- }
1687
- doGetTwoDigitsMonths(date) {
1688
- return pad((date.getMonth() + 1).toString(), 2, "0");
1689
- }
1690
- doGetFourDigitsYears(date) {
1691
- return pad(date.getFullYear().toString(), 4, "0");
1692
- }
1693
- doGetTwoDigitsHours(date) {
1694
- return pad(date.getHours().toString(), 2, "0");
1695
- }
1696
- doGetTwoDigitsMinutes(date) {
1697
- return pad(date.getMinutes().toString(), 2, "0");
1698
- }
1699
- doGetTwoDigitsSeconds(date) {
1700
- return pad(date.getSeconds().toString(), 2, "0");
1701
- }
1702
- doGetThreeDigitsMilliseconds(date) {
1703
- return pad(date.getMilliseconds().toString(), 3, "0");
1704
- }
1705
- doGetFourDigitsTimezoneOffset(date) {
1706
- const offset = date.getTimezoneOffset();
1707
- return (offset >= 0 ? "+" : "-") + pad(Math.floor(Math.abs(offset) / 60).toString(), 2, "0") + pad((Math.abs(offset) % 60).toString(), 2, "0");
1820
+ return this.format("yyyy-MM-dd HH:mm:ss");
1708
1821
  }
1709
- asUnixTimestamp() {
1822
+ toUnixTimestamp() {
1710
1823
  return this.ms;
1711
1824
  }
1712
- asDate() {
1825
+ toDate() {
1713
1826
  return new Date(this.ms);
1714
1827
  }
1715
- asDateUTC() {
1828
+ toDateUTC() {
1716
1829
  return new Date(this.ms + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3);
1717
1830
  }
1718
1831
  get isInThePast() {
@@ -1833,23 +1946,23 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1833
1946
  return _TimeInstant.fromUnixTimestamp(timestamp2);
1834
1947
  }
1835
1948
  get dayOfMonth() {
1836
- return this.asDate().getDate();
1949
+ return this.toDate().getDate();
1837
1950
  }
1838
1951
  get dayOfWeek() {
1839
- return this.asDate().getDay() + 1;
1952
+ return this.toDate().getDay() + 1;
1840
1953
  }
1841
1954
  get month() {
1842
- return this.asDate().getMonth() + 1;
1955
+ return this.toDate().getMonth() + 1;
1843
1956
  }
1844
1957
  get year() {
1845
- return this.asDate().getFullYear();
1958
+ return this.toDate().getFullYear();
1846
1959
  }
1847
1960
  /**
1848
1961
  * Returns the week number represented by this instant, according to the ISO 8601 standard.
1849
1962
  * 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.
1850
1963
  */
1851
1964
  get weekNumber() {
1852
- const date = this.asDate();
1965
+ const date = this.toDate();
1853
1966
  const oneDay = 1e3 * 60 * 60 * 24;
1854
1967
  const thursdayOfThisWeek = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 4 - (date.getDay() || 7), 14, 0, 0);
1855
1968
  const firstOfJanuary = new Date(thursdayOfThisWeek.getFullYear(), 0, 1, 14, 0, 0);
@@ -2702,6 +2815,7 @@ function isUpgradable(obj) {
2702
2815
  sum,
2703
2816
  sumBy,
2704
2817
  throttle,
2818
+ tryToParseJson,
2705
2819
  uniq,
2706
2820
  uniqBy,
2707
2821
  uniqByKey,