@zelgadis87/utils-core 4.11.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/dist/tsconfig.tsbuildinfo +1 -1
- package/esbuild/index.cjs +58 -34
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +48 -24
- package/esbuild/index.mjs.map +1 -1
- package/package.json +12 -12
- package/dist/async/index.d.ts +0 -4
- package/dist/lazy/index.d.ts +0 -2
- package/dist/sorting/index.d.ts +0 -4
- package/dist/time/index.d.ts +0 -7
- package/dist/upgrade/index.d.ts +0 -2
- package/dist/utils/functions/pipedInvokeFromArray.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -14
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)
|
|
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)
|
|
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)
|
|
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) {
|
|
@@ -493,13 +496,17 @@ function not(predicate) {
|
|
|
493
496
|
return (t) => !predicate(t);
|
|
494
497
|
}
|
|
495
498
|
function and(...predicates) {
|
|
496
|
-
if (predicates.length === 0)
|
|
497
|
-
|
|
499
|
+
if (predicates.length === 0)
|
|
500
|
+
return constantTrue;
|
|
501
|
+
else if (predicates.length === 1)
|
|
502
|
+
return predicates[0];
|
|
498
503
|
return (t) => predicates.reduce((prev, cur) => prev ? cur(t) : false, true);
|
|
499
504
|
}
|
|
500
505
|
function or(...predicates) {
|
|
501
|
-
if (predicates.length === 0)
|
|
502
|
-
|
|
506
|
+
if (predicates.length === 0)
|
|
507
|
+
return constantTrue;
|
|
508
|
+
else if (predicates.length === 1)
|
|
509
|
+
return predicates[0];
|
|
503
510
|
return (t) => predicates.reduce((prev, cur) => prev ? true : cur(t), false);
|
|
504
511
|
}
|
|
505
512
|
function xor(a, b) {
|
|
@@ -543,11 +550,13 @@ function uniqByKey(arr, key) {
|
|
|
543
550
|
|
|
544
551
|
// src/utils/arrays.ts
|
|
545
552
|
function ensureArray(t) {
|
|
546
|
-
if (isNullOrUndefined(t))
|
|
553
|
+
if (isNullOrUndefined(t))
|
|
554
|
+
return [];
|
|
547
555
|
return t instanceof Array ? t : [t];
|
|
548
556
|
}
|
|
549
557
|
function ensureReadableArray(t) {
|
|
550
|
-
if (isNullOrUndefined(t))
|
|
558
|
+
if (isNullOrUndefined(t))
|
|
559
|
+
return [];
|
|
551
560
|
return t instanceof Array ? t : [t];
|
|
552
561
|
}
|
|
553
562
|
function isArray(t) {
|
|
@@ -566,7 +575,8 @@ function upsert(arr, item, isEqual) {
|
|
|
566
575
|
}
|
|
567
576
|
}
|
|
568
577
|
function range(start, end) {
|
|
569
|
-
if (end < start)
|
|
578
|
+
if (end < start)
|
|
579
|
+
throw new Error();
|
|
570
580
|
let length = end - start + 1;
|
|
571
581
|
return new Array(length).fill(1).map((_, i) => start + i);
|
|
572
582
|
}
|
|
@@ -625,7 +635,8 @@ function partition(arr, predicate) {
|
|
|
625
635
|
function mapFirstTruthy(arr, mapFn) {
|
|
626
636
|
for (let i = 0; i < arr.length; i++) {
|
|
627
637
|
const result = mapFn(arr[i]);
|
|
628
|
-
if (result)
|
|
638
|
+
if (result)
|
|
639
|
+
return result;
|
|
629
640
|
}
|
|
630
641
|
return null;
|
|
631
642
|
}
|
|
@@ -653,7 +664,8 @@ function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectorsProd
|
|
|
653
664
|
const syleDeclarationRulesForSelectors = produceableToValue(syleDeclarationRulesForSelectorsProduceable);
|
|
654
665
|
return Object.entries(syleDeclarationRulesForSelectors).map(([selector, styleDeclarationRules]) => {
|
|
655
666
|
const cssRules = cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRules, indent + 1);
|
|
656
|
-
if (!cssRules.length)
|
|
667
|
+
if (!cssRules.length)
|
|
668
|
+
return null;
|
|
657
669
|
return repeat(tabulation, indent) + selector + space + openBracket + newLine + cssRules.join(newLine) + newLine + closeBracket;
|
|
658
670
|
}).filter(Boolean).join(newLine + newLine);
|
|
659
671
|
}
|
|
@@ -706,7 +718,8 @@ function tryToParseJson(jsonContent) {
|
|
|
706
718
|
return withTryCatch(() => JSON.parse(jsonContent));
|
|
707
719
|
}
|
|
708
720
|
function jsonCloneDeep(a) {
|
|
709
|
-
if (null === a || "object" !== typeof a)
|
|
721
|
+
if (null === a || "object" !== typeof a)
|
|
722
|
+
return a;
|
|
710
723
|
if (a instanceof Date) {
|
|
711
724
|
return new Date(a.getTime());
|
|
712
725
|
} else if (a instanceof Array) {
|
|
@@ -814,10 +827,13 @@ function clampInt0_100(n) {
|
|
|
814
827
|
function tryToParseNumber(numberStr) {
|
|
815
828
|
return withTryCatch(() => {
|
|
816
829
|
const type = typeof ensureDefined(numberStr);
|
|
817
|
-
if (type !== "string")
|
|
818
|
-
|
|
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);
|
|
819
834
|
const num = Number(numberStr);
|
|
820
|
-
if (isNaN(num))
|
|
835
|
+
if (isNaN(num))
|
|
836
|
+
throw new Error("Invalid number given: " + numberStr);
|
|
821
837
|
return num;
|
|
822
838
|
});
|
|
823
839
|
}
|
|
@@ -899,7 +915,8 @@ var StringParts = class _StringParts {
|
|
|
899
915
|
return new _StringParts(...this.parts.map((part) => part.toLowerCase()));
|
|
900
916
|
}
|
|
901
917
|
capitalizeFirst() {
|
|
902
|
-
if (!this.length)
|
|
918
|
+
if (!this.length)
|
|
919
|
+
return this;
|
|
903
920
|
return new _StringParts(capitalizeWord(this.first), ...this.tail.map((part) => part.toLowerCase()));
|
|
904
921
|
}
|
|
905
922
|
capitalizeEach() {
|
|
@@ -928,7 +945,8 @@ var StringParts = class _StringParts {
|
|
|
928
945
|
return this.toLowerCase().join("_");
|
|
929
946
|
}
|
|
930
947
|
toCamelCase() {
|
|
931
|
-
if (!this.length)
|
|
948
|
+
if (!this.length)
|
|
949
|
+
return "";
|
|
932
950
|
return [this.first.toLowerCase(), ...this.tail.map(capitalizeWord)].join("");
|
|
933
951
|
}
|
|
934
952
|
toKebabCase() {
|
|
@@ -1002,7 +1020,8 @@ function stringToNumber(s) {
|
|
|
1002
1020
|
}
|
|
1003
1021
|
function pad(str, n, char, where = "left") {
|
|
1004
1022
|
const length = ensureDefined(str).length;
|
|
1005
|
-
if (length >= ensureDefined(n))
|
|
1023
|
+
if (length >= ensureDefined(n))
|
|
1024
|
+
return str;
|
|
1006
1025
|
if (ensureDefined(char).length !== 1)
|
|
1007
1026
|
throw new Error("Illegal pad character");
|
|
1008
1027
|
const padding = repeat(char, n - length);
|
|
@@ -1345,7 +1364,8 @@ var TimeDuration = class _TimeDuration extends TimeBase {
|
|
|
1345
1364
|
get formatted() {
|
|
1346
1365
|
const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
|
|
1347
1366
|
const units = this.toUnits();
|
|
1348
|
-
if (units.days >= 1)
|
|
1367
|
+
if (units.days >= 1)
|
|
1368
|
+
return format2(units.days, "d", units.hours, "h");
|
|
1349
1369
|
else if (units.hours >= 1)
|
|
1350
1370
|
return format2(units.hours, "h", units.minutes, "m");
|
|
1351
1371
|
else if (units.minutes >= 1)
|
|
@@ -1613,7 +1633,8 @@ var getFromDate = {
|
|
|
1613
1633
|
};
|
|
1614
1634
|
var toReferenceDate = (x) => {
|
|
1615
1635
|
ensureDefined(x);
|
|
1616
|
-
if (isTimeInstant(x))
|
|
1636
|
+
if (isTimeInstant(x))
|
|
1637
|
+
return x.toDate();
|
|
1617
1638
|
return x;
|
|
1618
1639
|
};
|
|
1619
1640
|
function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInstant.now()) {
|
|
@@ -2195,8 +2216,10 @@ function compareBooleans(options) {
|
|
|
2195
2216
|
const fn = (a, b) => {
|
|
2196
2217
|
if (a === b)
|
|
2197
2218
|
return 0;
|
|
2198
|
-
if (isNullOrUndefined(a))
|
|
2199
|
-
|
|
2219
|
+
if (isNullOrUndefined(a))
|
|
2220
|
+
return opts.nullsFirst ? -1 : 1;
|
|
2221
|
+
if (isNullOrUndefined(b))
|
|
2222
|
+
return opts.nullsFirst ? 1 : -1;
|
|
2200
2223
|
return a === true && opts.truesFirst || a === false && !opts.truesFirst ? -1 : 1;
|
|
2201
2224
|
};
|
|
2202
2225
|
return (a, b) => applyDirection(fn(a, b), opts.direction);
|
|
@@ -2377,7 +2400,8 @@ var prioritizeSet = (fns, transform, set, reversed = false) => {
|
|
|
2377
2400
|
var prioritizeArray = (fns, transform, arr, reversed = false) => {
|
|
2378
2401
|
return compareNumbers(fns, (t) => {
|
|
2379
2402
|
const r = transform(t);
|
|
2380
|
-
if (!isDefined(r))
|
|
2403
|
+
if (!isDefined(r))
|
|
2404
|
+
return Number.MAX_VALUE;
|
|
2381
2405
|
const indexOf = arr.indexOf(r);
|
|
2382
2406
|
return indexOf === -1 ? Number.MAX_VALUE : indexOf;
|
|
2383
2407
|
}, { direction: reversed ? "DESC" : "ASC", nullsFirst: false });
|