@zelgadis87/utils-core 4.3.5 → 4.4.1

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