@zelgadis87/utils-core 4.3.4 → 4.4.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 (128) hide show
  1. package/dist/Optional.d.ts +1 -1
  2. package/dist/async/RateThrottler.d.ts +2 -1
  3. package/dist/index.d.ts +5 -8
  4. package/dist/lazy/index.d.ts +2 -0
  5. package/dist/sorting/ComparisonChain.d.ts +1 -1
  6. package/dist/sorting/Sorter.d.ts +1 -1
  7. package/dist/sorting/types.d.ts +1 -1
  8. package/dist/time/TimeDuration.d.ts +1 -1
  9. package/dist/time/TimeFrequency.d.ts +1 -1
  10. package/dist/time/TimeRange.d.ts +2 -2
  11. package/dist/time/types.d.ts +1 -1
  12. package/dist/tsconfig.tsbuildinfo +1 -1
  13. package/dist/upgrade/DataUpgrader.d.ts +1 -1
  14. package/dist/upgrade/getTransitionsPath.d.ts +1 -1
  15. package/dist/upgrade/types.d.ts +1 -1
  16. package/dist/utils/{groupBy.d.ts → arrays/groupBy.d.ts} +3 -1
  17. package/dist/utils/{indexBy.d.ts → arrays/indexBy.d.ts} +1 -1
  18. package/dist/utils/{math.d.ts → arrays/statistics.d.ts} +1 -2
  19. package/dist/utils/arrays/uniqBy.d.ts +4 -0
  20. package/dist/{types → utils}/arrays.d.ts +10 -4
  21. package/dist/utils/errors/withTryCatch.d.ts +3 -0
  22. package/dist/{types → utils}/errors.d.ts +1 -0
  23. package/dist/utils/functions/bindThis.d.ts +1 -0
  24. package/dist/utils/{iff.d.ts → functions/iff.d.ts} +3 -3
  25. package/dist/{types → utils}/functions.d.ts +4 -0
  26. package/dist/utils/index.d.ts +13 -19
  27. package/dist/utils/json.d.ts +11 -0
  28. package/dist/{types → utils}/numbers.d.ts +3 -1
  29. package/dist/utils/primitives.d.ts +3 -0
  30. package/dist/utils/random.d.ts +2 -0
  31. package/dist/utils/{entries.d.ts → records/entries.d.ts} +1 -1
  32. package/dist/{types → utils}/records.d.ts +1 -0
  33. package/dist/{types/strings.d.ts → utils/strings/StringParts.d.ts} +2 -15
  34. package/dist/utils/strings.d.ts +17 -0
  35. package/esbuild/index.cjs +548 -697
  36. package/esbuild/index.mjs +540 -693
  37. package/package.json +3 -40
  38. package/src/Logger.ts +1 -1
  39. package/src/Optional.ts +2 -2
  40. package/src/async/Deferred.ts +1 -1
  41. package/src/async/RateThrottler.ts +8 -1
  42. package/src/async/index.ts +1 -0
  43. package/src/index.ts +5 -8
  44. package/src/{Lazy.ts → lazy/Lazy.ts} +1 -1
  45. package/src/{LazyAsync.ts → lazy/LazyAsync.ts} +1 -1
  46. package/src/lazy/index.ts +3 -0
  47. package/src/sorting/ComparisonChain.ts +2 -2
  48. package/src/sorting/Sorter.ts +2 -2
  49. package/src/sorting/types.ts +1 -1
  50. package/src/time/RandomTimeDuration.ts +1 -1
  51. package/src/time/TimeDuration.ts +1 -2
  52. package/src/time/TimeFrequency.ts +1 -1
  53. package/src/time/TimeInstantBuilder.ts +2 -2
  54. package/src/time/TimeRange.ts +2 -2
  55. package/src/time/types.ts +1 -1
  56. package/src/upgrade/DataUpgrader.ts +1 -1
  57. package/src/upgrade/getTransitionsPath.ts +1 -1
  58. package/src/upgrade/types.ts +1 -1
  59. package/src/utils/{groupBy.ts → arrays/groupBy.ts} +1 -1
  60. package/src/utils/{indexBy.ts → arrays/indexBy.ts} +1 -1
  61. package/src/utils/{math.ts → arrays/statistics.ts} +1 -13
  62. package/src/utils/arrays/uniqBy.ts +24 -0
  63. package/src/{types → utils}/arrays.ts +15 -6
  64. package/src/utils/errors/withTryCatch.ts +15 -0
  65. package/src/{types → utils}/errors.ts +2 -0
  66. package/src/utils/functions/bindThis.ts +4 -0
  67. package/src/utils/{iff.ts → functions/iff.ts} +4 -2
  68. package/src/{types → utils}/functions.ts +6 -0
  69. package/src/utils/index.ts +13 -19
  70. package/src/utils/json.ts +49 -0
  71. package/src/utils/{round.ts → numbers/round.ts} +1 -0
  72. package/src/{types → utils}/numbers.ts +15 -1
  73. package/src/utils/primitives.ts +5 -0
  74. package/src/utils/random.ts +9 -0
  75. package/src/utils/{entries.ts → records/entries.ts} +1 -1
  76. package/src/{types → utils}/records.ts +2 -0
  77. package/src/utils/strings/StringParts.ts +114 -0
  78. package/src/utils/strings.ts +91 -0
  79. package/dist/random/index.d.ts +0 -2
  80. package/dist/random/randomInterval.d.ts +0 -1
  81. package/dist/random/randomPercentage.d.ts +0 -1
  82. package/dist/types/index.d.ts +0 -14
  83. package/dist/types/json.d.ts +0 -7
  84. package/dist/utils/bindThis.d.ts +0 -1
  85. package/dist/utils/jsonCloneDeep.d.ts +0 -2
  86. package/dist/utils/noop.d.ts +0 -1
  87. package/dist/utils/omit.d.ts +0 -2
  88. package/dist/utils/sortBy.d.ts +0 -7
  89. package/dist/utils/throttle.d.ts +0 -3
  90. package/dist/utils/uniq.d.ts +0 -1
  91. package/dist/utils/uniqBy.d.ts +0 -2
  92. package/dist/utils/uniqByKey.d.ts +0 -1
  93. package/dist/utils/upsert.d.ts +0 -0
  94. package/dist/utils/withTryCatch.d.ts +0 -2
  95. package/dist/utils/withTryCatchAsync.d.ts +0 -2
  96. package/dist/utils/wrap.d.ts +0 -1
  97. package/src/random/index.ts +0 -3
  98. package/src/random/randomInterval.ts +0 -4
  99. package/src/random/randomPercentage.ts +0 -6
  100. package/src/types/index.ts +0 -20
  101. package/src/types/json.ts +0 -15
  102. package/src/types/strings.ts +0 -191
  103. package/src/utils/bindThis.ts +0 -4
  104. package/src/utils/jsonCloneDeep.ts +0 -31
  105. package/src/utils/noop.ts +0 -2
  106. package/src/utils/omit.ts +0 -8
  107. package/src/utils/sortBy.ts +0 -27
  108. package/src/utils/throttle.ts +0 -10
  109. package/src/utils/uniq.ts +0 -6
  110. package/src/utils/uniqBy.ts +0 -15
  111. package/src/utils/uniqByKey.ts +0 -5
  112. package/src/utils/upsert.ts +0 -2
  113. package/src/utils/withTryCatch.ts +0 -9
  114. package/src/utils/withTryCatchAsync.ts +0 -5
  115. package/src/utils/wrap.ts +0 -4
  116. /package/dist/{Lazy.d.ts → lazy/Lazy.d.ts} +0 -0
  117. /package/dist/{LazyAsync.d.ts → lazy/LazyAsync.d.ts} +0 -0
  118. /package/dist/{types → utils}/booleans.d.ts +0 -0
  119. /package/dist/{types → utils}/empties.d.ts +0 -0
  120. /package/dist/utils/{constant.d.ts → functions/constant.d.ts} +0 -0
  121. /package/dist/{types → utils}/nulls.d.ts +0 -0
  122. /package/dist/utils/{round.d.ts → numbers/round.d.ts} +0 -0
  123. /package/dist/{types → utils}/promises.d.ts +0 -0
  124. /package/src/{types → utils}/booleans.ts +0 -0
  125. /package/src/{types → utils}/empties.ts +0 -0
  126. /package/src/utils/{constant.ts → functions/constant.ts} +0 -0
  127. /package/src/{types → utils}/nulls.ts +0 -0
  128. /package/src/{types → utils}/promises.ts +0 -0
