@zelgadis87/utils-core 4.5.0 → 4.6.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.
Files changed (65) hide show
  1. package/esbuild/index.cjs +149 -249
  2. package/esbuild/{index.mjs → index.js} +147 -262
  3. package/esbuild/package.json +39 -0
  4. package/package.json +14 -102
  5. package/src/async/Semaphore.ts +8 -6
  6. package/src/time/TimeDuration.ts +22 -11
  7. package/src/time/TimeInstant.ts +38 -21
  8. package/src/utils/arrays/groupBy.ts +11 -11
  9. package/src/utils/random.ts +9 -3
  10. package/src/utils/records.ts +12 -0
  11. package/dist/Logger.d.ts +0 -21
  12. package/dist/Optional.d.ts +0 -70
  13. package/dist/async/CancelableDeferred.d.ts +0 -17
  14. package/dist/async/Deferred.d.ts +0 -34
  15. package/dist/async/RateThrottler.d.ts +0 -13
  16. package/dist/async/Semaphore.d.ts +0 -14
  17. package/dist/async/index.d.ts +0 -4
  18. package/dist/index.d.ts +0 -8
  19. package/dist/lazy/Lazy.d.ts +0 -22
  20. package/dist/lazy/LazyAsync.d.ts +0 -24
  21. package/dist/lazy/index.d.ts +0 -2
  22. package/dist/sorting/ComparisonChain.d.ts +0 -57
  23. package/dist/sorting/Sorter.d.ts +0 -100
  24. package/dist/sorting/index.d.ts +0 -4
  25. package/dist/sorting/types.d.ts +0 -5
  26. package/dist/time/RandomTimeDuration.d.ts +0 -9
  27. package/dist/time/TimeBase.d.ts +0 -38
  28. package/dist/time/TimeDuration.d.ts +0 -79
  29. package/dist/time/TimeFrequency.d.ts +0 -10
  30. package/dist/time/TimeInstant.d.ts +0 -171
  31. package/dist/time/TimeInstantBuilder.d.ts +0 -77
  32. package/dist/time/TimeRange.d.ts +0 -11
  33. package/dist/time/TimeUnit.d.ts +0 -17
  34. package/dist/time/index.d.ts +0 -7
  35. package/dist/time/types.d.ts +0 -26
  36. package/dist/tsconfig.tsbuildinfo +0 -1
  37. package/dist/upgrade/DataUpgrader.d.ts +0 -22
  38. package/dist/upgrade/errors.d.ts +0 -12
  39. package/dist/upgrade/getTransitionsPath.d.ts +0 -3
  40. package/dist/upgrade/index.d.ts +0 -2
  41. package/dist/upgrade/types.d.ts +0 -31
  42. package/dist/utils/arrays/groupBy.d.ts +0 -9
  43. package/dist/utils/arrays/indexBy.d.ts +0 -7
  44. package/dist/utils/arrays/statistics.d.ts +0 -8
  45. package/dist/utils/arrays/uniqBy.d.ts +0 -4
  46. package/dist/utils/arrays.d.ts +0 -57
  47. package/dist/utils/booleans.d.ts +0 -2
  48. package/dist/utils/empties.d.ts +0 -17
  49. package/dist/utils/errors/withTryCatch.d.ts +0 -3
  50. package/dist/utils/errors.d.ts +0 -3
  51. package/dist/utils/functions/constant.d.ts +0 -10
  52. package/dist/utils/functions/iff.d.ts +0 -8
  53. package/dist/utils/functions.d.ts +0 -31
  54. package/dist/utils/index.d.ts +0 -13
  55. package/dist/utils/json.d.ts +0 -11
  56. package/dist/utils/nulls.d.ts +0 -8
  57. package/dist/utils/numbers/round.d.ts +0 -8
  58. package/dist/utils/numbers.d.ts +0 -34
  59. package/dist/utils/primitives.d.ts +0 -3
  60. package/dist/utils/promises.d.ts +0 -6
  61. package/dist/utils/random.d.ts +0 -2
  62. package/dist/utils/records/entries.d.ts +0 -4
  63. package/dist/utils/records.d.ts +0 -21
  64. package/dist/utils/strings/StringParts.d.ts +0 -32
  65. package/dist/utils/strings.d.ts +0 -17
package/esbuild/index.cjs CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  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
- };
11
6
  var __export = (target, all) => {
12
7
  for (var name in all)
13
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,155 +15,9 @@ var __copyProps = (to, from, except, desc) => {
20
15
  }
21
16
  return to;
22
17
  };
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
- ));
31
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
19
 
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
-
171
- // src/index.ts
20
+ // packages/core/src/index.ts
172
21
  var src_exports = {};
