@zelgadis87/utils-core 4.4.4 → 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 (68) hide show
  1. package/esbuild/index.cjs +207 -270
  2. package/esbuild/{index.mjs → index.js} +197 -282
  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/arrays.ts +9 -3
  10. package/src/utils/functions/constant.ts +2 -0
  11. package/src/utils/functions.ts +23 -0
  12. package/src/utils/random.ts +9 -3
  13. package/src/utils/records.ts +12 -0
  14. package/dist/Logger.d.ts +0 -21
  15. package/dist/Optional.d.ts +0 -70
  16. package/dist/async/CancelableDeferred.d.ts +0 -17
  17. package/dist/async/Deferred.d.ts +0 -34
  18. package/dist/async/RateThrottler.d.ts +0 -13
  19. package/dist/async/Semaphore.d.ts +0 -14
  20. package/dist/async/index.d.ts +0 -4
  21. package/dist/index.d.ts +0 -8
  22. package/dist/lazy/Lazy.d.ts +0 -22
  23. package/dist/lazy/LazyAsync.d.ts +0 -24
  24. package/dist/lazy/index.d.ts +0 -2
  25. package/dist/sorting/ComparisonChain.d.ts +0 -57
  26. package/dist/sorting/Sorter.d.ts +0 -100
  27. package/dist/sorting/index.d.ts +0 -4
  28. package/dist/sorting/types.d.ts +0 -5
  29. package/dist/time/RandomTimeDuration.d.ts +0 -9
  30. package/dist/time/TimeBase.d.ts +0 -38
  31. package/dist/time/TimeDuration.d.ts +0 -79
  32. package/dist/time/TimeFrequency.d.ts +0 -10
  33. package/dist/time/TimeInstant.d.ts +0 -171
  34. package/dist/time/TimeInstantBuilder.d.ts +0 -77
  35. package/dist/time/TimeRange.d.ts +0 -11
  36. package/dist/time/TimeUnit.d.ts +0 -17
  37. package/dist/time/index.d.ts +0 -7
  38. package/dist/time/types.d.ts +0 -26
  39. package/dist/tsconfig.tsbuildinfo +0 -1
  40. package/dist/upgrade/DataUpgrader.d.ts +0 -22
  41. package/dist/upgrade/errors.d.ts +0 -12
  42. package/dist/upgrade/getTransitionsPath.d.ts +0 -3
  43. package/dist/upgrade/index.d.ts +0 -2
  44. package/dist/upgrade/types.d.ts +0 -31
  45. package/dist/utils/arrays/groupBy.d.ts +0 -9
  46. package/dist/utils/arrays/indexBy.d.ts +0 -7
  47. package/dist/utils/arrays/statistics.d.ts +0 -8
  48. package/dist/utils/arrays/uniqBy.d.ts +0 -4
  49. package/dist/utils/arrays.d.ts +0 -56
  50. package/dist/utils/booleans.d.ts +0 -2
  51. package/dist/utils/empties.d.ts +0 -17
  52. package/dist/utils/errors/withTryCatch.d.ts +0 -3
  53. package/dist/utils/errors.d.ts +0 -3
  54. package/dist/utils/functions/constant.d.ts +0 -8
  55. package/dist/utils/functions/iff.d.ts +0 -8
  56. package/dist/utils/functions.d.ts +0 -27
  57. package/dist/utils/index.d.ts +0 -13
  58. package/dist/utils/json.d.ts +0 -11
  59. package/dist/utils/nulls.d.ts +0 -8
  60. package/dist/utils/numbers/round.d.ts +0 -8
  61. package/dist/utils/numbers.d.ts +0 -34
  62. package/dist/utils/primitives.d.ts +0 -3
  63. package/dist/utils/promises.d.ts +0 -6
  64. package/dist/utils/random.d.ts +0 -2
  65. package/dist/utils/records/entries.d.ts +0 -4
  66. package/dist/utils/records.d.ts +0 -21
  67. package/dist/utils/strings/StringParts.d.ts +0 -32
  68. package/dist/utils/strings.d.ts +0 -17
