@zelgadis87/utils-core 4.10.0 → 4.11.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.
package/esbuild/index.mjs CHANGED
@@ -267,7 +267,8 @@ var RateThrottler = class {
267
267
  return slot.promise().then(() => fn());
268
268
  } finally {
269
269
  this._availableSlots.push(TimeInstant.now().addDuration(this.cooldown));
270
- if (this._waitingRequests.length > 0) this._waitingRequests.shift().resolve();
270
+ if (this._waitingRequests.length > 0)
271
+ this._waitingRequests.shift().resolve();
271
272
  }
272
273
  };
273
274
  if (this._availableSlots.length > 0) {
@@ -433,14 +434,16 @@ function sumBy(arr, getter) {
433
434
  return sum(arr.map(getter));
434
435
  }
435
436
  function min(arr) {
436
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
437
+ if (arr.length === 0)
438
+ throw new Error("Cannot calculate value on empty array");
437
439
  return arr.reduce((min2, cur) => cur < min2 ? cur : min2);
438
440
  }
439
441
  function minBy(arr, getter) {
440
442
  return min(arr.map(getter));
441
443
  }
442
444
  function max(arr) {
443
- if (arr.length === 0) throw new Error("Cannot calculate value on empty array");
445
+ if (arr.length === 0)
446
+ throw new Error("Cannot calculate value on empty array");
444
447
  return arr.reduce((max2, cur) => cur > max2 ? cur : max2);
445
448
  }
446
449
  function maxBy(arr, getter) {
@@ -457,6 +460,7 @@ function identity(t) {
457
460
  var constantNull = constant(null);
458
461
  var constantTrue = constant(true);
459
462
  var constantFalse = constant(false);
463
+ var constantUndefined = constant(void 0);
460
464
  var alwaysTrue = constantTrue;
461
465
  var alwaysFalse = constantFalse;
462
466
  var constantZero = constant(0);
@@ -492,18 +496,36 @@ function not(predicate) {
492
496
  return (t) => !predicate(t);
493
497
  }
494
498
  function and(...predicates) {
495
- if (predicates.length === 0) return constantTrue;
496
- else if (predicates.length === 1) return predicates[0];
499
+ if (predicates.length === 0)
500
+ return constantTrue;
501
+ else if (predicates.length === 1)
502
+ return predicates[0];
497
503
  return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
498
504
  }
499
505
  function or(...predicates) {
500
- if (predicates.length === 0) return constantTrue;
501
- else if (predicates.length === 1) return predicates[0];
506
+ if (predicates.length === 0)
507
+ return constantTrue;
508
+ else if (predicates.length === 1)
509
+ return predicates[0];
502
510
  return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
503
511
  }
504
512
  function xor(a, b) {
505
513
  return (t) => a(t) !== b(t);
506
514
  }
515
+ function pipedInvoke(...fns) {
516
+ return pipedInvokeFromArray(fns);
517
+ }
518
+ function pipedInvokeFromArray(fns) {
519
+ if (fns.length === 0) {
520
+ return identity;
521
+ }
522
+ if (fns.length === 1) {
523
+ return fns[0];
524
+ }
525
+ return function piped(input) {
526
+ return fns.reduce((prev, fn) => fn(prev), input);
527
+ };
528
+ }
507
529
 
508
530
  // src/utils/arrays/uniqBy.ts
509
531
  function uniq(arr) {
@@ -528,11 +550,13 @@ function uniqByKey(arr, key) {
528
550
 
529
551
  // src/utils/arrays.ts
530
552
  function ensureArray(t) {
531
- if (isNullOrUndefined(t)) return [];
553
+ if (isNullOrUndefined(t))
554
+ return [];
532
555
  return t instanceof Array ? t : [t];
533
556
  }
534
557
  function ensureReadableArray(t) {
535
- if (isNullOrUndefined(t)) return [];
558
+ if (isNullOrUndefined(t))
559
+ return [];
536
560
  return t instanceof Array ? t : [t];
537
561
  }
538
562
  function isArray(t) {
@@ -551,7 +575,8 @@ function upsert(arr, item, isEqual) {
551
575
  }
552
576
  }
553
577
  function range(start, end) {
554
- if (end < start) throw new Error();
578
+ if (end < start)
579
+ throw new Error();
555
580
  let length = end - start + 1;
556
581
  return new Array(length).fill(1).map((_, i) => start + i);
557
582
  }
@@ -610,7 +635,8 @@ function partition(arr, predicate) {
610
635
  function mapFirstTruthy(arr, mapFn) {
611
636
  for (let i = 0; i < arr.length; i++) {
612
637
  const result = mapFn(arr[i]);
613
- if (result) return result;
638
+ if (result)
639
+ return result;
614
640
  }
615
641
  return null;
616
642
  }
@@ -638,7 +664,8 @@ function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectorsProd
638
664
  const syleDeclarationRulesForSelectors = produceableToValue(syleDeclarationRulesForSelectorsProduceable);
639
665
  return Object.entries(syleDeclarationRulesForSelectors).map(([selector, styleDeclarationRules]) => {
640
666
  const cssRules = cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRules, indent + 1);
641
- if (!cssRules.length) return null;
667
+ if (!cssRules.length)
668
+ return null;
642
669
  return repeat(tabulation, indent) + selector + space + openBracket + newLine + cssRules.join(newLine) + newLine + closeBracket;
643
670
  }).filter(Boolean).join(newLine + newLine);
644
671
  }
@@ -691,7 +718,8 @@ function tryToParseJson(jsonContent) {
691
718
  return withTryCatch(() => JSON.parse(jsonContent));
692
719
  }
693
720
  function jsonCloneDeep(a) {
694
- if (null === a || "object" !== typeof a) return a;
721
+ if (null === a || "object" !== typeof a)
722
+ return a;
695
723
  if (a instanceof Date) {
696
724
  return new Date(a.getTime());
697
725
  } else if (a instanceof Array) {
@@ -793,13 +821,19 @@ function clamp(n, min2, max2) {
793
821
  return n;
794
822
  }
795
823
  }
824
+ function clampInt0_100(n) {
825
+ return clamp(Math.round(n), 0, 100);
826
+ }
796
827
  function tryToParseNumber(numberStr) {
797
828
  return withTryCatch(() => {
798
829
  const type = typeof ensureDefined(numberStr);
799
- if (type !== "string") throw new Error("Invalid number given: " + numberStr);
800
- if (numberStr.trim().length === 0) throw new Error("Invalid number given: " + numberStr);
830
+ if (type !== "string")
831
+ throw new Error("Invalid number given: " + numberStr);
832
+ if (numberStr.trim().length === 0)
833
+ throw new Error("Invalid number given: " + numberStr);
801
834
  const num = Number(numberStr);
802
- if (isNaN(num)) throw new Error("Invalid number given: " + numberStr);
835
+ if (isNaN(num))
836
+ throw new Error("Invalid number given: " + numberStr);
803
837
  return num;
804
838
  });
805
839
  }
@@ -833,6 +867,8 @@ async function awaitAtMost(p, t) {
833
867
  throw new TimeoutError();
834
868
  });
835
869
  }
870
+ var NEVER = new Promise((_resolve) => {
871
+ });
836
872
 
837
873
  // src/utils/random.ts
838
874
  var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
@@ -879,7 +915,8 @@ var StringParts = class _StringParts {
879
915
  return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
880
916
  }
881
917
  capitalizeFirst() {
882
- if (!this.length) return this;
918
+ if (!this.length)
919
+ return this;
883
920
  return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
884
921
  }
885
922
  capitalizeEach() {
@@ -908,7 +945,8 @@ var StringParts = class _StringParts {
908
945
  return this.toLowerCase().join("_");
909
946
  }
910
947
  toCamelCase() {
911
- if (!this.length) return "";
948
+ if (!this.length)
949
+ return "";
912
950
  return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
913
951
  }
914
952
  toKebabCase() {
@@ -982,7 +1020,8 @@ function stringToNumber(s) {
982
1020
  }
983
1021
  function pad(str, n, char, where = "left") {
984
1022
  const length = ensureDefined(str).length;
985
- if (length >= ensureDefined(n)) return str;
1023
+ if (length >= ensureDefined(n))
1024
+ return str;
986
1025
  if (ensureDefined(char).length !== 1)
987
1026
  throw new Error("Illegal pad character");
988
1027
  const padding = repeat(char, n - length);
@@ -1325,7 +1364,8 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1325
1364
  get formatted() {
1326
1365
  const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1327
1366
  const units = this.toUnits();
1328
- if (units.days >= 1) return format2(units.days, "d", units.hours, "h");
1367
+ if (units.days >= 1)
1368
+ return format2(units.days, "d", units.hours, "h");
1329
1369
  else if (units.hours >= 1)
1330
1370
  return format2(units.hours, "h", units.minutes, "m");
1331
1371
  else if (units.minutes >= 1)
@@ -1593,7 +1633,8 @@ var getFromDate = {
1593
1633
  };
1594
1634
  var toReferenceDate = (x) => {
1595
1635
  ensureDefined(x);
1596
- if (isTimeInstant(x)) return x.toDate();
1636
+ if (isTimeInstant(x))
1637
+ return x.toDate();
1597
1638
  return x;
1598
1639
  };
1599
1640
  function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
@@ -2175,8 +2216,10 @@ function compareBooleans(options) {
2175
2216
  const fn = (a, b) => {
2176
2217
  if (a === b)
2177
2218
  return 0;
2178
- if (isNullOrUndefined(a)) return opts.nullsFirst ? -1 : 1;
2179
- if (isNullOrUndefined(b)) return opts.nullsFirst ? 1 : -1;
2219
+ if (isNullOrUndefined(a))
2220
+ return opts.nullsFirst ? -1 : 1;
2221
+ if (isNullOrUndefined(b))
2222
+ return opts.nullsFirst ? 1 : -1;
2180
2223
  return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
2181
2224
  };
2182
2225
  return (a, b) => applyDirection(fn(a, b), opts.direction);
@@ -2357,7 +2400,8 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
2357
2400
  var prioritizeArray = (fns, transform, arr, reversed = false) => {
2358
2401
  return compareNumbers(fns, (t) => {
2359
2402
  const r = transform(t);
2360
- if (!isDefined(r)) return Number.MAX_VALUE;
2403
+ if (!isDefined(r))
2404
+ return Number.MAX_VALUE;
2361
2405
  const indexOf = arr.indexOf(r);
2362
2406
  return indexOf === -1 ? Number.MAX_VALUE : indexOf;
2363
2407
  }, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
@@ -2719,6 +2763,7 @@ export {
2719
2763
  Lazy,
2720
2764
  LazyAsync,
2721
2765
  Logger,
2766
+ NEVER,
2722
2767
  Optional,
2723
2768
  RandomTimeDuration,
2724
2769
  RateThrottler,
@@ -2741,11 +2786,13 @@ export {
2741
2786
  awaitAtMost,
2742
2787
  capitalizeWord,
2743
2788
  clamp,
2789
+ clampInt0_100,
2744
2790
  constant,
2745
2791
  constantFalse,
2746
2792
  constantNull,
2747
2793
  constantOne,
2748
2794
  constantTrue,
2795
+ constantUndefined,
2749
2796
  constantZero,
2750
2797
  createSorterFor,
2751
2798
  cssDeclarationRulesDictionaryToCss,
@@ -2831,6 +2878,8 @@ export {
2831
2878
  padRight,
2832
2879
  partition,
2833
2880
  pick,
2881
+ pipedInvoke,
2882
+ pipedInvokeFromArray,
2834
2883
  pluralize,
2835
2884
  promiseSequence,
2836
2885
  randomId,