173
22
  __export(src_exports, {
174
23
  ComparisonChain: () => ComparisonChain_default,
@@ -292,7 +141,9 @@ __export(src_exports, {
292
141
  pick: () => pick,
293
142
  pluralize: () => pluralize,
294
143
  promiseSequence: () => promiseSequence,
144
+ randomId: () => randomId,
295
145
  randomInterval: () => randomInterval,
146
+ randomNumberInInterval: () => randomNumberInInterval,
296
147
  randomPercentage: () => randomPercentage,
297
148
  range: () => range,
298
149
  repeat: () => repeat,
@@ -324,7 +175,7 @@ __export(src_exports, {
324
175
  });
325
176
  module.exports = __toCommonJS(src_exports);
326
177
 
327
- // src/async/Deferred.ts
178
+ // packages/core/src/async/Deferred.ts
328
179
  var DeferredCanceledError = class extends Error {
329
180
  constructor() {
330
181
  super("Execution canceled");
@@ -409,7 +260,7 @@ var Deferred = class {
409
260
  };
410
261
  var Deferred_default = Deferred;
411
262
 
412
- // src/async/RateThrottler.ts
263
+ // packages/core/src/async/RateThrottler.ts
413
264
  var RateThrottler = class {
414
265
  constructor(_frequency) {
415
266
  this._frequency = _frequency;
@@ -429,7 +280,8 @@ var RateThrottler = class {
429
280
  return slot.promise().then(() => fn());
430
281
  } finally {
431
282
  this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
432
- if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
283
+ if (this._waitingRequests.length > 0)
284
+ this._waitingRequests.shift().resolve();
433
285
  }
434
286
  };
435
287
  if (this._availableSlots.length > 0) {
@@ -448,7 +300,7 @@ function throttle(fn, frequence) {
448
300
  };
449
301
  }
450
302
 
451
- // src/async/Semaphore.ts
303
+ // packages/core/src/async/Semaphore.ts
452
304
  var Semaphore = class {
453
305
  constructor(_availableSlots = 1) {
454
306
  this._availableSlots = _availableSlots;
@@ -477,8 +329,8 @@ var Semaphore = class {
477
329
  }
478
330
  }
479
331
  async execute(fn, cooldown = TimeDuration.ZERO) {
480
- return this._awaitSlot().then(() => fn()).finally(() => {
481
- void cooldown.promise().then(() => this._releaseSlot());
332
+ return this._awaitSlot().then(fn).finally(() => {
333
+ void cooldown.delay(() => this._releaseSlot());
482
334
  });
483
335
  }
484
336
  get availableSlots() {
@@ -492,7 +344,7 @@ var Semaphore = class {
492
344
  }
493
345
  };
494
346
 
495
- // src/utils/nulls.ts
347
+ // packages/core/src/utils/nulls.ts
496
348
  function ensureDefined(v, name = "value") {
497
349
  if (isDefined(v))
498
350
  return v;
@@ -518,7 +370,7 @@ function ifNullOrUndefined(source, callback) {
518
370
  callback();
519
371
  }
520
372
 
521
- // src/utils/arrays/groupBy.ts
373
+ // packages/core/src/utils/arrays/groupBy.ts
522
374
  function groupByString(arr, field) {
523
375
  return groupByStringWith(arr, (t) => t[field]);
524
376
  }
@@ -544,7 +396,7 @@ function groupBySymbolWith(arr, getter) {
544
396
  return doGroupByWith(arr, getter);
545
397
  }
546
398
  function doGroupByWith(arr, getter) {
547
- return arr.reduce((dict, cur) => {
399
+ return [...arr].reduce((dict, cur) => {
548
400
  const key = getter(cur);
549
401
  if (key !== null && key !== void 0) {
550
402
  const arr2 = dict[key] ?? [];
@@ -555,7 +407,7 @@ function doGroupByWith(arr, getter) {
555
407
  }, {});
556
408
  }
557
409
 
558
- // src/utils/arrays/indexBy.ts
410
+ // packages/core/src/utils/arrays/indexBy.ts
559
411
  function indexByString(arr, field) {
560
412
  return indexByStringWith(arr, (t) => t[field]);
561
413
  }
@@ -583,7 +435,7 @@ function doIndexByWith(arr, getter) {
583
435
  }, {});
584
436
  }
585
437
 
586
- // src/utils/arrays/statistics.ts
438
+ // packages/core/src/utils/arrays/statistics.ts
587
439
  function average(arr) {
588
440
  const f = 1 / arr.length;
589
441
  return arr.reduce((tot, cur) => tot + cur * f, 0);
@@ -595,21 +447,23 @@ function sumBy(arr, getter) {
595
447
  return sum(arr.map(getter));
596
448
  }
597
449
  function min(arr) {
598
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
450
+ if (arr.length === 0)
451
+ throw new Error("Cannot calculate value on empty array");
599
452
  return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
600
453
  }
601
454
  function minBy(arr, getter) {
602
455
  return min(arr.map(getter));
603
456
  }
604
457
  function max(arr) {
605
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
458
+ if (arr.length === 0)
459
+ throw new Error("Cannot calculate value on empty array");
606
460
  return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
607
461
  }
608
462
  function maxBy(arr, getter) {
609
463
  return max(arr.map(getter));
610
464
  }
611
465
 
612
- // src/utils/functions/constant.ts
466
+ // packages/core/src/utils/functions/constant.ts
613
467
  function constant(v) {
614
468
  return () => v;
615
469
  }
@@ -624,7 +478,7 @@ var alwaysFalse = constantFalse;
624
478
  var constantZero = constant(0);
625
479
  var constantOne = constant(1);
626
480
 
627
- // src/utils/functions/iff.ts
481
+ // packages/core/src/utils/functions/iff.ts
628
482
  function iff(firstPredicate, valueIfTrue) {
629
483
  if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
630
484
  const ret = {
@@ -641,7 +495,7 @@ function iff(firstPredicate, valueIfTrue) {
641
495
  }
642
496
  }
643
497
 
644
- // src/utils/functions.ts
498
+ // packages/core/src/utils/functions.ts
645
499
  function isFunction(t) {
646
500
  return typeof t === "function";
647
501
  }
@@ -654,20 +508,24 @@ function not(predicate) {
654
508
  return (t) => !predicate(t);
655
509
  }
656
510
  function and(...predicates) {
657
- if (predicates.length === 0) return constantTrue;
658
- else if (predicates.length === 1) return predicates[0];
511
+ if (predicates.length === 0)
512
+ return constantTrue;
513
+ else if (predicates.length === 1)
514
+ return predicates[0];
659
515
  return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
660
516
  }
661
517
  function or(...predicates) {
662
- if (predicates.length === 0) return constantTrue;
663
- else if (predicates.length === 1) return predicates[0];
518
+ if (predicates.length === 0)
519
+ return constantTrue;
520
+ else if (predicates.length === 1)
521
+ return predicates[0];
664
522
  return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
665
523
  }
666
524
  function xor(a, b) {
667
525
  return (t) => a(t) !== b(t);
668
526
  }
669
527
 
670
- // src/utils/arrays/uniqBy.ts
528
+ // packages/core/src/utils/arrays/uniqBy.ts
671
529
  function uniq(arr) {
672
530
  return uniqBy(arr, identity);
673
531
  }
@@ -688,13 +546,15 @@ function uniqByKey(arr, key) {
688
546
  return uniqBy(arr, (item) => item[key]);
689
547
  }
690
548
 
691
- // src/utils/arrays.ts
549
+ // packages/core/src/utils/arrays.ts
692
550
  function ensureArray(t) {
693
- if (isNullOrUndefined(t)) return [];
551
+ if (isNullOrUndefined(t))
552
+ return [];
694
553
  return t instanceof Array ? t : [t];
695
554
  }
696
555
  function ensureReadableArray(t) {
697
- if (isNullOrUndefined(t)) return [];
556
+ if (isNullOrUndefined(t))
557
+ return [];
698
558
  return t instanceof Array ? t : [t];
699
559
  }
700
560
  function isArray(t) {
@@ -713,7 +573,8 @@ function upsert(arr, item, isEqual) {
713
573
  }
714
574
  }
715
575
  function range(start, end) {
716
- if (end < start) throw new Error();
576
+ if (end < start)
577
+ throw new Error();
717
578
  let length = end - start + 1;
718
579
  return new Array(length).fill(1).map((_, i) => start + i);
719
580
  }
@@ -772,7 +633,8 @@ function partition(arr, predicate) {
772
633
  function mapFirstTruthy(arr, mapFn) {
773
634
  for (let i = 0; i < arr.length; i++) {
774
635
  const result = mapFn(arr[i]);
775
- if (result) return result;
636
+ if (result)
637
+ return result;
776
638
  }
777
639
  return null;
778
640
  }
@@ -780,7 +642,7 @@ function makeArrayEmpty(arr) {
780
642
  arr.splice(0, arr.length);
781
643
  }
782
644
 
783
- // src/utils/booleans.ts
645
+ // packages/core/src/utils/booleans.ts
784
646
  function isTrue(x) {
785
647
  return x === true;
786
648
  }
@@ -788,7 +650,7 @@ function isFalse(x) {
788
650
  return x === false;
789
651
  }
790
652
 
791
- // src/utils/errors/withTryCatch.ts
653
+ // packages/core/src/utils/errors/withTryCatch.ts
792
654
  function withTryCatch(fn, errMapFn) {
793
655
  try {
794
656
  return [fn(), void 0];
@@ -800,7 +662,7 @@ async function withTryCatchAsync(fn, errMapFn) {
800
662
  return fn().then((value) => [value, void 0], (e) => [void 0, (errMapFn ?? identity)(asError(e))]);
801
663
  }
802
664
 
803
- // src/utils/errors.ts
665
+ // packages/core/src/utils/errors.ts
804
666
  function asError(e) {
805
667
  if (e === void 0 || e === null)
806
668
  return new Error("Void message");
@@ -816,12 +678,13 @@ function isError(e) {
816
678
  return e instanceof Error;
817
679
  }
818
680
 
819
- // src/utils/json.ts
681
+ // packages/core/src/utils/json.ts
820
682
  function tryToParseJson(jsonContent) {
821
683
  return withTryCatch(() => JSON.parse(jsonContent));
822
684
  }
823
685
  function jsonCloneDeep(a) {
824
- if (null === a || "object" !== typeof a) return a;
686
+ if (null === a || "object" !== typeof a)
687
+ return a;
825
688
  if (a instanceof Date) {
826
689
  return new Date(a.getTime());
827
690
  } else if (a instanceof Array) {
@@ -848,7 +711,7 @@ function omitFromJsonObject(o, ...keys) {
848
711
  }
849
712
  var omit = omitFromJsonObject;
850
713
 
851
- // src/utils/numbers/round.ts
714
+ // packages/core/src/utils/numbers/round.ts
852
715
  var roundModes = {
853
716
  "toNearest": Math.round,
854
717
  "toLower": Math.floor,
@@ -867,7 +730,7 @@ var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
867
730
  var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
868
731
  var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
869
732
 
870
- // src/utils/numbers.ts
733
+ // packages/core/src/utils/numbers.ts
871
734
  function ensurePositiveNumber(v, name = "value") {
872
735
  if (v !== void 0 && v !== null && v > 0)
873
736
  return v;
@@ -926,15 +789,18 @@ function clamp(n, min2, max2) {
926
789
  function tryToParseNumber(numberStr) {
927
790
  return withTryCatch(() => {
928
791
  const type = typeof ensureDefined(numberStr);
929
- if (type !== "string") throw new Error("Invalid number given: " + numberStr);
930
- if (numberStr.trim().length === 0) throw new Error("Invalid number given: " + numberStr);
792
+ if (type !== "string")
793
+ throw new Error("Invalid number given: " + numberStr);
794
+ if (numberStr.trim().length === 0)
795
+ throw new Error("Invalid number given: " + numberStr);
931
796
  const num = Number(numberStr);
932
- if (isNaN(num)) throw new Error("Invalid number given: " + numberStr);
797
+ if (isNaN(num))
798
+ throw new Error("Invalid number given: " + numberStr);
933
799
  return num;
934
800
  });
935
801
  }
936
802
 
937
- // src/utils/promises.ts
803
+ // packages/core/src/utils/promises.ts
938
804
  function asPromise(promisable) {
939
805
  return Promise.resolve(promisable);
940
806
  }
@@ -952,15 +818,17 @@ function delayPromise(duration) {
952
818
  return (result) => duration.promise().then(() => result);
953
819
  }
954
820
 
955
- // src/utils/random.ts
956
- function randomInterval(min2, max2) {
821
+ // packages/core/src/utils/random.ts
822
+ var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
823
+ var randomPercentage = (min2, max2) => randomNumberInInterval(min2, max2) / 100;
824
+ function randomNumberInInterval(min2, max2) {
957
825
  return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
958
826
  }
959
- function randomPercentage(min2, max2) {
960
- return randomInterval(min2, max2) / 100;
961
- }
827
+ var randomId = (length) => {
828
+ return Math.random().toString(36).substring(2, length + 2);
829
+ };
962
830
 
963
- // src/utils/records/entries.ts
831
+ // packages/core/src/utils/records/entries.ts
964
832
  function dictToEntries(obj) {
965
833
  return Object.entries(obj);
966
834
  }
@@ -971,7 +839,7 @@ function mapEntries(dict, mapper) {
971
839
  return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
972
840
  }
973
841
 
974
- // src/utils/records.ts
842
+ // packages/core/src/utils/records.ts
975
843
  function dictToList(obj) {
976
844
  return Object.keys(obj).map((key) => obj[key]);
977
845
  }
@@ -982,7 +850,7 @@ function pick(o, keys) {
982
850
  }, {});
983
851
  }
984
852
 
985
- // src/utils/strings/StringParts.ts
853
+ // packages/core/src/utils/strings/StringParts.ts
986
854
  var StringParts = class _StringParts {
987
855
  _parts;
988
856
  constructor(...parts) {
@@ -995,7 +863,8 @@ var StringParts = class _StringParts {
995
863
  return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
996
864
  }
997
865
  capitalizeFirst() {
998
- if (!this.length) return this;
866
+ if (!this.length)
867
+ return this;
999
868
  return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
1000
869
  }
1001
870
  capitalizeEach() {
@@ -1024,7 +893,8 @@ var StringParts = class _StringParts {
1024
893
  return this.toLowerCase().join("_");
1025
894
  }
1026
895
  toCamelCase() {
1027
- if (!this.length) return "";
896
+ if (!this.length)
897
+ return "";
1028
898
  return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
1029
899
  }
1030
900
  toKebabCase() {
@@ -1067,7 +937,7 @@ var StringParts = class _StringParts {
1067
937
  };
1068
938
  };
1069
939
 
1070
- // src/utils/strings.ts
940
+ // packages/core/src/utils/strings.ts
1071
941
  function hashCode(str) {
1072
942
  let hash = 0;
1073
943
  for (let i = 0; i < str.length; ++i)
@@ -1090,7 +960,8 @@ function stringToNumber(s) {
1090
960
  }
1091
961
  function pad(str, n, char, where = "left") {
1092
962
  const length = ensureDefined(str).length;
1093
- if (length >= ensureDefined(n)) return str;
963
+ if (length >= ensureDefined(n))
964
+ return str;
1094
965
  if (ensureDefined(char).length !== 1)
1095
966
  throw new Error("Illegal pad character");
1096
967
  const padding = repeat(char, n - length);
@@ -1130,7 +1001,7 @@ function wrapWithString(str, delimiter) {
1130
1001
  }
1131
1002
  var wrap = wrapWithString;
1132
1003
 
1133
- // src/lazy/Lazy.ts
1004
+ // packages/core/src/lazy/Lazy.ts
1134
1005
  var Lazy = class _Lazy {
1135
1006
  _value = void 0;
1136
1007
  _initialized = false;
@@ -1188,7 +1059,7 @@ var Lazy = class _Lazy {
1188
1059
  }
1189
1060
  };
1190
1061
 
1191
- // src/lazy/LazyAsync.ts
1062
+ // packages/core/src/lazy/LazyAsync.ts
1192
1063
  var LazyAsync = class _LazyAsync {
1193
1064
  _promise = void 0;
1194
1065
  _pending = false;
@@ -1270,10 +1141,10 @@ var LazyAsync = class _LazyAsync {
1270
1141
  }
1271
1142
  };
1272
1143
 
1273
- // src/time/TimeInstant.ts
1274
- var import_small_date = __toESM(require_lib());
1144
+ // packages/core/src/time/TimeInstant.ts
1145
+ var import_small_date = require("small-date");
1275
1146
 
1276
- // src/time/TimeUnit.ts
1147
+ // packages/core/src/time/TimeUnit.ts
1277
1148
  var TimeUnit = class _TimeUnit {
1278
1149
  constructor(multiplier) {
1279
1150
  this.multiplier = multiplier;
@@ -1307,7 +1178,7 @@ var TimeUnit = class _TimeUnit {
1307
1178
  static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
1308
1179
  };
1309
1180
 
1310
- // src/time/TimeBase.ts
1181
+ // packages/core/src/time/TimeBase.ts
1311
1182
  var TimeBase = class {
1312
1183
  _ms;
1313
1184
  constructor(value, unit) {
@@ -1391,7 +1262,7 @@ var TimeBase = class {
1391
1262
  }
1392
1263
  };
1393
1264
 
1394
- // src/time/TimeDuration.ts
1265
+ // packages/core/src/time/TimeDuration.ts
1395
1266
  var TimeDuration = class _TimeDuration extends TimeBase {
1396
1267
  constructor(value, unit) {
1397
1268
  super(value, unit);
@@ -1424,11 +1295,11 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1424
1295
  return _TimeDuration.ms(this.ms / times);
1425
1296
  }
1426
1297
  /**
1427
- * Returns the current duration in a human readable format, prioritizing the most significant unit of time and excluding the rest.
1428
- * @todo[2023-06] Should allow more customization options
1429
- * @todo[2023-06] By default should show the secondary unit only when actually needed (eg, 1h 20m & 3h, instead of 1h 20m & 3h 28m)
1430
- * @todo[2023-06] Should not allow negative durations, as this is a duration and not an instant.
1431
- * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1298
+ * Returns the current duration in a human readable format, prioritizing the most significant unit of time and excluding the rest.
1299
+ * @todo[2023-06] Should allow more customization options
1300
+ * @todo[2023-06] By default should show the secondary unit only when actually needed (eg, 1h 20m & 3h, instead of 1h 20m & 3h 28m)
1301
+ * @todo[2023-06] Should not allow negative durations, as this is a duration and not an instant.
1302
+ * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1432
1303
  */
1433
1304
  get formatted() {
1434
1305
  const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
@@ -1458,7 +1329,7 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1458
1329
  timeout(cb) {
1459
1330
  return setTimeout(cb, this.ms);
1460
1331
  }
1461
- promise() {
1332
+ cancelablePromise() {
1462
1333
  const deferred = new Deferred_default();
1463
1334
  if (this.ms > 0) {
1464
1335
  this.timeout(() => deferred.resolve());
@@ -1467,8 +1338,18 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1467
1338
  }
1468
1339
  return deferred.asCancelablePromise();
1469
1340
  }
1341
+ promise() {
1342
+ if (this.isEmpty())
1343
+ return Promise.resolve();
1344
+ const deferred = new Deferred_default();
1345
+ this.timeout(() => deferred.resolve());
1346
+ return deferred.asPromise();
1347
+ }
1470
1348
  delay(cb) {
1471
- const deferred = this.promise();
1349
+ void this.promise().then(() => cb());
1350
+ }
1351
+ cancelableDelay(cb) {
1352
+ const deferred = this.cancelablePromise();
1472
1353
  void deferred.then(() => {
1473
1354
  cb();
1474
1355
  }, (err) => {
@@ -1623,7 +1504,7 @@ function isAllowedTimeDuration(t) {
1623
1504
  }
1624
1505
  var TimeDuration_default = TimeDuration;
1625
1506
 
1626
- // src/time/TimeInstantBuilder.ts
1507
+ // packages/core/src/time/TimeInstantBuilder.ts
1627
1508
  var isRelativeNumber = (x) => x !== void 0 && x.length > 0 && (x[0] === "+" || x[0] === "-");
1628
1509
  var defaultTimeInstantCreationParameters = {
1629
1510
  year: { relative: 0, relativeTo: "now" },
@@ -1692,7 +1573,8 @@ var getFromDate = {
1692
1573
  };
1693
1574
  var toReferenceDate = (x) => {
1694
1575
  ensureDefined(x);
1695
- if (isTimeInstant(x)) return x.toDate();
1576
+ if (isTimeInstant(x))
1577
+ return x.toDate();
1696
1578
  return x;
1697
1579
  };
1698
1580
  function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
@@ -1756,7 +1638,7 @@ function timeInstantBuilder() {
1756
1638
  return ret;
1757
1639
  }
1758
1640
 
1759
- // src/time/TimeInstant.ts
1641
+ // packages/core/src/time/TimeInstant.ts
1760
1642
  var TimeInstant = class _TimeInstant extends TimeBase {
1761
1643
  constructor(number, unit) {
1762
1644
  super(number, unit);
@@ -1776,6 +1658,14 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1776
1658
  distanceFromNow() {
1777
1659
  return TimeDuration_default.fromMs(Math.abs(this.ms - Date.now()));
1778
1660
  }
1661
+ timeLeftFrom(instant) {
1662
+ const distance = this.ms - instant.ms;
1663
+ return TimeDuration_default.fromMs(Math.max(distance, 0));
1664
+ }
1665
+ timeLeftFromNow() {
1666
+ const distance = this.ms - Date.now();
1667
+ return TimeDuration_default.fromMs(Math.max(distance, 0));
1668
+ }
1779
1669
  distanceFromStartOfDay() {
1780
1670
  return this.distanceFrom(this.atStartOfDay());
1781
1671
  }
@@ -1789,14 +1679,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1789
1679
  return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
1790
1680
  }
1791
1681
  promise() {
1792
- const ms = this.ms - Date.now();
1793
- const duration = TimeDuration_default.fromMs(Math.max(ms, 0));
1794
- return duration.promise();
1682
+ return this.timeLeftFromNow().promise();
1683
+ }
1684
+ cancelablePromise() {
1685
+ return this.timeLeftFromNow().cancelablePromise();
1795
1686
  }
1796
1687
  delay(cb) {
1797
- const ms = this.ms - Date.now();
1798
- const duration = TimeDuration_default.fromMs(Math.max(ms, 0));
1799
- return duration.delay(cb);
1688
+ return this.timeLeftFromNow().delay(cb);
1689
+ }
1690
+ cancelableDelay(cb) {
1691
+ return this.timeLeftFromNow().cancelableDelay(cb);
1800
1692
  }
1801
1693
  ensureInTheFuture() {
1802
1694
  if (!this.isInTheFuture)
@@ -1911,20 +1803,23 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1911
1803
  }
1912
1804
  }
1913
1805
  /**
1914
- * @deprecated[04/07/2023]: Use distanceFromNow instead
1915
- */
1806
+ * @deprecated: Use {@link distanceFromNow} instead
1807
+ */
1808
+ // TODO[2023-07-04, Deprecated]: Remove this method in a future version
1916
1809
  fromNow() {
1917
1810
  return TimeDuration_default.ms(this.ms - Date.now());
1918
1811
  }
1919
1812
  /**
1920
- * @deprecated[04/07/2023]: Use distanceFrom instead
1921
- */
1813
+ * @deprecated: Use {@link distanceFrom} instead
1814
+ */
1815
+ // TODO[2023-07-04, Deprecated]: Remove this method in a future version
1922
1816
  from(instant) {
1923
1817
  return TimeDuration_default.ms(this.ms - instant.ms);
1924
1818
  }
1925
1819
  /**
1926
- * @deprecated[04/07/2023]: Use distanceFromUnixTimestamp instead
1927
- */
1820
+ * @deprecated: Use {@link distanceFromUnixTimestamp} instead
1821
+ */
1822
+ // TODO[2023-07-04, Deprecated]: Remove this method in a future version
1928
1823
  fromTimestamp(timestamp2) {
1929
1824
  return TimeDuration_default.ms(this.ms - timestamp2);
1930
1825
  }
@@ -1965,8 +1860,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1965
1860
  return timeInstantBuilder();
1966
1861
  }
1967
1862
  /**
1968
- * @deprecated[19/07/2023] Use {@link fromParameters} instead.
1969
- */
1863
+ * @deprecated[19/07/2023] Use {@link fromParameters} instead.
1864
+ */
1970
1865
  static fromUnits({ date, month, year, hours, minutes, seconds }) {
1971
1866
  const dt = Date.UTC(year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0);
1972
1867
  if (isNaN(dt))
@@ -2024,9 +1919,9 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2024
1919
  return this.toDate().getFullYear();
2025
1920
  }
2026
1921
  /**
2027
- * Returns the week number represented by this instant, according to the ISO 8601 standard.
1922
+ * Returns the week number represented by this instant, according to the ISO 8601 standard.
2028
1923
  * 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.
2029
- */
1924
+ */
2030
1925
  get weekNumber() {
2031
1926
  const date = this.toDate();
2032
1927
  const oneDay = 1e3 * 60 * 60 * 24;
@@ -2037,8 +1932,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2037
1932
  return { weekNumber, year: thursdayOfThisWeek.getFullYear() };
2038
1933
  }
2039
1934
  /**
2040
- * This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
2041
- */
1935
+ * This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
1936
+ */
2042
1937
  get _time() {
2043
1938
  return this.asHumanTimestamp();
2044
1939
  }
@@ -2055,7 +1950,7 @@ function isTimeInstant(x) {
2055
1950
  }
2056
1951
  var TimeInstant_default = TimeInstant;
2057
1952
 
2058
- // src/Logger.ts
1953
+ // packages/core/src/Logger.ts
2059
1954
  var LEVELS = ["log", "debug", "info", "warn", "error"];
2060
1955
  var timestamp = () => TimeInstant_default.now().asTimeString();
2061
1956
  var Logger = class {
@@ -2092,7 +1987,7 @@ var Logger = class {
2092
1987
  }
2093
1988
  };
2094
1989
 
2095
- // src/Optional.ts
1990
+ // packages/core/src/Optional.ts
2096
1991
  var Optional = class _Optional {
2097
1992
  _present;
2098
1993
  _value;
@@ -2206,7 +2101,7 @@ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
2206
2101
  }
2207
2102
  };
2208
2103
 
2209
- // src/sorting/ComparisonChain.ts
2104
+ // packages/core/src/sorting/ComparisonChain.ts
2210
2105
  var defaultCompareValueOptions = {
2211
2106
  nullsFirst: false,
2212
2107
  direction: "ASC"
@@ -2248,8 +2143,10 @@ function compareBooleans(options) {
2248
2143
  const fn = (a, b) => {
2249
2144
  if (a === b)
2250
2145
  return 0;
2251
- if (isNullOrUndefined(a)) return opts.nullsFirst ? -1 : 1;
2252
- if (isNullOrUndefined(b)) return opts.nullsFirst ? 1 : -1;
2146
+ if (isNullOrUndefined(a))
2147
+ return opts.nullsFirst ? -1 : 1;
2148
+ if (isNullOrUndefined(b))
2149
+ return opts.nullsFirst ? 1 : -1;
2253
2150
  return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
2254
2151
  };
2255
2152
  return (a, b) => applyDirection(fn(a, b), opts.direction);
@@ -2364,7 +2261,7 @@ function getComparisonFunction(arg) {
2364
2261
  return arg instanceof ComparisonChain ? arg.compare : arg;
2365
2262
  }
2366
2263
 
2367
- // src/sorting/Sorter.ts
2264
+ // packages/core/src/sorting/Sorter.ts
2368
2265
  var defaultCompareValuesOptions = {
2369
2266
  nullsFirst: false
2370
2267
  };
@@ -2430,7 +2327,8 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
2430
2327
  var prioritizeArray = (fns, transform, arr, reversed = false) => {
2431
2328
  return compareNumbers(fns, (t) => {
2432
2329
  const r = transform(t);
2433
- if (!isDefined(r)) return Number.MAX_VALUE;
2330
+ if (!isDefined(r))
2331
+ return Number.MAX_VALUE;
2434
2332
  const indexOf = arr.indexOf(r);
2435
2333
  return indexOf === -1 ? Number.MAX_VALUE : indexOf;
2436
2334
  }, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
@@ -2596,7 +2494,7 @@ var Sorter = {
2596
2494
  };
2597
2495
  var Sorting = Sorter;
2598
2496
 
2599
- // src/time/RandomTimeDuration.ts
2497
+ // packages/core/src/time/RandomTimeDuration.ts
2600
2498
  function randomize(unit) {
2601
2499
  return (a, b) => {
2602
2500
  return TimeDuration_default.fromMs(randomInterval(unit.toMs(a), unit.toMs(b)));
@@ -2612,7 +2510,7 @@ var RandomTimeDuration = class {
2612
2510
  static days = randomize(TimeUnit.DAYS);
2613
2511
  };
2614
2512
 
2615
- // src/time/TimeFrequency.ts
2513
+ // packages/core/src/time/TimeFrequency.ts
2616
2514
  var TimeFrequency = class _TimeFrequency {
2617
2515
  constructor(times, period) {
2618
2516
  this.times = times;
@@ -2633,7 +2531,7 @@ var TimeFrequency = class _TimeFrequency {
2633
2531
  }
2634
2532
  };
2635
2533
 
2636
- // src/time/TimeRange.ts
2534
+ // packages/core/src/time/TimeRange.ts
2637
2535
  var TimeRange = class _TimeRange {
2638
2536
  constructor(start, duration) {
2639
2537
  this.start = start;
@@ -2654,7 +2552,7 @@ var TimeRange = class _TimeRange {
2654
2552
  }
2655
2553
  };
2656
2554
 
2657
- // src/upgrade/errors.ts
2555
+ // packages/core/src/upgrade/errors.ts
2658
2556
  var UnavailableUpgradeError = class extends Error {
2659
2557
  constructor(data, from, to) {
2660
2558
  super(`No transition found to upgrade data from version ${from} to version ${to}.`);
@@ -2672,7 +2570,7 @@ var EmptyUpgradeError = class extends Error {
2672
2570
  }
2673
2571
  };
2674
2572
 
2675
- // src/upgrade/getTransitionsPath.ts
2573
+ // packages/core/src/upgrade/getTransitionsPath.ts
2676
2574
  var DEBUG_ENABLED = false;
2677
2575
  function getTransitionsPath(matrix, from, to) {
2678
2576
  return internalGetTransitionsPath(matrix, from, to, 0, DEBUG_ENABLED);
@@ -2721,7 +2619,7 @@ function printTransitions(transitions) {
2721
2619
  }, "" + transitions[0].from);
2722
2620
  }
2723
2621
 
2724
- // src/upgrade/DataUpgrader.ts
2622
+ // packages/core/src/upgrade/DataUpgrader.ts
2725
2623
  var VERSION_FIELD = "$version";
2726
2624
  var DataUpgrader = class _DataUpgrader {
2727
2625
  constructor(latestVersion) {
@@ -2904,7 +2802,9 @@ function isUpgradable(obj) {
2904
2802
  pick,
2905
2803
  pluralize,
2906
2804
  promiseSequence,
2805
+ randomId,
2907
2806
  randomInterval,
2807
+ randomNumberInInterval,
2908
2808
  randomPercentage,
2909
2809
  range,
2910
2810
  repeat,