@@ -1,168 +1,4 @@
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
-
165
- // src/async/Deferred.ts
1
+ // packages/core/src/async/Deferred.ts
166
2
  var DeferredCanceledError = class extends Error {
167
3
  constructor() {
168
4
  super("Execution canceled");
@@ -247,7 +83,7 @@ var Deferred = class {
247
83
  };
248
84
  var Deferred_default = Deferred;
249
85
 
250
- // src/async/RateThrottler.ts
86
+ // packages/core/src/async/RateThrottler.ts
251
87
  var RateThrottler = class {
252
88
  constructor(_frequency) {
253
89
  this._frequency = _frequency;
@@ -267,7 +103,8 @@ var RateThrottler = class {
267
103
  return slot.promise().then(() => fn());
268
104
  } finally {
269
105
  this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
270
- if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
106
+ if (this._waitingRequests.length > 0)
107
+ this._waitingRequests.shift().resolve();
271
108
  }
272
109
  };
273
110
  if (this._availableSlots.length > 0) {
@@ -286,7 +123,7 @@ function throttle(fn, frequence) {
286
123
  };
287
124
  }
288
125
 
289
- // src/async/Semaphore.ts
126
+ // packages/core/src/async/Semaphore.ts
290
127
  var Semaphore = class {
291
128
  constructor(_availableSlots = 1) {
292
129
  this._availableSlots = _availableSlots;
@@ -315,8 +152,8 @@ var Semaphore = class {
315
152
  }
316
153
  }
317
154
  async execute(fn, cooldown = TimeDuration.ZERO) {
318
- return this._awaitSlot().then(() => fn()).finally(() => {
319
- void cooldown.promise().then(() => this._releaseSlot());
155
+ return this._awaitSlot().then(fn).finally(() => {
156
+ void cooldown.delay(() => this._releaseSlot());
320
157
  });
321
158
  }
322
159
  get availableSlots() {
@@ -330,7 +167,33 @@ var Semaphore = class {
330
167
  }
331
168
  };
332
169
 
333
- // src/utils/arrays/groupBy.ts
170
+ // packages/core/src/utils/nulls.ts
171
+ function ensureDefined(v, name = "value") {
172
+ if (isDefined(v))
173
+ return v;
174
+ throw new Error("Expected " + name + " to be defined, got: " + v);
175
+ }
176
+ function isDefined(x) {
177
+ return x !== null && x !== void 0;
178
+ }
179
+ function isNullOrUndefined(x) {
180
+ return x === null || x === void 0;
181
+ }
182
+ function ifDefined(source, callback) {
183
+ if (isDefined(source))
184
+ callback(source);
185
+ }
186
+ function mapDefined(source, mapper) {
187
+ if (isDefined(source))
188
+ return mapper(source);
189
+ return null;
190
+ }
191
+ function ifNullOrUndefined(source, callback) {
192
+ if (isNullOrUndefined(source))
193
+ callback();
194
+ }
195
+
196
+ // packages/core/src/utils/arrays/groupBy.ts
334
197
  function groupByString(arr, field) {
335
198
  return groupByStringWith(arr, (t) => t[field]);
336
199
  }
@@ -356,7 +219,7 @@ function groupBySymbolWith(arr, getter) {
356
219
  return doGroupByWith(arr, getter);
357
220
  }
358
221
  function doGroupByWith(arr, getter) {
359
- return arr.reduce((dict, cur) => {
222
+ return [...arr].reduce((dict, cur) => {
360
223
  const key = getter(cur);
361
224
  if (key !== null && key !== void 0) {
362
225
  const arr2 = dict[key] ?? [];
@@ -367,7 +230,7 @@ function doGroupByWith(arr, getter) {
367
230
  }, {});
368
231
  }
369
232
 
370
- // src/utils/arrays/indexBy.ts
233
+ // packages/core/src/utils/arrays/indexBy.ts
371
234
  function indexByString(arr, field) {
372
235
  return indexByStringWith(arr, (t) => t[field]);
373
236
  }
@@ -395,7 +258,7 @@ function doIndexByWith(arr, getter) {
395
258
  }, {});
396
259
  }
397
260
 
398
- // src/utils/arrays/statistics.ts
261
+ // packages/core/src/utils/arrays/statistics.ts
399
262
  function average(arr) {
400
263
  const f = 1 / arr.length;
401
264
  return arr.reduce((tot, cur) => tot + cur * f, 0);
@@ -407,21 +270,23 @@ function sumBy(arr, getter) {
407
270
  return sum(arr.map(getter));
408
271
  }
409
272
  function min(arr) {
410
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
273
+ if (arr.length === 0)
274
+ throw new Error("Cannot calculate value on empty array");
411
275
  return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
412
276
  }
413
277
  function minBy(arr, getter) {
414
278
  return min(arr.map(getter));
415
279
  }
416
280
  function max(arr) {
417
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
281
+ if (arr.length === 0)
282
+ throw new Error("Cannot calculate value on empty array");
418
283
  return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
419
284
  }
420
285
  function maxBy(arr, getter) {
421
286
  return max(arr.map(getter));
422
287
  }
423
288
 
424
- // src/utils/functions/constant.ts
289
+ // packages/core/src/utils/functions/constant.ts
425
290
  function constant(v) {
426
291
  return () => v;
427
292
  }
@@ -431,10 +296,12 @@ function identity(t) {
431
296
  var constantNull = constant(null);
432
297
  var constantTrue = constant(true);
433
298
  var constantFalse = constant(false);
299
+ var alwaysTrue = constantTrue;
300
+ var alwaysFalse = constantFalse;
434
301
  var constantZero = constant(0);
435
302
  var constantOne = constant(1);
436
303
 
437
- // src/utils/functions/iff.ts
304
+ // packages/core/src/utils/functions/iff.ts
438
305
  function iff(firstPredicate, valueIfTrue) {
439
306
  if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
440
307
  const ret = {
@@ -451,7 +318,7 @@ function iff(firstPredicate, valueIfTrue) {
451
318
  }
452
319
  }
453
320
 
454
- // src/utils/functions.ts
321
+ // packages/core/src/utils/functions.ts
455
322
  function isFunction(t) {
456
323
  return typeof t === "function";
457
324
  }
@@ -460,8 +327,28 @@ function noop() {
460
327
  function filterWithTypePredicate(filter) {
461
328
  return (t) => filter(t);
462
329
  }
330
+ function not(predicate) {
331
+ return (t) => !predicate(t);
332
+ }
333
+ function and(...predicates) {
334
+ if (predicates.length === 0)
335
+ return constantTrue;
336
+ else if (predicates.length === 1)
337
+ return predicates[0];
338
+ return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
339
+ }
340
+ function or(...predicates) {
341
+ if (predicates.length === 0)
342
+ return constantTrue;
343
+ else if (predicates.length === 1)
344
+ return predicates[0];
345
+ return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
346
+ }
347
+ function xor(a, b) {
348
+ return (t) => a(t) !== b(t);
349
+ }
463
350
 
464
- // src/utils/arrays/uniqBy.ts
351
+ // packages/core/src/utils/arrays/uniqBy.ts
465
352
  function uniq(arr) {
466
353
  return uniqBy(arr, identity);
467
354
  }
@@ -482,11 +369,15 @@ function uniqByKey(arr, key) {
482
369
  return uniqBy(arr, (item) => item[key]);
483
370
  }
484
371
 
485
- // src/utils/arrays.ts
372
+ // packages/core/src/utils/arrays.ts
486
373
  function ensureArray(t) {
374
+ if (isNullOrUndefined(t))
375
+ return [];
487
376
  return t instanceof Array ? t : [t];
488
377
  }
489
378
  function ensureReadableArray(t) {
379
+ if (isNullOrUndefined(t))
380
+ return [];
490
381
  return t instanceof Array ? t : [t];
491
382
  }
492
383
  function isArray(t) {
@@ -505,7 +396,8 @@ function upsert(arr, item, isEqual) {
505
396
  }
506
397
  }
507
398
  function range(start, end) {
508
- if (end < start) throw new Error();
399
+ if (end < start)
400
+ throw new Error();
509
401
  let length = end - start + 1;
510
402
  return new Array(length).fill(1).map((_, i) => start + i);
511
403
  }
@@ -564,12 +456,16 @@ function partition(arr, predicate) {
564
456
  function mapFirstTruthy(arr, mapFn) {
565
457
  for (let i = 0; i < arr.length; i++) {
566
458
  const result = mapFn(arr[i]);
567
- if (result) return result;
459
+ if (result)
460
+ return result;
568
461
  }
569
462
  return null;
570
463
  }
464
+ function makeArrayEmpty(arr) {
465
+ arr.splice(0, arr.length);
466
+ }
571
467
 
572
- // src/utils/booleans.ts
468
+ // packages/core/src/utils/booleans.ts
573
469
  function isTrue(x) {
574
470
  return x === true;
575
471
  }
@@ -577,7 +473,7 @@ function isFalse(x) {
577
473
  return x === false;
578
474
  }
579
475
 
580
- // src/utils/errors/withTryCatch.ts
476
+ // packages/core/src/utils/errors/withTryCatch.ts
581
477
  function withTryCatch(fn, errMapFn) {
582
478
  try {
583
479
  return [fn(), void 0];
@@ -589,7 +485,7 @@ async function withTryCatchAsync(fn, errMapFn) {
589
485
  return fn().then((value) => [value, void 0], (e) => [void 0, (errMapFn ?? identity)(asError(e))]);
590
486
  }
591
487
 
592
- // src/utils/errors.ts
488
+ // packages/core/src/utils/errors.ts
593
489
  function asError(e) {
594
490
  if (e === void 0 || e === null)
595
491
  return new Error("Void message");
@@ -605,12 +501,13 @@ function isError(e) {
605
501
  return e instanceof Error;
606
502
  }
607
503
 
608
- // src/utils/json.ts
504
+ // packages/core/src/utils/json.ts
609
505
  function tryToParseJson(jsonContent) {
610
506
  return withTryCatch(() => JSON.parse(jsonContent));
611
507
  }
612
508
  function jsonCloneDeep(a) {
613
- if (null === a || "object" !== typeof a) return a;
509
+ if (null === a || "object" !== typeof a)
510
+ return a;
614
511
  if (a instanceof Date) {
615
512
  return new Date(a.getTime());
616
513
  } else if (a instanceof Array) {
@@ -637,33 +534,7 @@ function omitFromJsonObject(o, ...keys) {
637
534
  }
638
535
  var omit = omitFromJsonObject;
639
536
 
640
- // src/utils/nulls.ts
641
- function ensureDefined(v, name = "value") {
642
- if (isDefined(v))
643
- return v;
644
- throw new Error("Expected " + name + " to be defined, got: " + v);
645
- }
646
- function isDefined(x) {
647
- return x !== null && x !== void 0;
648
- }
649
- function isNullOrUndefined(x) {
650
- return x === null || x === void 0;
651
- }
652
- function ifDefined(source, callback) {
653
- if (isDefined(source))
654
- callback(source);
655
- }
656
- function mapDefined(source, mapper) {
657
- if (isDefined(source))
658
- return mapper(source);
659
- return null;
660
- }
661
- function ifNullOrUndefined(source, callback) {
662
- if (isNullOrUndefined(source))
663
- callback();
664
- }
665
-
666
- // src/utils/numbers/round.ts
537
+ // packages/core/src/utils/numbers/round.ts
667
538
  var roundModes = {
668
539
  "toNearest": Math.round,
669
540
  "toLower": Math.floor,
@@ -682,7 +553,7 @@ var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
682
553
  var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
683
554
  var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
684
555
 
685
- // src/utils/numbers.ts
556
+ // packages/core/src/utils/numbers.ts
686
557
  function ensurePositiveNumber(v, name = "value") {
687
558
  if (v !== void 0 && v !== null && v > 0)
688
559
  return v;
@@ -741,15 +612,18 @@ function clamp(n, min2, max2) {
741
612
  function tryToParseNumber(numberStr) {
742
613
  return withTryCatch(() => {
743
614
  const type = typeof ensureDefined(numberStr);
744
- if (type !== "string") throw new Error("Invalid number given: " + numberStr);
745
- if (numberStr.trim().length === 0) throw new Error("Invalid number given: " + numberStr);
615
+ if (type !== "string")
616
+ throw new Error("Invalid number given: " + numberStr);
617
+ if (numberStr.trim().length === 0)
618
+ throw new Error("Invalid number given: " + numberStr);
746
619
  const num = Number(numberStr);
747
- if (isNaN(num)) throw new Error("Invalid number given: " + numberStr);
620
+ if (isNaN(num))
621
+ throw new Error("Invalid number given: " + numberStr);
748
622
  return num;
749
623
  });
750
624
  }
751
625
 
752
- // src/utils/promises.ts
626
+ // packages/core/src/utils/promises.ts
753
627
  function asPromise(promisable) {
754
628
  return Promise.resolve(promisable);
755
629
  }
@@ -767,15 +641,17 @@ function delayPromise(duration) {
767
641
  return (result) => duration.promise().then(() => result);
768
642
  }
769
643
 
770
- // src/utils/random.ts
771
- function randomInterval(min2, max2) {
644
+ // packages/core/src/utils/random.ts
645
+ var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
646
+ var randomPercentage = (min2, max2) => randomNumberInInterval(min2, max2) / 100;
647
+ function randomNumberInInterval(min2, max2) {
772
648
  return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
773
649
  }
774
- function randomPercentage(min2, max2) {
775
- return randomInterval(min2, max2) / 100;
776
- }
650
+ var randomId = (length) => {
651
+ return Math.random().toString(36).substring(2, length + 2);
652
+ };
777
653
 
778
- // src/utils/records/entries.ts
654
+ // packages/core/src/utils/records/entries.ts
779
655
  function dictToEntries(obj) {
780
656
  return Object.entries(obj);
781
657
  }
@@ -786,7 +662,7 @@ function mapEntries(dict, mapper) {
786
662
  return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
787
663
  }
788
664
 
789
- // src/utils/records.ts
665
+ // packages/core/src/utils/records.ts
790
666
  function dictToList(obj) {
791
667
  return Object.keys(obj).map((key) => obj[key]);
792
668
  }
@@ -797,7 +673,7 @@ function pick(o, keys) {
797
673
  }, {});
798
674
  }
799
675
 
800
- // src/utils/strings/StringParts.ts
676
+ // packages/core/src/utils/strings/StringParts.ts
801
677
  var StringParts = class _StringParts {
802
678
  _parts;
803
679
  constructor(...parts) {
@@ -810,7 +686,8 @@ var StringParts = class _StringParts {
810
686
  return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
811
687
  }
812
688
  capitalizeFirst() {
813
- if (!this.length) return this;
689
+ if (!this.length)
690
+ return this;
814
691
  return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
815
692
  }
816
693
  capitalizeEach() {
@@ -839,7 +716,8 @@ var StringParts = class _StringParts {
839
716
  return this.toLowerCase().join("_");
840
717
  }
841
718
  toCamelCase() {
842
- if (!this.length) return "";
719
+ if (!this.length)
720
+ return "";
843
721
  return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
844
722
  }
845
723
  toKebabCase() {
@@ -882,7 +760,7 @@ var StringParts = class _StringParts {
882
760
  };
883
761
  };
884
762
 
885
- // src/utils/strings.ts
763
+ // packages/core/src/utils/strings.ts
886
764
  function hashCode(str) {
887
765
  let hash = 0;
888
766
  for (let i = 0; i < str.length; ++i)
@@ -905,7 +783,8 @@ function stringToNumber(s) {
905
783
  }
906
784
  function pad(str, n, char, where = "left") {
907
785
  const length = ensureDefined(str).length;
908
- if (length >= ensureDefined(n)) return str;
786
+ if (length >= ensureDefined(n))
787
+ return str;
909
788
  if (ensureDefined(char).length !== 1)
910
789
  throw new Error("Illegal pad character");
911
790
  const padding = repeat(char, n - length);
@@ -945,7 +824,7 @@ function wrapWithString(str, delimiter) {
945
824
  }
946
825
  var wrap = wrapWithString;
947
826
 
948
- // src/lazy/Lazy.ts
827
+ // packages/core/src/lazy/Lazy.ts
949
828
  var Lazy = class _Lazy {
950
829
  _value = void 0;
951
830
  _initialized = false;
@@ -1003,7 +882,7 @@ var Lazy = class _Lazy {
1003
882
  }
1004
883
  };
1005
884
 
1006
- // src/lazy/LazyAsync.ts
885
+ // packages/core/src/lazy/LazyAsync.ts
1007
886
  var LazyAsync = class _LazyAsync {
1008
887
  _promise = void 0;
1009
888
  _pending = false;
@@ -1085,10 +964,10 @@ var LazyAsync = class _LazyAsync {
1085
964
  }
1086
965
  };
1087
966
 
1088
- // src/time/TimeInstant.ts
1089
- var import_small_date = __toESM(require_lib());
967
+ // packages/core/src/time/TimeInstant.ts
968
+ import { format } from "small-date";
1090
969
 
1091
- // src/time/TimeUnit.ts
970
+ // packages/core/src/time/TimeUnit.ts
1092
971
  var TimeUnit = class _TimeUnit {
1093
972
  constructor(multiplier) {
1094
973
  this.multiplier = multiplier;
@@ -1122,7 +1001,7 @@ var TimeUnit = class _TimeUnit {
1122
1001
  static WEEKS = new _TimeUnit(7 * _TimeUnit.DAYS.multiplier);
1123
1002
  };
1124
1003
 
1125
- // src/time/TimeBase.ts
1004
+ // packages/core/src/time/TimeBase.ts
1126
1005
  var TimeBase = class {
1127
1006
  _ms;
1128
1007
  constructor(value, unit) {
@@ -1206,7 +1085,7 @@ var TimeBase = class {
1206
1085
  }
1207
1086
  };
1208
1087
 
1209
- // src/time/TimeDuration.ts
1088
+ // packages/core/src/time/TimeDuration.ts
1210
1089
  var TimeDuration = class _TimeDuration extends TimeBase {
1211
1090
  constructor(value, unit) {
1212
1091
  super(value, unit);
@@ -1239,11 +1118,11 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1239
1118
  return _TimeDuration.ms(this.ms / times);
1240
1119
  }
1241
1120
  /**
1242
- * Returns the current duration in a human readable format, prioritizing the most significant unit of time and excluding the rest.
1243
- * @todo[2023-06] Should allow more customization options
1244
- * @todo[2023-06] By default should show the secondary unit only when actually needed (eg, 1h 20m & 3h, instead of 1h 20m & 3h 28m)
1245
- * @todo[2023-06] Should not allow negative durations, as this is a duration and not an instant.
1246
- * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1121
+ * Returns the current duration in a human readable format, prioritizing the most significant unit of time and excluding the rest.
1122
+ * @todo[2023-06] Should allow more customization options
1123
+ * @todo[2023-06] By default should show the secondary unit only when actually needed (eg, 1h 20m & 3h, instead of 1h 20m & 3h 28m)
1124
+ * @todo[2023-06] Should not allow negative durations, as this is a duration and not an instant.
1125
+ * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1247
1126
  */
1248
1127
  get formatted() {
1249
1128
  const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
@@ -1273,7 +1152,7 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1273
1152
  timeout(cb) {
1274
1153
  return setTimeout(cb, this.ms);
1275
1154
  }
1276
- promise() {
1155
+ cancelablePromise() {
1277
1156
  const deferred = new Deferred_default();
1278
1157
  if (this.ms > 0) {
1279
1158
  this.timeout(() => deferred.resolve());
@@ -1282,8 +1161,18 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1282
1161
  }
1283
1162
  return deferred.asCancelablePromise();
1284
1163
  }
1164
+ promise() {
1165
+ if (this.isEmpty())
1166
+ return Promise.resolve();
1167
+ const deferred = new Deferred_default();
1168
+ this.timeout(() => deferred.resolve());
1169
+ return deferred.asPromise();
1170
+ }
1285
1171
  delay(cb) {
1286
- const deferred = this.promise();
1172
+ void this.promise().then(() => cb());
1173
+ }
1174
+ cancelableDelay(cb) {
1175
+ const deferred = this.cancelablePromise();
1287
1176
  void deferred.then(() => {
1288
1177
  cb();
1289
1178
  }, (err) => {
@@ -1438,7 +1327,7 @@ function isAllowedTimeDuration(t) {
1438
1327
  }
1439
1328
  var TimeDuration_default = TimeDuration;
1440
1329
 
1441
- // src/time/TimeInstantBuilder.ts
1330
+ // packages/core/src/time/TimeInstantBuilder.ts
1442
1331
  var isRelativeNumber = (x) => x !== void 0 && x.length > 0 && (x[0] === "+" || x[0] === "-");
1443
1332
  var defaultTimeInstantCreationParameters = {
1444
1333
  year: { relative: 0, relativeTo: "now" },
@@ -1507,7 +1396,8 @@ var getFromDate = {
1507
1396
  };
1508
1397
  var toReferenceDate = (x) => {
1509
1398
  ensureDefined(x);
1510
- if (isTimeInstant(x)) return x.toDate();
1399
+ if (isTimeInstant(x))
1400
+ return x.toDate();
1511
1401
  return x;
1512
1402
  };
1513
1403
  function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
@@ -1571,7 +1461,7 @@ function timeInstantBuilder() {
1571
1461
  return ret;
1572
1462
  }
1573
1463
 
1574
- // src/time/TimeInstant.ts
1464
+ // packages/core/src/time/TimeInstant.ts
1575
1465
  var TimeInstant = class _TimeInstant extends TimeBase {
1576
1466
  constructor(number, unit) {
1577
1467
  super(number, unit);
@@ -1591,6 +1481,14 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1591
1481
  distanceFromNow() {
1592
1482
  return TimeDuration_default.fromMs(Math.abs(this.ms - Date.now()));
1593
1483
  }
1484
+ timeLeftFrom(instant) {
1485
+ const distance = this.ms - instant.ms;
1486
+ return TimeDuration_default.fromMs(Math.max(distance, 0));
1487
+ }
1488
+ timeLeftFromNow() {
1489
+ const distance = this.ms - Date.now();
1490
+ return TimeDuration_default.fromMs(Math.max(distance, 0));
1491
+ }
1594
1492
  distanceFromStartOfDay() {
1595
1493
  return this.distanceFrom(this.atStartOfDay());
1596
1494
  }
@@ -1604,14 +1502,16 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1604
1502
  return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
1605
1503
  }
1606
1504
  promise() {
1607
- const ms = this.ms - Date.now();
1608
- const duration = TimeDuration_default.fromMs(Math.max(ms, 0));
1609
- return duration.promise();
1505
+ return this.timeLeftFromNow().promise();
1506
+ }
1507
+ cancelablePromise() {
1508
+ return this.timeLeftFromNow().cancelablePromise();
1610
1509
  }
1611
1510
  delay(cb) {
1612
- const ms = this.ms - Date.now();
1613
- const duration = TimeDuration_default.fromMs(Math.max(ms, 0));
1614
- return duration.delay(cb);
1511
+ return this.timeLeftFromNow().delay(cb);
1512
+ }
1513
+ cancelableDelay(cb) {
1514
+ return this.timeLeftFromNow().cancelableDelay(cb);
1615
1515
  }
1616
1516
  ensureInTheFuture() {
1617
1517
  if (!this.isInTheFuture)
@@ -1680,7 +1580,7 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1680
1580
  * @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
1681
1581
  */
1682
1582
  format(pattern, config = {}) {
1683
- return (0, import_small_date.format)(this.toDate(), pattern, config);
1583
+ return format(this.toDate(), pattern, config);
1684
1584
  }
1685
1585
  /**
1686
1586
  * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
@@ -1726,20 +1626,23 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1726
1626
  }
1727
1627
  }
1728
1628
  /**
1729
- * @deprecated[04/07/2023]: Use distanceFromNow instead
1730
- */
1629
+ * @deprecated: Use {@link distanceFromNow} instead
1630
+ */
1631
+ // TODO[2023-07-04, Deprecated]: Remove this method in a future version
1731
1632
  fromNow() {
1732
1633
  return TimeDuration_default.ms(this.ms - Date.now());
1733
1634
  }
1734
1635
  /**
1735
- * @deprecated[04/07/2023]: Use distanceFrom instead
1736
- */
1636
+ * @deprecated: Use {@link distanceFrom} instead
1637
+ */
1638
+ // TODO[2023-07-04, Deprecated]: Remove this method in a future version
1737
1639
  from(instant) {
1738
1640
  return TimeDuration_default.ms(this.ms - instant.ms);
1739
1641
  }
1740
1642
  /**
1741
- * @deprecated[04/07/2023]: Use distanceFromUnixTimestamp instead
1742
- */
1643
+ * @deprecated: Use {@link distanceFromUnixTimestamp} instead
1644
+ */
1645
+ // TODO[2023-07-04, Deprecated]: Remove this method in a future version
1743
1646
  fromTimestamp(timestamp2) {
1744
1647
  return TimeDuration_default.ms(this.ms - timestamp2);
1745
1648
  }
@@ -1780,8 +1683,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1780
1683
  return timeInstantBuilder();
1781
1684
  }
1782
1685
  /**
1783
- * @deprecated[19/07/2023] Use {@link fromParameters} instead.
1784
- */
1686
+ * @deprecated[19/07/2023] Use {@link fromParameters} instead.
1687
+ */
1785
1688
  static fromUnits({ date, month, year, hours, minutes, seconds }) {
1786
1689
  const dt = Date.UTC(year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0);
1787
1690
  if (isNaN(dt))
@@ -1839,9 +1742,9 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1839
1742
  return this.toDate().getFullYear();
1840
1743
  }
1841
1744
  /**
1842
- * Returns the week number represented by this instant, according to the ISO 8601 standard.
1745
+ * Returns the week number represented by this instant, according to the ISO 8601 standard.
1843
1746
  * 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.
1844
- */
1747
+ */
1845
1748
  get weekNumber() {
1846
1749
  const date = this.toDate();
1847
1750
  const oneDay = 1e3 * 60 * 60 * 24;
@@ -1852,8 +1755,8 @@ var TimeInstant = class _TimeInstant extends TimeBase {
1852
1755
  return { weekNumber, year: thursdayOfThisWeek.getFullYear() };
1853
1756
  }
1854
1757
  /**
1855
- * This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
1856
- */
1758
+ * This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
1759
+ */
1857
1760
  get _time() {
1858
1761
  return this.asHumanTimestamp();
1859
1762
  }
@@ -1870,7 +1773,7 @@ function isTimeInstant(x) {
1870
1773
  }
1871
1774
  var TimeInstant_default = TimeInstant;
1872
1775
 
1873
- // src/Logger.ts
1776
+ // packages/core/src/Logger.ts
1874
1777
  var LEVELS = ["log", "debug", "info", "warn", "error"];
1875
1778
  var timestamp = () => TimeInstant_default.now().asTimeString();
1876
1779
  var Logger = class {
@@ -1907,7 +1810,7 @@ var Logger = class {
1907
1810
  }
1908
1811
  };
1909
1812
 
1910
- // src/Optional.ts
1813
+ // packages/core/src/Optional.ts
1911
1814
  var Optional = class _Optional {
1912
1815
  _present;
1913
1816
  _value;
@@ -2021,7 +1924,7 @@ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
2021
1924
  }
2022
1925
  };
2023
1926
 
2024
- // src/sorting/ComparisonChain.ts
1927
+ // packages/core/src/sorting/ComparisonChain.ts
2025
1928
  var defaultCompareValueOptions = {
2026
1929
  nullsFirst: false,
2027
1930
  direction: "ASC"
@@ -2063,8 +1966,10 @@ function compareBooleans(options) {
2063
1966
  const fn = (a, b) => {
2064
1967
  if (a === b)
2065
1968
  return 0;
2066
- if (isNullOrUndefined(a)) return opts.nullsFirst ? -1 : 1;
2067
- if (isNullOrUndefined(b)) return opts.nullsFirst ? 1 : -1;
1969
+ if (isNullOrUndefined(a))
1970
+ return opts.nullsFirst ? -1 : 1;
1971
+ if (isNullOrUndefined(b))
1972
+ return opts.nullsFirst ? 1 : -1;
2068
1973
  return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
2069
1974
  };
2070
1975
  return (a, b) => applyDirection(fn(a, b), opts.direction);
@@ -2179,7 +2084,7 @@ function getComparisonFunction(arg) {
2179
2084
  return arg instanceof ComparisonChain ? arg.compare : arg;
2180
2085
  }
2181
2086
 
2182
- // src/sorting/Sorter.ts
2087
+ // packages/core/src/sorting/Sorter.ts
2183
2088
  var defaultCompareValuesOptions = {
2184
2089
  nullsFirst: false
2185
2090
  };
@@ -2245,7 +2150,8 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
2245
2150
  var prioritizeArray = (fns, transform, arr, reversed = false) => {
2246
2151
  return compareNumbers(fns, (t) => {
2247
2152
  const r = transform(t);
2248
- if (!isDefined(r)) return Number.MAX_VALUE;
2153
+ if (!isDefined(r))
2154
+ return Number.MAX_VALUE;
2249
2155
  const indexOf = arr.indexOf(r);
2250
2156
  return indexOf === -1 ? Number.MAX_VALUE : indexOf;
2251
2157
  }, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
@@ -2411,7 +2317,7 @@ var Sorter = {
2411
2317
  };
2412
2318
  var Sorting = Sorter;
2413
2319
 
2414
- // src/time/RandomTimeDuration.ts
2320
+ // packages/core/src/time/RandomTimeDuration.ts
2415
2321
  function randomize(unit) {
2416
2322
  return (a, b) => {
2417
2323
  return TimeDuration_default.fromMs(randomInterval(unit.toMs(a), unit.toMs(b)));
@@ -2427,7 +2333,7 @@ var RandomTimeDuration = class {
2427
2333
  static days = randomize(TimeUnit.DAYS);
2428
2334
  };
2429
2335
 
2430
- // src/time/TimeFrequency.ts
2336
+ // packages/core/src/time/TimeFrequency.ts
2431
2337
  var TimeFrequency = class _TimeFrequency {
2432
2338
  constructor(times, period) {
2433
2339
  this.times = times;
@@ -2448,7 +2354,7 @@ var TimeFrequency = class _TimeFrequency {
2448
2354
  }
2449
2355
  };
2450
2356
 
2451
- // src/time/TimeRange.ts
2357
+ // packages/core/src/time/TimeRange.ts
2452
2358
  var TimeRange = class _TimeRange {
2453
2359
  constructor(start, duration) {
2454
2360
  this.start = start;
@@ -2469,7 +2375,7 @@ var TimeRange = class _TimeRange {
2469
2375
  }
2470
2376
  };
2471
2377
 
2472
- // src/upgrade/errors.ts
2378
+ // packages/core/src/upgrade/errors.ts
2473
2379
  var UnavailableUpgradeError = class extends Error {
2474
2380
  constructor(data, from, to) {
2475
2381
  super(`No transition found to upgrade data from version ${from} to version ${to}.`);
@@ -2487,7 +2393,7 @@ var EmptyUpgradeError = class extends Error {
2487
2393
  }
2488
2394
  };
2489
2395
 
2490
- // src/upgrade/getTransitionsPath.ts
2396
+ // packages/core/src/upgrade/getTransitionsPath.ts
2491
2397
  var DEBUG_ENABLED = false;
2492
2398
  function getTransitionsPath(matrix, from, to) {
2493
2399
  return internalGetTransitionsPath(matrix, from, to, 0, DEBUG_ENABLED);
@@ -2536,7 +2442,7 @@ function printTransitions(transitions) {
2536
2442
  }, "" + transitions[0].from);
2537
2443
  }
2538
2444
 
2539
- // src/upgrade/DataUpgrader.ts
2445
+ // packages/core/src/upgrade/DataUpgrader.ts
2540
2446
  var VERSION_FIELD = "$version";
2541
2447
  var DataUpgrader = class _DataUpgrader {
2542
2448
  constructor(latestVersion) {
@@ -2619,6 +2525,9 @@ export {
2619
2525
  TimeInstant,
2620
2526
  TimeRange,
2621
2527
  TimeUnit,
2528
+ alwaysFalse,
2529
+ alwaysTrue,
2530
+ and,
2622
2531
  asError,
2623
2532
  asPromise,
2624
2533
  average,
@@ -2693,6 +2602,7 @@ export {
2693
2602
  isZero,
2694
2603
  jsonCloneDeep,
2695
2604
  last,
2605
+ makeArrayEmpty,
2696
2606
  mapDefined,
2697
2607
  mapEntries,
2698
2608
  mapFirstTruthy,
@@ -2703,8 +2613,10 @@ export {
2703
2613
  minBy,
2704
2614
  multiplyBy,
2705
2615
  noop,
2616
+ not,
2706
2617
  omit,
2707
2618
  omitFromJsonObject,
2619
+ or,
2708
2620
  pad,
2709
2621
  padLeft,
2710
2622
  padRight,
@@ -2712,7 +2624,9 @@ export {
2712
2624
  pick,
2713
2625
  pluralize,
2714
2626
  promiseSequence,
2627
+ randomId,
2715
2628
  randomInterval,
2629
+ randomNumberInInterval,
2716
2630
  randomPercentage,
2717
2631
  range,
2718
2632
  repeat,
@@ -2739,5 +2653,6 @@ export {
2739
2653
  withTryCatch,
2740
2654
  withTryCatchAsync,
2741
2655
  wrap,
2742
- wrapWithString
2656
+ wrapWithString,
2657
+ xor
2743
2658
  };