package/esbuild/index.cjs CHANGED
@@ -178,8 +178,6 @@ __export(src_exports, {
178
178
  ErrorCannotInstantiatePresentOptionalWithEmptyValue: () => ErrorCannotInstantiatePresentOptionalWithEmptyValue,
179
179
  ErrorGetEmptyOptional: () => ErrorGetEmptyOptional,
180
180
  ErrorSetEmptyOptional: () => ErrorSetEmptyOptional,
181
- Lazy: () => Lazy,
182
- LazyAsync: () => LazyAsync,
183
181
  Logger: () => Logger,
184
182
  Optional: () => Optional,
185
183
  RandomTimeDuration: () => RandomTimeDuration,
@@ -224,7 +222,10 @@ __export(src_exports, {
224
222
  extendArray: () => extendArray,
225
223
  extendArrayWith: () => extendArrayWith,
226
224
  fill: () => fill,
225
+ first: () => first,
227
226
  flatMapTruthys: () => flatMapTruthys,
227
+ groupByBoolean: () => groupByBoolean,
228
+ groupByBooleanWith: () => groupByBooleanWith,
228
229
  groupByNumber: () => groupByNumber,
229
230
  groupByNumberWith: () => groupByNumberWith,
230
231
  groupByString: () => groupByString,
@@ -272,10 +273,12 @@ __export(src_exports, {
272
273
  multiplyBy: () => multiplyBy,
273
274
  noop: () => noop,
274
275
  omit: () => omit,
276
+ omitFromJsonObject: () => omitFromJsonObject,
275
277
  pad: () => pad,
276
278
  padLeft: () => padLeft,
277
279
  padRight: () => padRight,
278
280
  pick: () => pick,
281
+ pluralize: () => pluralize,
279
282
  promiseSequence: () => promiseSequence,
280
283
  randomInterval: () => randomInterval,
281
284
  randomPercentage: () => randomPercentage,
@@ -288,12 +291,12 @@ __export(src_exports, {
288
291
  roundToNearest: () => roundToNearest,
289
292
  roundToUpper: () => roundToUpper,
290
293
  roundTowardsZero: () => roundTowardsZero,
291
- sortBy: () => sortBy,
292
294
  sortedArray: () => sortedArray,
293
295
  splitWords: () => splitWords,
294
296
  stringToNumber: () => stringToNumber,
295
297
  sum: () => sum,
296
298
  sumBy: () => sumBy,
299
+ tail: () => tail,
297
300
  throttle: () => throttle,
298
301
  tryToParseJson: () => tryToParseJson,
299
302
  uniq: () => uniq,
@@ -302,11 +305,334 @@ __export(src_exports, {
302
305
  upsert: () => upsert,
303
306
  withTryCatch: () => withTryCatch,
304
307
  withTryCatchAsync: () => withTryCatchAsync,
305
- wrap: () => wrap
308
+ wrap: () => wrap,
309
+ wrapWithString: () => wrapWithString
306
310
  });
307
311
  module.exports = __toCommonJS(src_exports);
308
312
 
309
- // src/types/arrays.ts
313
+ // src/async/Deferred.ts
314
+ var DeferredCanceledError = class extends Error {
315
+ constructor() {
316
+ super("Execution canceled");
317
+ }
318
+ };
319
+ var Deferred = class {
320
+ _pending;
321
+ _internals;
322
+ get pending() {
323
+ return this._pending;
324
+ }
325
+ /** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
326
+ get promise() {
327
+ return this._internals.promise;
328
+ }
329
+ constructor() {
330
+ this._pending = true;
331
+ this._internals = this.createInternals();
332
+ }
333
+ resolve(val) {
334
+ if (!this._pending)
335
+ throw new Error("Illegal state exception");
336
+ this.resolveIfPending(val);
337
+ }
338
+ reject(reason) {
339
+ if (!this._pending)
340
+ throw new Error("Illegal state exception");
341
+ this.rejectIfPending(reason);
342
+ }
343
+ cancel() {
344
+ if (!this._pending)
345
+ throw new Error("Illegal state exception");
346
+ this.cancelIfPending();
347
+ }
348
+ resolveIfPending(val) {
349
+ if (!this._pending)
350
+ return;
351
+ this._pending = false;
352
+ this._internals.resolve(val);
353
+ }
354
+ rejectIfPending(reason) {
355
+ if (!this._pending)
356
+ return;
357
+ this._pending = false;
358
+ this._internals.reject(reason);
359
+ }
360
+ cancelIfPending() {
361
+ if (!this._pending)
362
+ return;
363
+ this.reject(new DeferredCanceledError());
364
+ }
365
+ then(onFulfilled, onRejected) {
366
+ return this._internals.promise.then(onFulfilled, onRejected);
367
+ }
368
+ catch(onRejected) {
369
+ return this._internals.promise.catch(onRejected);
370
+ }
371
+ finally(onfinally) {
372
+ return this._internals.promise.finally(onfinally);
373
+ }
374
+ asPromise() {
375
+ return this;
376
+ }
377
+ asCancelablePromise() {
378
+ return this;
379
+ }
380
+ createInternals() {
381
+ let resolveSelf, rejectSelf;
382
+ const promise = new Promise((resolve, reject) => {
383
+ resolveSelf = resolve;
384
+ rejectSelf = reject;
385
+ });
386
+ return {
387
+ promise,
388
+ resolve: resolveSelf,
389
+ reject: rejectSelf
390
+ };
391
+ }
392
+ get [Symbol.toStringTag]() {
393
+ return "[object Deferred]";
394
+ }
395
+ };
396
+ var Deferred_default = Deferred;
397
+
398
+ // src/async/RateThrottler.ts
399
+ var RateThrottler = class {
400
+ constructor(_frequency) {
401
+ this._frequency = _frequency;
402
+ const initialOffset = this.cooldown.divideBy(_frequency.times);
403
+ this._availableSlots = new Array(_frequency.times).fill(0).map((_, i) => TimeInstant.now().addMs(i * initialOffset.ms));
404
+ this._waitingRequests = [];
405
+ }
406
+ _availableSlots;
407
+ _waitingRequests;
408
+ get cooldown() {
409
+ return this._frequency.period;
410
+ }
411
+ async execute(fn) {
412
+ const wrappedFn = async () => {
413
+ const slot = this._availableSlots.shift();
414
+ try {
415
+ return slot.promise().then(() => fn());
416
+ } finally {
417
+ this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
418
+ if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
419
+ }
420
+ };
421
+ if (this._availableSlots.length > 0) {
422
+ return wrappedFn();
423
+ } else {
424
+ const waitingRequest = new Deferred_default();
425
+ this._waitingRequests.push(waitingRequest);
426
+ return waitingRequest.then(() => wrappedFn());
427
+ }
428
+ }
429
+ };
430
+ function throttle(fn, frequence) {
431
+ const semaphore = new RateThrottler(frequence);
432
+ return (...t) => {
433
+ return semaphore.execute(async () => fn(...t));
434
+ };
435
+ }
436
+
437
+ // src/async/Semaphore.ts
438
+ var Semaphore = class {
439
+ constructor(_availableSlots = 1) {
440
+ this._availableSlots = _availableSlots;
441
+ this._queuedRequests = [];
442
+ }
443
+ _queuedRequests;
444
+ _inProgress = 0;
445
+ async _awaitSlot() {
446
+ if (this._availableSlots > 0) {
447
+ this._availableSlots -= 1;
448
+ this._inProgress += 1;
449
+ return void 0;
450
+ } else {
451
+ const deferred = new Deferred_default();
452
+ this._queuedRequests.push(deferred);
453
+ return deferred.asPromise();
454
+ }
455
+ }
456
+ _releaseSlot() {
457
+ const waitingSlotToResolve = this._queuedRequests.shift();
458
+ if (waitingSlotToResolve) {
459
+ waitingSlotToResolve.resolve();
460
+ } else {
461
+ this._availableSlots += 1;
462
+ this._inProgress -= 1;
463
+ }
464
+ }
465
+ async execute(fn, cooldown = TimeDuration.ZERO) {
466
+ return this._awaitSlot().then(() => fn()).finally(() => {
467
+ void cooldown.promise().then(() => this._releaseSlot());
468
+ });
469
+ }
470
+ get availableSlots() {
471
+ return this._availableSlots;
472
+ }
473
+ get queueSize() {
474
+ return this._queuedRequests.length;
475
+ }
476
+ get inProgressSize() {
477
+ return this._inProgress;
478
+ }
479
+ };
480
+
481
+ // src/utils/arrays/groupBy.ts
482
+ function groupByString(arr, field) {
483
+ return groupByStringWith(arr, (t) => t[field]);
484
+ }
485
+ function groupByNumber(arr, field) {
486
+ return groupByNumberWith(arr, (t) => t[field]);
487
+ }
488
+ function groupByBoolean(arr, field) {
489
+ return groupByBooleanWith(arr, (t) => t[field]);
490
+ }
491
+ function groupBySymbol(arr, field) {
492
+ return groupBySymbolWith(arr, (t) => t[field]);
493
+ }
494
+ function groupByStringWith(arr, getter) {
495
+ return doGroupByWith(arr, getter);
496
+ }
497
+ function groupByNumberWith(arr, getter) {
498
+ return doGroupByWith(arr, getter);
499
+ }
500
+ function groupByBooleanWith(arr, getter) {
501
+ return doGroupByWith(arr, (item) => getter(item) ? "true" : "false");
502
+ }
503
+ function groupBySymbolWith(arr, getter) {
504
+ return doGroupByWith(arr, getter);
505
+ }
506
+ function doGroupByWith(arr, getter) {
507
+ return arr.reduce((dict, cur) => {
508
+ const key = getter(cur);
509
+ if (key !== null && key !== void 0) {
510
+ const arr2 = dict[key] ?? [];
511
+ arr2.push(cur);
512
+ dict[key] = arr2;
513
+ }
514
+ return dict;
515
+ }, {});
516
+ }
517
+
518
+ // src/utils/arrays/indexBy.ts
519
+ function indexByString(arr, field) {
520
+ return indexByStringWith(arr, (t) => t[field]);
521
+ }
522
+ function indexByNumber(arr, field) {
523
+ return indexByNumberWith(arr, (t) => t[field]);
524
+ }
525
+ function indexBySymbol(arr, field) {
526
+ return indexBySymbolWith(arr, (t) => t[field]);
527
+ }
528
+ function indexByStringWith(arr, getter) {
529
+ return doIndexByWith(arr, getter);
530
+ }
531
+ function indexByNumberWith(arr, getter) {
532
+ return doIndexByWith(arr, getter);
533
+ }
534
+ function indexBySymbolWith(arr, getter) {
535
+ return doIndexByWith(arr, getter);
536
+ }
537
+ function doIndexByWith(arr, getter) {
538
+ return arr.reduce((dict, cur) => {
539
+ const key = getter(cur);
540
+ if (key !== null && key !== void 0)
541
+ dict[key] = cur;
542
+ return dict;
543
+ }, {});
544
+ }
545
+
546
+ // src/utils/arrays/statistics.ts
547
+ function average(arr) {
548
+ const f = 1 / arr.length;
549
+ return arr.reduce((tot, cur) => tot + cur * f, 0);
550
+ }
551
+ function sum(arr) {
552
+ return arr.reduce((tot, cur) => tot + cur, 0);
553
+ }
554
+ function sumBy(arr, getter) {
555
+ return sum(arr.map(getter));
556
+ }
557
+ function min(arr) {
558
+ if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
559
+ return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
560
+ }
561
+ function minBy(arr, getter) {
562
+ return min(arr.map(getter));
563
+ }
564
+ function max(arr) {
565
+ if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
566
+ return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
567
+ }
568
+ function maxBy(arr, getter) {
569
+ return max(arr.map(getter));
570
+ }
571
+
572
+ // src/utils/functions/bindThis.ts
573
+ function bindThis(fn, _this) {
574
+ return fn.bind(_this);
575
+ }
576
+
577
+ // src/utils/functions/constant.ts
578
+ function constant(v) {
579
+ return () => v;
580
+ }
581
+ function identity(t) {
582
+ return t;
583
+ }
584
+ var constantNull = constant(null);
585
+ var constantTrue = constant(true);
586
+ var constantFalse = constant(false);
587
+ var constantZero = constant(0);
588
+ var constantOne = constant(1);
589
+
590
+ // src/utils/functions/iff.ts
591
+ function iff(firstPredicate, valueIfTrue) {
592
+ if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
593
+ const ret = {
594
+ elseIf: () => ret,
595
+ otherwise: () => valueIfTrue
596
+ };
597
+ return ret;
598
+ } else {
599
+ const ret = {
600
+ elseIf: (elseIf, valueIfElseIfTrue) => iff(elseIf, valueIfElseIfTrue),
601
+ otherwise: (valueIfElse) => valueIfElse
602
+ };
603
+ return ret;
604
+ }
605
+ }
606
+
607
+ // src/utils/functions.ts
608
+ function isFunction(t) {
609
+ return typeof t === "function";
610
+ }
611
+ function noop() {
612
+ }
613
+
614
+ // src/utils/arrays/uniqBy.ts
615
+ function uniq(arr) {
616
+ return uniqBy(arr, identity);
617
+ }
618
+ function uniqBy(arr, getter) {
619
+ return arr.reduce((dict, cur) => {
620
+ const key = getter(cur);
621
+ if (dict.keys.includes(key)) {
622
+ return dict;
623
+ } else {
624
+ return {
625
+ keys: [...dict.keys, key],
626
+ values: [...dict.values, cur]
627
+ };
628
+ }
629
+ }, { keys: [], values: [] }).values;
630
+ }
631
+ function uniqByKey(arr, key) {
632
+ return uniqBy(arr, (item) => item[key]);
633
+ }
634
+
635
+ // src/utils/arrays.ts
310
636
  function ensureArray(t) {
311
637
  return t instanceof Array ? t : [t];
312
638
  }
@@ -351,11 +677,15 @@ function extendArrayWith(arr, propsFn) {
351
677
  function reverse(arr) {
352
678
  return [...arr].reverse();
353
679
  }
354
- function head(arr, defaultValue = null) {
680
+ function first(arr, defaultValue = null) {
355
681
  return arr.length ? arr[0] : defaultValue;
356
682
  }
357
683
  function last(arr, defaultValue = null) {
358
- return head(reverse(arr), defaultValue);
684
+ return arr.length ? arr[arr.length - 1] : defaultValue;
685
+ }
686
+ var head = first;
687
+ function tail(arr) {
688
+ return arr.length ? arr.slice(1) : [];
359
689
  }
360
690
  function sortedArray(arr, sortFn) {
361
691
  return [...arr].sort(sortFn);
@@ -370,7 +700,7 @@ function flatMapTruthys(arr, mapper) {
370
700
  return arr.flatMap(mapper).filter((value) => value !== void 0);
371
701
  }
372
702
 
373
- // src/types/booleans.ts
703
+ // src/utils/booleans.ts
374
704
  function isTrue(x) {
375
705
  return x === true;
376
706
  }
@@ -378,7 +708,19 @@ function isFalse(x) {
378
708
  return x === false;
379
709
  }
380
710
 
381
- // src/types/errors.ts
711
+ // src/utils/errors/withTryCatch.ts
712
+ function withTryCatch(fn) {
713
+ try {
714
+ return [fn(), void 0];
715
+ } catch (e) {
716
+ return [void 0, asError(e)];
717
+ }
718
+ }
719
+ async function withTryCatchAsync(fn) {
720
+ return fn().then((value) => [value, void 0], (e) => [void 0, asError(e)]);
721
+ }
722
+
723
+ // src/utils/errors.ts
382
724
  function asError(e) {
383
725
  if (e === void 0 || e === null)
384
726
  return new Error("Void message");
@@ -394,22 +736,39 @@ function isError(e) {
394
736
  return e instanceof Error;
395
737
  }
396
738
 
397
- // src/types/functions.ts
398
- function isFunction(t) {
399
- return typeof t === "function";
400
- }
401
-
402
- // src/types/json.ts
739
+ // src/utils/json.ts
403
740
  function tryToParseJson(jsonContent) {
404
- try {
405
- const data = JSON.parse(jsonContent);
406
- return [data, null];
407
- } catch (err) {
408
- return [null, asError(err)];
741
+ return withTryCatch(() => JSON.parse(jsonContent));
742
+ }
743
+ function jsonCloneDeep(a) {
744
+ if (null === a || "object" !== typeof a) return a;
745
+ if (a instanceof Date) {
746
+ return new Date(a.getTime());
747
+ } else if (a instanceof Array) {
748
+ const copy = [];
749
+ for (let i = 0, len = a.length; i < len; i++) {
750
+ copy[i] = jsonCloneDeep(a[i]);
751
+ }
752
+ return copy;
753
+ } else if (a instanceof Object) {
754
+ const copy = {};
755
+ for (let attr in a) {
756
+ if (a.hasOwnProperty(attr))
757
+ copy[attr] = jsonCloneDeep(a[attr]);
758
+ }
759
+ return copy;
409
760
  }
761
+ throw new Error("Unable to copy obj! Its type isn't supported.");
762
+ }
763
+ function omitFromJsonObject(o, ...keys) {
764
+ return keys.reduce((obj, key) => {
765
+ delete obj[key];
766
+ return obj;
767
+ }, { ...o });
410
768
  }
769
+ var omit = omitFromJsonObject;
411
770
 
412
- // src/types/nulls.ts
771
+ // src/utils/nulls.ts
413
772
  function ensureDefined(v, name = "value") {
414
773
  if (isDefined(v))
415
774
  return v;
@@ -435,7 +794,26 @@ function ifNullOrUndefined(source, callback) {
435
794
  callback();
436
795
  }
437
796
 
438
- // src/types/numbers.ts
797
+ // src/utils/numbers/round.ts
798
+ var roundModes = {
799
+ "toNearest": Math.round,
800
+ "toLower": Math.floor,
801
+ "toUpper": Math.ceil,
802
+ "towardsZero": (n) => n > 0 ? Math.floor(n) : Math.ceil(n),
803
+ "awayFromZero": (n) => n > 0 ? Math.ceil(n) : Math.floor(n)
804
+ };
805
+ function round(n, precision = 0, mode = "toNearest") {
806
+ const base = 10;
807
+ const power = Math.pow(base, precision);
808
+ return roundModes[mode](n * power) / power;
809
+ }
810
+ var roundToNearest = (n, precision = 0) => round(n, precision, "toNearest");
811
+ var roundToLower = (n, precision = 0) => round(n, precision, "toLower");
812
+ var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
813
+ var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
814
+ var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
815
+
816
+ // src/utils/numbers.ts
439
817
  function ensurePositiveNumber(v, name = "value") {
440
818
  if (v !== void 0 && v !== null && v > 0)
441
819
  return v;
@@ -480,8 +858,19 @@ function isNegativeNumber(v) {
480
858
  function isZero(v) {
481
859
  return v === 0;
482
860
  }
861
+ function clamp(n, min2, max2) {
862
+ if (min2 === null || max2 === null || n === null || isNaN(min2) || isNaN(max2) || isNaN(n) || min2 > max2)
863
+ throw new Error();
864
+ if (n > max2) {
865
+ return max2;
866
+ } else if (n < min2) {
867
+ return min2;
868
+ } else {
869
+ return n;
870
+ }
871
+ }
483
872
 
484
- // src/types/promises.ts
873
+ // src/utils/promises.ts
485
874
  function asPromise(promisable) {
486
875
  return Promise.resolve(promisable);
487
876
  }
@@ -499,7 +888,26 @@ function delayPromise(duration) {
499
888
  return (result) => duration.promise().then(() => result);
500
889
  }
501
890
 
502
- // src/types/records.ts
891
+ // src/utils/random.ts
892
+ function randomInterval(min2, max2) {
893
+ return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
894
+ }
895
+ function randomPercentage(min2, max2) {
896
+ return randomInterval(min2, max2) / 100;
897
+ }
898
+
899
+ // src/utils/records/entries.ts
900
+ function dictToEntries(obj) {
901
+ return Object.entries(obj);
902
+ }
903
+ function entriesToDict(entries) {
904
+ return Object.fromEntries(entries);
905
+ }
906
+ function mapEntries(dict, mapper) {
907
+ return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
908
+ }
909
+
910
+ // src/utils/records.ts
503
911
  function dictToList(obj) {
504
912
  return Object.keys(obj).map((key) => obj[key]);
505
913
  }
@@ -510,50 +918,7 @@ function pick(o, keys) {
510
918
  }, {});
511
919
  }
512
920
 
513
- // src/types/strings.ts
514
- function hashCode(str) {
515
- let hash = 0;
516
- for (let i = 0; i < str.length; ++i)
517
- hash = Math.imul(31, hash) + str.charCodeAt(i);
518
- return hash | 0;
519
- }
520
- function repeat(char, times) {
521
- return times > 0 ? range(0, times - 1).map((_) => char).join("") : "";
522
- }
523
- function capitalizeWord(word) {
524
- return word[0].toUpperCase() + word.substring(1).toLowerCase();
525
- }
526
- function splitWords(text, regEx = /\s+/) {
527
- return text.split(regEx).filter((t) => t.length > 0);
528
- }
529
- function stringToNumber(s) {
530
- if (isNullOrUndefined(s))
531
- return null;
532
- return Number(s);
533
- }
534
- function pad(str, n, char, where = "left") {
535
- const length = ensureDefined(str).length;
536
- if (length >= ensureDefined(n)) return str;
537
- if (ensureDefined(char).length !== 1)
538
- throw new Error("Illegal pad character");
539
- const padding = repeat(char, n - length);
540
- return (where === "left" ? padding : "") + str + (where === "right" ? padding : "");
541
- }
542
- function padLeft(str, n, char) {
543
- return pad(str, n, char, "left");
544
- }
545
- function padRight(str, n, char) {
546
- return pad(str, n, char, "right");
547
- }
548
- function ellipsis(str, maxLength, padChar, padWhere = "left") {
549
- if (maxLength < 4)
550
- throw new Error("Invalid argument maxLength");
551
- if (str.length <= maxLength) {
552
- return pad(str, maxLength, padChar, padWhere);
553
- } else {
554
- return str.substring(0, maxLength - 3) + "...";
555
- }
556
- }
921
+ // src/utils/strings/StringParts.ts
557
922
  var StringParts = class _StringParts {
558
923
  _parts;
559
924
  constructor(...parts) {
@@ -576,8 +941,8 @@ var StringParts = class _StringParts {
576
941
  return this._parts;
577
942
  }
578
943
  get tail() {
579
- const [_first, ...tail] = this.parts;
580
- return tail;
944
+ const [_first, ...tail2] = this.parts;
945
+ return tail2;
581
946
  }
582
947
  get first() {
583
948
  return this._parts[0] ?? null;
@@ -605,179 +970,102 @@ var StringParts = class _StringParts {
605
970
  return this.capitalizeEach().join("");
606
971
  }
607
972
  toHumanCase() {
608
- return this.capitalizeFirst().join(" ");
609
- }
610
- join(separator) {
611
- return this.parts.join(separator);
612
- }
613
- mergeWith({ parts: otherParts }) {
614
- return new _StringParts(...this.parts, ...otherParts);
615
- }
616
- slice(start, end) {
617
- return new _StringParts(...this.parts.slice(start, end));
618
- }
619
- splice(start, deleteCount, ...items) {
620
- return new _StringParts(...this.parts.splice(start, deleteCount, ...items));
621
- }
622
- push(part) {
623
- return new _StringParts(...this.parts, part);
624
- }
625
- shift(part) {
626
- return new _StringParts(part, ...this.parts);
627
- }
628
- reverse() {
629
- return new _StringParts(...this.parts.reverse());
630
- }
631
- static fromString = (s, separator = /\s+/g) => {
632
- if (s === null || separator === null)
633
- throw new Error("Invalid arguments");
634
- return new _StringParts(...s.split(separator));
635
- };
636
- static fromParts = (...parts) => {
637
- return new _StringParts(...parts);
638
- };
639
- };
640
-
641
- // src/Lazy.ts
642
- var Lazy = class _Lazy {
643
- _value = void 0;
644
- _initialized = false;
645
- _generator;
646
- constructor(generator) {
647
- this._generator = ensureDefined(generator);
648
- }
649
- get value() {
650
- return this._value;
651
- }
652
- getOrCreate() {
653
- if (!this._initialized) {
654
- this._value = this._generator();
655
- this._initialized = true;
656
- }
657
- return this._value;
658
- }
659
- getOrThrow(errorMessage) {
660
- if (!this._initialized)
661
- throw new Error(errorMessage);
662
- return this._value;
663
- }
664
- or(t) {
665
- if (!this._initialized) {
666
- return t;
667
- } else {
668
- return this._value;
669
- }
670
- }
671
- isPresent() {
672
- return this._initialized;
673
- }
674
- isEmpty() {
675
- return !this._initialized;
676
- }
677
- ifPresent(fn) {
678
- if (this.isPresent()) {
679
- fn(this._value);
680
- }
681
- }
682
- ifEmpty(fn) {
683
- if (this.isEmpty()) {
684
- fn();
685
- }
686
- }
687
- apply(fnPresent, fnEmpty) {
688
- if (this.isPresent()) {
689
- fnPresent(this._value);
690
- } else {
691
- fnEmpty();
692
- }
693
- }
694
- static of(generator) {
695
- return new _Lazy(generator);
696
- }
697
- };
698
-
699
- // src/LazyAsync.ts
700
- var LazyAsync = class _LazyAsync {
701
- _promise = void 0;
702
- _pending = false;
703
- _resolvedValue = void 0;
704
- _error = void 0;
705
- _generator;
706
- constructor(generator) {
707
- this._generator = ensureDefined(generator);
708
- }
709
- getOrCreate() {
710
- if (this.isEmpty()) {
711
- this._pending = true;
712
- this._promise = this._generator();
713
- this._promise.then((value) => {
714
- this._pending = false;
715
- this._resolvedValue = value;
716
- }, (err) => {
717
- this._pending = false;
718
- this._error = err;
719
- });
720
- }
721
- return this._promise;
722
- }
723
- isPresent() {
724
- return this._promise !== void 0;
725
- }
726
- isEmpty() {
727
- return this._promise === void 0;
728
- }
729
- isPending() {
730
- return this.isPresent() && this._pending === true;
731
- }
732
- isReady() {
733
- return this.isPresent() && this._pending === false;
734
- }
735
- isResolved() {
736
- return this.isReady() && this._error === void 0;
737
- }
738
- isError() {
739
- return this.isReady() && this._error !== void 0;
740
- }
741
- ifPresent(fn) {
742
- if (this.isPresent()) {
743
- fn(this._promise);
744
- }
973
+ return this.capitalizeFirst().join(" ");
745
974
  }
746
- ifEmpty(fn) {
747
- if (this.isEmpty()) {
748
- fn();
749
- }
975
+ join(separator) {
976
+ return this.parts.join(separator);
750
977
  }
751
- ifPending(fn) {
752
- if (this.isPending()) {
753
- fn(this._promise);
754
- }
978
+ mergeWith({ parts: otherParts }) {
979
+ return new _StringParts(...this.parts, ...otherParts);
755
980
  }
756
- ifReady(fn) {
757
- if (this.isReady()) {
758
- fn(this._promise);
759
- }
981
+ slice(start, end) {
982
+ return new _StringParts(...this.parts.slice(start, end));
760
983
  }
761
- ifResolved(fn) {
762
- if (this.isResolved()) {
763
- fn(this._resolvedValue);
764
- }
984
+ splice(start, deleteCount, ...items) {
985
+ return new _StringParts(...this.parts.splice(start, deleteCount, ...items));
765
986
  }
766
- ifError(fn) {
767
- if (this.isError()) {
768
- fn(this._error);
769
- }
987
+ push(part) {
988
+ return new _StringParts(...this.parts, part);
770
989
  }
771
- getOrThrow(errorMessage) {
772
- if (!this._promise)
773
- throw new Error(errorMessage);
774
- return this._promise;
990
+ shift(part) {
991
+ return new _StringParts(part, ...this.parts);
775
992
  }
776
- static of(generator) {
777
- return new _LazyAsync(generator);
993
+ reverse() {
994
+ return new _StringParts(...this.parts.reverse());
778
995
  }
996
+ static fromString = (s, separator = /\s+/g) => {
997
+ if (s === null || separator === null)
998
+ throw new Error("Invalid arguments");
999
+ return new _StringParts(...s.split(separator));
1000
+ };
1001
+ static fromParts = (...parts) => {
1002
+ return new _StringParts(...parts);
1003
+ };
779
1004
  };
780
1005
 
1006
+ // src/utils/strings.ts
1007
+ function hashCode(str) {
1008
+ let hash = 0;
1009
+ for (let i = 0; i < str.length; ++i)
1010
+ hash = Math.imul(31, hash) + str.charCodeAt(i);
1011
+ return hash | 0;
1012
+ }
1013
+ function repeat(char, times) {
1014
+ return times > 0 ? range(0, times - 1).map((_) => char).join("") : "";
1015
+ }
1016
+ function capitalizeWord(word) {
1017
+ return word[0].toUpperCase() + word.substring(1).toLowerCase();
1018
+ }
1019
+ function splitWords(text, regEx = /\s+/) {
1020
+ return text.split(regEx).filter((t) => t.length > 0);
1021
+ }
1022
+ function stringToNumber(s) {
1023
+ if (isNullOrUndefined(s))
1024
+ return null;
1025
+ return Number(s);
1026
+ }
1027
+ function pad(str, n, char, where = "left") {
1028
+ const length = ensureDefined(str).length;
1029
+ if (length >= ensureDefined(n)) return str;
1030
+ if (ensureDefined(char).length !== 1)
1031
+ throw new Error("Illegal pad character");
1032
+ const padding = repeat(char, n - length);
1033
+ return (where === "left" ? padding : "") + str + (where === "right" ? padding : "");
1034
+ }
1035
+ function padLeft(str, n, char) {
1036
+ return pad(str, n, char, "left");
1037
+ }
1038
+ function padRight(str, n, char) {
1039
+ return pad(str, n, char, "right");
1040
+ }
1041
+ function ellipsis(str, maxLength, padChar, padWhere = "left") {
1042
+ if (maxLength < 4)
1043
+ throw new Error("Invalid argument maxLength");
1044
+ if (str.length <= maxLength) {
1045
+ return pad(str, maxLength, padChar, padWhere);
1046
+ } else {
1047
+ return str.substring(0, maxLength - 3) + "...";
1048
+ }
1049
+ }
1050
+ function pluralize(n, singular, plural) {
1051
+ if (!singular || !singular.length)
1052
+ throw new Error();
1053
+ if (n === 1)
1054
+ return singular;
1055
+ plural = plural ?? singular + "s";
1056
+ const firstUppercase = singular.charAt(0) === singular.charAt(0).toUpperCase();
1057
+ if (firstUppercase) {
1058
+ const PLURAL = plural.toUpperCase();
1059
+ const isAllUppercase = plural === PLURAL;
1060
+ plural = isAllUppercase ? PLURAL : plural.charAt(0).toUpperCase() + plural.slice(1).toLowerCase();
1061
+ }
1062
+ return plural;
1063
+ }
1064
+ function wrapWithString(str, delimiter) {
1065
+ return delimiter + str + delimiter;
1066
+ }
1067
+ var wrap = wrapWithString;
1068
+
781
1069
  // src/time/TimeInstant.ts
782
1070
  var import_small_date = __toESM(require_lib());
783
1071
 
@@ -899,101 +1187,6 @@ var TimeBase = class {
899
1187
  }
900
1188
  };
901
1189
 
902
- // src/async/Deferred.ts
903
- var DeferredCanceledError = class extends Error {
904
- constructor() {
905
- super("Execution canceled");
906
- }
907
- };
908
- var Deferred = class {
909
- _pending;
910
- _internals;
911
- get pending() {
912
- return this._pending;
913
- }
914
- /** @deprecated: Use resolve, then and catch directly; use asPromise to return a promise type. */
915
- get promise() {
916
- return this._internals.promise;
917
- }
918
- constructor() {
919
- this._pending = true;
920
- this._internals = this.createInternals();
921
- }
922
- resolve(val) {
923
- if (!this._pending)
924
- throw new Error("Illegal state exception");
925
- this.resolveIfPending(val);
926
- }
927
- reject(reason) {
928
- if (!this._pending)
929
- throw new Error("Illegal state exception");
930
- this.rejectIfPending(reason);
931
- }
932
- cancel() {
933
- if (!this._pending)
934
- throw new Error("Illegal state exception");
935
- this.cancelIfPending();
936
- }
937
- resolveIfPending(val) {
938
- if (!this._pending)
939
- return;
940
- this._pending = false;
941
- this._internals.resolve(val);
942
- }
943
- rejectIfPending(reason) {
944
- if (!this._pending)
945
- return;
946
- this._pending = false;
947
- this._internals.reject(reason);
948
- }
949
- cancelIfPending() {
950
- if (!this._pending)
951
- return;
952
- this.reject(new DeferredCanceledError());
953
- }
954
- then(onFulfilled, onRejected) {
955
- return this._internals.promise.then(onFulfilled, onRejected);
956
- }
957
- catch(onRejected) {
958
- return this._internals.promise.catch(onRejected);
959
- }
960
- finally(onfinally) {
961
- return this._internals.promise.finally(onfinally);
962
- }
963
- asPromise() {
964
- return this;
965
- }
966
- asCancelablePromise() {
967
- return this;
968
- }
969
- createInternals() {
970
- let resolveSelf, rejectSelf;
971
- const promise = new Promise((resolve, reject) => {
972
- resolveSelf = resolve;
973
- rejectSelf = reject;
974
- });
975
- return {
976
- promise,
977
- resolve: resolveSelf,
978
- reject: rejectSelf
979
- };
980
- }
981
- get [Symbol.toStringTag]() {
982
- return "[object Deferred]";
983
- }
984
- };
985
- var Deferred_default = Deferred;
986
-
987
- // src/random/randomInterval.ts
988
- function randomInterval(min2, max2) {
989
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
990
- }
991
-
992
- // src/random/randomPercentage.ts
993
- function randomPercentage(min2, max2) {
994
- return randomInterval(min2, max2) / 100;
995
- }
996
-
997
1190
  // src/time/TimeDuration.ts
998
1191
  var TimeDuration = class _TimeDuration extends TimeBase {
999
1192
  constructor(value, unit) {
@@ -1658,10 +1851,6 @@ function isTimeInstant(x) {
1658
1851
  }
1659
1852
  var TimeInstant_default = TimeInstant;
1660
1853
 
1661
- // src/utils/noop.ts
1662
- function noop() {
1663
- }
1664
-
1665
1854
  // src/Logger.ts
1666
1855
  var LEVELS = ["log", "debug", "info", "warn", "error"];
1667
1856
  var timestamp = () => TimeInstant_default.now().asTimeString();
@@ -1789,120 +1978,30 @@ var Optional = class _Optional {
1789
1978
  return new _Optional(void 0);
1790
1979
  }
1791
1980
  static of(t) {
1792
- if (isNullOrUndefined(t))
1793
- throw new ErrorCannotInstantiatePresentOptionalWithEmptyValue();
1794
- return new _Optional(t);
1795
- }
1796
- static ofNullable(t) {
1797
- return new _Optional(t);
1798
- }
1799
- };
1800
- var ErrorGetEmptyOptional = class extends Error {
1801
- constructor() {
1802
- super("Cannot retrieve a value from an EmptyOptional.");
1803
- }
1804
- };
1805
- var ErrorSetEmptyOptional = class extends Error {
1806
- constructor() {
1807
- super("Cannot set a null or undefined value.");
1808
- }
1809
- };
1810
- var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
1811
- constructor() {
1812
- super("Cannot initialize a PresentOptional with a null or undefined value.");
1813
- }
1814
- };
1815
-
1816
- // src/async/RateThrottler.ts
1817
- var RateThrottler = class {
1818
- constructor(_frequency) {
1819
- this._frequency = _frequency;
1820
- const initialOffset = this.cooldown.divideBy(_frequency.times);
1821
- this._availableSlots = new Array(_frequency.times).fill(0).map((_, i) => TimeInstant.now().addMs(i * initialOffset.ms));
1822
- this._waitingRequests = [];
1823
- }
1824
- _availableSlots;
1825
- _waitingRequests;
1826
- get cooldown() {
1827
- return this._frequency.period;
1828
- }
1829
- async execute(fn) {
1830
- const wrappedFn = async () => {
1831
- const slot = this._availableSlots.shift();
1832
- try {
1833
- return slot.promise().then(() => fn());
1834
- } finally {
1835
- this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
1836
- if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
1837
- }
1838
- };
1839
- if (this._availableSlots.length > 0) {
1840
- return wrappedFn();
1841
- } else {
1842
- const waitingRequest = new Deferred_default();
1843
- this._waitingRequests.push(waitingRequest);
1844
- return waitingRequest.then(() => wrappedFn());
1845
- }
1846
- }
1847
- };
1848
-
1849
- // src/async/Semaphore.ts
1850
- var Semaphore = class {
1851
- constructor(_availableSlots = 1) {
1852
- this._availableSlots = _availableSlots;
1853
- this._queuedRequests = [];
1854
- }
1855
- _queuedRequests;
1856
- _inProgress = 0;
1857
- async _awaitSlot() {
1858
- if (this._availableSlots > 0) {
1859
- this._availableSlots -= 1;
1860
- this._inProgress += 1;
1861
- return void 0;
1862
- } else {
1863
- const deferred = new Deferred_default();
1864
- this._queuedRequests.push(deferred);
1865
- return deferred.asPromise();
1866
- }
1867
- }
1868
- _releaseSlot() {
1869
- const waitingSlotToResolve = this._queuedRequests.shift();
1870
- if (waitingSlotToResolve) {
1871
- waitingSlotToResolve.resolve();
1872
- } else {
1873
- this._availableSlots += 1;
1874
- this._inProgress -= 1;
1875
- }
1981
+ if (isNullOrUndefined(t))
1982
+ throw new ErrorCannotInstantiatePresentOptionalWithEmptyValue();
1983
+ return new _Optional(t);
1876
1984
  }
1877
- async execute(fn, cooldown = TimeDuration.ZERO) {
1878
- return this._awaitSlot().then(() => fn()).finally(() => {
1879
- void cooldown.promise().then(() => this._releaseSlot());
1880
- });
1985
+ static ofNullable(t) {
1986
+ return new _Optional(t);
1881
1987
  }
1882
- get availableSlots() {
1883
- return this._availableSlots;
1988
+ };
1989
+ var ErrorGetEmptyOptional = class extends Error {
1990
+ constructor() {
1991
+ super("Cannot retrieve a value from an EmptyOptional.");
1884
1992
  }
1885
- get queueSize() {
1886
- return this._queuedRequests.length;
1993
+ };
1994
+ var ErrorSetEmptyOptional = class extends Error {
1995
+ constructor() {
1996
+ super("Cannot set a null or undefined value.");
1887
1997
  }
1888
- get inProgressSize() {
1889
- return this._inProgress;
1998
+ };
1999
+ var ErrorCannotInstantiatePresentOptionalWithEmptyValue = class extends Error {
2000
+ constructor() {
2001
+ super("Cannot initialize a PresentOptional with a null or undefined value.");
1890
2002
  }
1891
2003
  };
1892
2004
 
1893
- // src/utils/constant.ts
1894
- function constant(v) {
1895
- return () => v;
1896
- }
1897
- function identity(t) {
1898
- return t;
1899
- }
1900
- var constantNull = constant(null);
1901
- var constantTrue = constant(true);
1902
- var constantFalse = constant(false);
1903
- var constantZero = constant(0);
1904
- var constantOne = constant(1);
1905
-
1906
2005
  // src/sorting/ComparisonChain.ts
1907
2006
  var defaultCompareValueOptions = {
1908
2007
  nullsFirst: false,
@@ -2239,7 +2338,7 @@ var top = (fns, arr, n) => {
2239
2338
  var bottom = (fns, arr, n) => {
2240
2339
  return sort(fns, arr).slice(-Math.max(0, n)).reverse();
2241
2340
  };
2242
- var first = (fns, arr) => {
2341
+ var first2 = (fns, arr) => {
2243
2342
  return arr.length ? top(fns, arr, 1)[0] : null;
2244
2343
  };
2245
2344
  var last2 = (fns, arr) => {
@@ -2269,7 +2368,7 @@ function doCreateWithFunctions(fns) {
2269
2368
  return bottom(fns, arr, n);
2270
2369
  },
2271
2370
  first: (arr) => {
2272
- return first(fns, arr);
2371
+ return first2(fns, arr);
2273
2372
  },
2274
2373
  last: (arr) => {
2275
2374
  return last2(fns, arr);
@@ -2351,258 +2450,6 @@ var TimeRange = class _TimeRange {
2351
2450
  }
2352
2451
  };
2353
2452
 
2354
- // src/utils/bindThis.ts
2355
- function bindThis(fn, _this) {
2356
- return fn.bind(_this);
2357
- }
2358
-
2359
- // src/utils/entries.ts
2360
- function dictToEntries(obj) {
2361
- return Object.entries(obj);
2362
- }
2363
- function entriesToDict(entries) {
2364
- return Object.fromEntries(entries);
2365
- }
2366
- function mapEntries(dict, mapper) {
2367
- return entriesToDict(dictToEntries(dict).map((entry) => mapper(entry)));
2368
- }
2369
-
2370
- // src/utils/groupBy.ts
2371
- function groupByString(arr, field) {
2372
- return groupByStringWith(arr, (t) => t[field]);
2373
- }
2374
- function groupByNumber(arr, field) {
2375
- return groupByNumberWith(arr, (t) => t[field]);
2376
- }
2377
- function groupBySymbol(arr, field) {
2378
- return groupBySymbolWith(arr, (t) => t[field]);
2379
- }
2380
- function groupByStringWith(arr, getter) {
2381
- return doGroupByWith(arr, getter);
2382
- }
2383
- function groupByNumberWith(arr, getter) {
2384
- return doGroupByWith(arr, getter);
2385
- }
2386
- function groupBySymbolWith(arr, getter) {
2387
- return doGroupByWith(arr, getter);
2388
- }
2389
- function doGroupByWith(arr, getter) {
2390
- return arr.reduce((dict, cur) => {
2391
- const key = getter(cur);
2392
- if (key !== null && key !== void 0) {
2393
- const arr2 = dict[key] ?? [];
2394
- arr2.push(cur);
2395
- dict[key] = arr2;
2396
- }
2397
- return dict;
2398
- }, {});
2399
- }
2400
-
2401
- // src/utils/iff.ts
2402
- function iff(firstPredicate, valueIfTrue) {
2403
- if (firstPredicate === true || firstPredicate instanceof Function && firstPredicate() === true) {
2404
- const ret = {
2405
- elseIf: () => ret,
2406
- otherwise: () => valueIfTrue
2407
- };
2408
- return ret;
2409
- } else {
2410
- const ret = {
2411
- elseIf: (elseIf, valueIfElseIfTrue) => iff(elseIf, valueIfElseIfTrue),
2412
- otherwise: (valueIfElse) => valueIfElse
2413
- };
2414
- return ret;
2415
- }
2416
- }
2417
-
2418
- // src/utils/indexBy.ts
2419
- function indexByString(arr, field) {
2420
- return indexByStringWith(arr, (t) => t[field]);
2421
- }
2422
- function indexByNumber(arr, field) {
2423
- return indexByNumberWith(arr, (t) => t[field]);
2424
- }
2425
- function indexBySymbol(arr, field) {
2426
- return indexBySymbolWith(arr, (t) => t[field]);
2427
- }
2428
- function indexByStringWith(arr, getter) {
2429
- return doIndexByWith(arr, getter);
2430
- }
2431
- function indexByNumberWith(arr, getter) {
2432
- return doIndexByWith(arr, getter);
2433
- }
2434
- function indexBySymbolWith(arr, getter) {
2435
- return doIndexByWith(arr, getter);
2436
- }
2437
- function doIndexByWith(arr, getter) {
2438
- return arr.reduce((dict, cur) => {
2439
- const key = getter(cur);
2440
- if (key !== null && key !== void 0)
2441
- dict[key] = cur;
2442
- return dict;
2443
- }, {});
2444
- }
2445
-
2446
- // src/utils/jsonCloneDeep.ts
2447
- function jsonCloneDeep(a) {
2448
- if (null === a || "object" !== typeof a) return a;
2449
- if (a instanceof Date) {
2450
- return new Date(a.getTime());
2451
- } else if (a instanceof Array) {
2452
- const copy = [];
2453
- for (let i = 0, len = a.length; i < len; i++) {
2454
- copy[i] = jsonCloneDeep(a[i]);
2455
- }
2456
- return copy;
2457
- } else if (a instanceof Object) {
2458
- const copy = {};
2459
- for (let attr in a) {
2460
- if (a.hasOwnProperty(attr))
2461
- copy[attr] = jsonCloneDeep(a[attr]);
2462
- }
2463
- return copy;
2464
- }
2465
- throw new Error("Unable to copy obj! Its type isn't supported.");
2466
- }
2467
-
2468
- // src/utils/math.ts
2469
- function clamp(n, min2, max2) {
2470
- if (min2 === null || max2 === null || n === null || isNaN(min2) || isNaN(max2) || isNaN(n) || min2 > max2)
2471
- throw new Error();
2472
- if (n > max2) {
2473
- return max2;
2474
- } else if (n < min2) {
2475
- return min2;
2476
- } else {
2477
- return n;
2478
- }
2479
- }
2480
- function average(arr) {
2481
- const f = 1 / arr.length;
2482
- return arr.reduce((tot, cur) => tot + cur * f, 0);
2483
- }
2484
- function sum(arr) {
2485
- return arr.reduce((tot, cur) => tot + cur, 0);
2486
- }
2487
- function sumBy(arr, getter) {
2488
- return sum(arr.map(getter));
2489
- }
2490
- function min(arr) {
2491
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
2492
- return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
2493
- }
2494
- function minBy(arr, getter) {
2495
- return min(arr.map(getter));
2496
- }
2497
- function max(arr) {
2498
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
2499
- return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
2500
- }
2501
- function maxBy(arr, getter) {
2502
- return max(arr.map(getter));
2503
- }
2504
-
2505
- // src/utils/omit.ts
2506
- function omit(o, ...keys) {
2507
- return keys.reduce((obj, key) => {
2508
- delete obj[key];
2509
- return obj;
2510
- }, { ...o });
2511
- }
2512
-
2513
- // src/utils/round.ts
2514
- var roundModes = {
2515
- "toNearest": Math.round,
2516
- "toLower": Math.floor,
2517
- "toUpper": Math.ceil,
2518
- "towardsZero": (n) => n > 0 ? Math.floor(n) : Math.ceil(n),
2519
- "awayFromZero": (n) => n > 0 ? Math.ceil(n) : Math.floor(n)
2520
- };
2521
- function round(n, precision = 0, mode = "toNearest") {
2522
- const base = 10;
2523
- const power = Math.pow(base, precision);
2524
- return roundModes[mode](n * power) / power;
2525
- }
2526
- var roundToNearest = (n, precision = 0) => round(n, precision, "toNearest");
2527
- var roundToLower = (n, precision = 0) => round(n, precision, "toLower");
2528
- var roundToUpper = (n, precision = 0) => round(n, precision, "toUpper");
2529
- var roundTowardsZero = (n, precision = 0) => round(n, precision, "towardsZero");
2530
- var roundAwayFromZero = (n, precision = 0) => round(n, precision, "awayFromZero");
2531
-
2532
- // src/utils/sortBy.ts
2533
- function sortBy(keyOrGetter, direction = "ASC", nulls = "LAST") {
2534
- const directionNum = direction === "ASC" ? -1 : 1;
2535
- const nullsNum = nulls === "LAST" ? -1 : 1;
2536
- const sortByNum = (a, b) => {
2537
- if (a === b)
2538
- return -1;
2539
- const aDefined = !(a === null || a === void 0 || isNaN(a));
2540
- const bDefined = !(b === null || b === void 0 || isNaN(b));
2541
- if (!aDefined && !bDefined)
2542
- return -1;
2543
- if (aDefined !== bDefined)
2544
- return nullsNum * (aDefined ? 1 : -1);
2545
- return (a > b ? -1 : 1) * directionNum;
2546
- };
2547
- if (typeof keyOrGetter === "function") {
2548
- return (a, b) => sortByNum(keyOrGetter(a), keyOrGetter(b));
2549
- } else {
2550
- return (a, b) => sortByNum(a[keyOrGetter], b[keyOrGetter]);
2551
- }
2552
- }
2553
-
2554
- // src/utils/throttle.ts
2555
- function throttle(fn, frequence) {
2556
- const semaphore = new RateThrottler(frequence);
2557
- return (...t) => {
2558
- return semaphore.execute(async () => fn(...t));
2559
- };
2560
- }
2561
-
2562
- // src/utils/uniqBy.ts
2563
- function uniqBy(arr, getter) {
2564
- return arr.reduce((dict, cur) => {
2565
- const key = getter(cur);
2566
- if (dict.keys.includes(key)) {
2567
- return dict;
2568
- } else {
2569
- return {
2570
- keys: [...dict.keys, key],
2571
- values: [...dict.values, cur]
2572
- };
2573
- }
2574
- }, { keys: [], values: [] }).values;
2575
- }
2576
-
2577
- // src/utils/uniq.ts
2578
- function uniq(arr) {
2579
- return uniqBy(arr, identity);
2580
- }
2581
-
2582
- // src/utils/uniqByKey.ts
2583
- function uniqByKey(arr, key) {
2584
- return uniqBy(arr, (item) => item[key]);
2585
- }
2586
-
2587
- // src/utils/withTryCatch.ts
2588
- function withTryCatch(fn) {
2589
- try {
2590
- return fn();
2591
- } catch (e) {
2592
- return asError(e);
2593
- }
2594
- }
2595
-
2596
- // src/utils/withTryCatchAsync.ts
2597
- async function withTryCatchAsync(fn) {
2598
- return fn().catch((e) => asError(e));
2599
- }
2600
-
2601
- // src/utils/wrap.ts
2602
- function wrap(str, delimiter) {
2603
- return delimiter + str + delimiter;
2604
- }
2605
-
2606
2453
  // src/upgrade/errors.ts
2607
2454
  var UnavailableUpgradeError = class extends Error {
2608
2455
  constructor(data, from, to) {
@@ -2739,8 +2586,6 @@ function isUpgradable(obj) {
2739
2586
  ErrorCannotInstantiatePresentOptionalWithEmptyValue,
2740
2587
  ErrorGetEmptyOptional,
2741
2588
  ErrorSetEmptyOptional,
2742
- Lazy,
2743
- LazyAsync,
2744
2589
  Logger,
2745
2590
  Optional,
2746
2591
  RandomTimeDuration,
@@ -2785,7 +2630,10 @@ function isUpgradable(obj) {
2785
2630
  extendArray,
2786
2631
  extendArrayWith,
2787
2632
  fill,
2633
+ first,
2788
2634
  flatMapTruthys,
2635
+ groupByBoolean,
2636
+ groupByBooleanWith,
2789
2637
  groupByNumber,
2790
2638
  groupByNumberWith,
2791
2639
  groupByString,
@@ -2833,10 +2681,12 @@ function isUpgradable(obj) {
2833
2681
  multiplyBy,
2834
2682
  noop,
2835
2683
  omit,
2684
+ omitFromJsonObject,
2836
2685
  pad,
2837
2686
  padLeft,
2838
2687
  padRight,
2839
2688
  pick,
2689
+ pluralize,
2840
2690
  promiseSequence,
2841
2691
  randomInterval,
2842
2692
  randomPercentage,
@@ -2849,12 +2699,12 @@ function isUpgradable(obj) {
2849
2699
  roundToNearest,
2850
2700
  roundToUpper,
2851
2701
  roundTowardsZero,
2852
- sortBy,
2853
2702
  sortedArray,
2854
2703
  splitWords,
2855
2704
  stringToNumber,
2856
2705
  sum,
2857
2706
  sumBy,
2707
+ tail,
2858
2708
  throttle,
2859
2709
  tryToParseJson,
2860
2710
  uniq,
@@ -2863,5 +2713,6 @@ function isUpgradable(obj) {
2863
2713
  upsert,
2864
2714
  withTryCatch,
2865
2715
  withTryCatchAsync,
2866
- wrap
2716
+ wrap,
2717
+ wrapWithString
2867
2718
  });