@oscarpalmer/atoms 0.217.0 → 0.218.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.
- package/dist/array/insert.mjs +1 -1
- package/dist/array/slice.mjs +27 -14
- package/dist/array/sort.mjs +2 -1
- package/dist/color/misc/get.mjs +3 -1
- package/dist/color/space/hex.mjs +1 -1
- package/dist/function/retry.d.mts +1 -1
- package/dist/function/retry.mjs +5 -2
- package/dist/index.d.mts +163 -154
- package/dist/index.mjs +227 -145
- package/dist/internal/array/find.mjs +57 -34
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/match.mjs +21 -17
- package/dist/internal/array/sets.mjs +7 -1
- package/dist/internal/math/aggregate.mjs +4 -1
- package/dist/internal/number.d.mts +1 -1
- package/dist/internal/number.mjs +4 -2
- package/dist/internal/plan/plan.generate.mjs +3 -3
- package/dist/internal/random.d.mts +6 -0
- package/dist/internal/random.mjs +13 -2
- package/dist/internal/result/attempt.mjs +4 -4
- package/dist/internal/string/misc.mjs +2 -1
- package/dist/internal/subscription.mjs +1 -1
- package/dist/internal/value/equal.mjs +2 -1
- package/dist/internal/value/partial.mjs +3 -1
- package/dist/models/plan.model.d.mts +2 -0
- package/dist/models/plan.model.mjs +3 -1
- package/dist/models/string/string.fuzzy.model.d.mts +1 -1
- package/dist/models/string/string.misc.model.mjs +1 -1
- package/dist/models/value/value.merge.model.d.mts +1 -1
- package/dist/plan/index.d.mts +1 -4
- package/dist/plan/index.mjs +2 -3
- package/dist/plan/use.mjs +4 -4
- package/dist/promise/index.d.mts +6 -4
- package/dist/promise/index.mjs +4 -4
- package/dist/promise/misc.mjs +5 -2
- package/dist/promise/timed.mjs +2 -2
- package/dist/queue.mjs +4 -5
- package/dist/random.d.mts +2 -2
- package/dist/random.mjs +3 -3
- package/dist/result/match.mjs +2 -2
- package/dist/result/misc.mjs +3 -10
- package/dist/result/work/pipe.d.mts +24 -22
- package/dist/result/work/pipe.mjs +7 -3
- package/dist/string/fuzzy.mjs +1 -1
- package/dist/string/index.mjs +1 -1
- package/dist/value/clone.mjs +1 -1
- package/dist/value/merge.mjs +17 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -29,15 +29,47 @@ function createFindParameters(original) {
|
|
|
29
29
|
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
function findComplexValues(parameters) {
|
|
33
|
+
const { array, keyCallback, length, mapAfter, mapBefore, result, type, value } = parameters;
|
|
34
|
+
const keys = /* @__PURE__ */ new Set();
|
|
35
|
+
for (let index = 0; index < length; index += 1) {
|
|
36
|
+
const item = array[index];
|
|
37
|
+
let keyed;
|
|
38
|
+
let transformed;
|
|
39
|
+
if (mapBefore == null) {
|
|
40
|
+
keyed = keyCallback?.(item, index, array) ?? item;
|
|
41
|
+
transformed = item;
|
|
42
|
+
} else {
|
|
43
|
+
transformed = mapBefore(item, index, array);
|
|
44
|
+
keyed = keyCallback?.(transformed, index, array) ?? transformed;
|
|
45
|
+
}
|
|
46
|
+
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
47
|
+
keys.add(keyed);
|
|
48
|
+
result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
49
|
+
} else result.notMatched.push(item);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function findSimpleValue(array, value, findIndex, reversed) {
|
|
54
|
+
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
55
|
+
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
56
|
+
}
|
|
57
|
+
function findSimpleValues(array, length, value, boolCallback, mapBefore, mapAfter, result) {
|
|
58
|
+
const callback = boolCallback ?? ((item) => Object.is(item, value));
|
|
59
|
+
for (let index = 0; index < length; index += 1) {
|
|
60
|
+
const item = array[index];
|
|
61
|
+
const transformed = mapBefore?.(item, index, array) ?? item;
|
|
62
|
+
if (callback(transformed, index, array)) result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
63
|
+
else result.notMatched.push(item);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
32
67
|
function findValue(type, array, parameters, reversed) {
|
|
33
68
|
const findIndex = type === ARRAY_FIND_VALUE_INDEX;
|
|
34
69
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
35
70
|
const { bool, key, value } = createFindParameters(parameters);
|
|
36
71
|
const callbacks = getArrayCallbacks(bool, key);
|
|
37
|
-
if (callbacks?.bool == null && callbacks?.keyed == null)
|
|
38
|
-
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
39
|
-
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
40
|
-
}
|
|
72
|
+
if (callbacks?.bool == null && callbacks?.keyed == null) return findSimpleValue(array, value, findIndex, reversed);
|
|
41
73
|
if (callbacks.bool != null) {
|
|
42
74
|
const index = reversed ? array.findLastIndex(callbacks.bool) : array.findIndex(callbacks.bool);
|
|
43
75
|
return findIndex ? index : array[index];
|
|
@@ -58,7 +90,8 @@ function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultV
|
|
|
58
90
|
return useDefaultValue ? defaultValue : void 0;
|
|
59
91
|
}
|
|
60
92
|
const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
|
|
61
|
-
|
|
93
|
+
if (index === -1) return useDefaultValue ? defaultValue : void 0;
|
|
94
|
+
return array[index];
|
|
62
95
|
}
|
|
63
96
|
function findValues(type, array, parameters, mapper) {
|
|
64
97
|
const result = {
|
|
@@ -75,36 +108,26 @@ function findValues(type, array, parameters, mapper) {
|
|
|
75
108
|
}
|
|
76
109
|
const mapCallback = getArrayCallback(mapper?.callback);
|
|
77
110
|
const mapReverse = mapper?.reverse ?? false;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
transformed = mapBefore(item, index, array);
|
|
100
|
-
keyed = callbacks?.keyed?.(transformed, index, array) ?? transformed;
|
|
101
|
-
}
|
|
102
|
-
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
103
|
-
keys.add(keyed);
|
|
104
|
-
result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
105
|
-
} else result.notMatched.push(item);
|
|
106
|
-
}
|
|
107
|
-
return result;
|
|
111
|
+
let mapAfter;
|
|
112
|
+
let mapBefore;
|
|
113
|
+
if (mapCallback == null) {
|
|
114
|
+
mapAfter = void 0;
|
|
115
|
+
mapBefore = void 0;
|
|
116
|
+
} else {
|
|
117
|
+
mapAfter = mapReverse ? void 0 : mapCallback;
|
|
118
|
+
mapBefore = mapReverse ? mapCallback : void 0;
|
|
119
|
+
}
|
|
120
|
+
if (callbacks?.bool != null || type === "all" && key == null) return findSimpleValues(array, length, value, callbacks?.bool, mapBefore, mapAfter, result);
|
|
121
|
+
return findComplexValues({
|
|
122
|
+
array,
|
|
123
|
+
length,
|
|
124
|
+
mapAfter,
|
|
125
|
+
mapBefore,
|
|
126
|
+
result,
|
|
127
|
+
type,
|
|
128
|
+
value,
|
|
129
|
+
keyCallback: callbacks?.keyed
|
|
130
|
+
});
|
|
108
131
|
}
|
|
109
132
|
//#endregion
|
|
110
133
|
//#region src/array/filter.ts
|
|
@@ -431,6 +454,21 @@ const arrayMatchStarts = /* @__PURE__ */ new Set([ARRAY_MATCH_COMPARISON_START,
|
|
|
431
454
|
function endsWithArray(haystack, needle, key) {
|
|
432
455
|
return arrayMatchEndings.has(getPosition(haystack, needle, key)[1]);
|
|
433
456
|
}
|
|
457
|
+
function evaluatePosition(haystack, haystackLength, needle, needleLength, key) {
|
|
458
|
+
const callback = getArrayCallback(key);
|
|
459
|
+
const limit = haystackLength - needleLength + 1;
|
|
460
|
+
let needleValues = callback == null ? needle : needle.slice();
|
|
461
|
+
if (callback != null) for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) needleValues[needleIndex] = callback(needle[needleIndex], needleIndex, needle);
|
|
462
|
+
for (let haystackIndex = 0; haystackIndex < limit; haystackIndex += 1) {
|
|
463
|
+
if (!inHaystack(haystack, haystackIndex, needleValues, 0, callback)) continue;
|
|
464
|
+
if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
465
|
+
for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
|
|
466
|
+
if (!inHaystack(haystack, haystackIndex, needleValues, needleIndex, callback)) break;
|
|
467
|
+
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return arrayMatchOutside;
|
|
471
|
+
}
|
|
434
472
|
function getArrayComparison(haystack, needle, key) {
|
|
435
473
|
return getPosition(haystack, needle, key)[1];
|
|
436
474
|
}
|
|
@@ -444,23 +482,12 @@ function getPosition(haystack, needle, key) {
|
|
|
444
482
|
const needleLength = needle.length;
|
|
445
483
|
if (haystackLength === 0 || needleLength === 0) return arrayMatchOutside;
|
|
446
484
|
if (needleLength > haystackLength) return arrayMatchOutside;
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
let haystackValue = callback?.(haystackItem, haystackIndex, haystack) ?? haystackItem;
|
|
454
|
-
if (!Object.is(haystackValue, needleValues[0])) continue;
|
|
455
|
-
if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
456
|
-
for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
|
|
457
|
-
haystackItem = haystack[haystackIndex + needleIndex];
|
|
458
|
-
haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
|
|
459
|
-
if (!Object.is(haystackValue, needleValues[needleIndex])) break;
|
|
460
|
-
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return arrayMatchOutside;
|
|
485
|
+
return evaluatePosition(haystack, haystackLength, needle, needleLength, key);
|
|
486
|
+
}
|
|
487
|
+
function inHaystack(haystack, haystackIndex, needleValues, needleIndex, callback) {
|
|
488
|
+
const haystackItem = haystack[haystackIndex + needleIndex];
|
|
489
|
+
const haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
|
|
490
|
+
return Object.is(haystackValue, needleValues[needleIndex]);
|
|
464
491
|
}
|
|
465
492
|
function includesArray(haystack, needle, key) {
|
|
466
493
|
return !arrayMatchOutsides.has(getPosition(haystack, needle, key)[1]);
|
|
@@ -501,12 +528,22 @@ function roundNumber(callback, value, decimals) {
|
|
|
501
528
|
}
|
|
502
529
|
//#endregion
|
|
503
530
|
//#region src/internal/random.ts
|
|
531
|
+
/**
|
|
532
|
+
* Get a random number between 0 _(inclusive)_ and 1 _(exclusive)_
|
|
533
|
+
*
|
|
534
|
+
* @returns Random number
|
|
535
|
+
*/
|
|
536
|
+
function getRandom() {
|
|
537
|
+
/* istanbul ignore if */
|
|
538
|
+
if (globalThis.crypto == null) return Math.random();
|
|
539
|
+
return globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] / RANDOM_DIVISOR;
|
|
540
|
+
}
|
|
504
541
|
function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
|
|
505
542
|
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
506
543
|
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
507
544
|
if (minFloat === maxFloat) return minFloat;
|
|
508
545
|
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
509
|
-
return
|
|
546
|
+
return getRandom() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
510
547
|
}
|
|
511
548
|
/**
|
|
512
549
|
* Get a random floating-point number
|
|
@@ -528,6 +565,7 @@ function getRandomFloatingNumber(minimum, maximum) {
|
|
|
528
565
|
function getRandomInteger(minimum, maximum) {
|
|
529
566
|
return floor(getRandomFloatingNumberValue(true, minimum, maximum));
|
|
530
567
|
}
|
|
568
|
+
const RANDOM_DIVISOR = 2 ** 32;
|
|
531
569
|
//#endregion
|
|
532
570
|
//#region src/internal/array/shuffle.ts
|
|
533
571
|
/**
|
|
@@ -554,8 +592,14 @@ function compareSets(type, first, second, key) {
|
|
|
554
592
|
const isDifference = type === ARRAY_SETS_COMPARE_DIFFERENCE;
|
|
555
593
|
const isIntersection = type === ARRAY_SETS_COMPARE_INTERSECTION;
|
|
556
594
|
const isUnion = type === ARRAY_SETS_COMPARE_UNION;
|
|
557
|
-
if (first.length === 0)
|
|
595
|
+
if (first.length === 0) {
|
|
596
|
+
if (isDifference) return first.slice();
|
|
597
|
+
return isIntersection ? [] : second.slice();
|
|
598
|
+
}
|
|
558
599
|
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : first.slice();
|
|
600
|
+
return getComparison(first, second, isIntersection, isUnion, key);
|
|
601
|
+
}
|
|
602
|
+
function getComparison(first, second, isIntersection, isUnion, key) {
|
|
559
603
|
const callback = getArrayCallback(key);
|
|
560
604
|
const values = isUnion ? first : second;
|
|
561
605
|
let { length } = values;
|
|
@@ -668,7 +712,10 @@ function getAggregateCallback(key) {
|
|
|
668
712
|
}
|
|
669
713
|
function getAggregated(type, array, key, first) {
|
|
670
714
|
const aggregation = aggregate(type, array, key, first);
|
|
671
|
-
if (aggregation.count === 0)
|
|
715
|
+
if (aggregation.count === 0) {
|
|
716
|
+
if (aggregation.array) return aggregation.first ? void 0 : [];
|
|
717
|
+
return NaN;
|
|
718
|
+
}
|
|
672
719
|
if (aggregation.array) {
|
|
673
720
|
const array = aggregation.items[aggregation.value];
|
|
674
721
|
return aggregation.first ? array[0] : array;
|
|
@@ -696,7 +743,7 @@ const aggregators = {
|
|
|
696
743
|
//#endregion
|
|
697
744
|
//#region src/internal/array/insert.ts
|
|
698
745
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
699
|
-
const actualDeleteCount = deleteCount
|
|
746
|
+
const actualDeleteCount = max([deleteCount, 0]);
|
|
700
747
|
const actualStart = min([max([0, start]), array.length]);
|
|
701
748
|
const chunked = chunk(items);
|
|
702
749
|
const lastIndex = chunked.length - 1;
|
|
@@ -719,7 +766,7 @@ function insertValues(type, array, items, start, deleteCount) {
|
|
|
719
766
|
//#endregion
|
|
720
767
|
//#region src/array/insert.ts
|
|
721
768
|
function insert(array, indexOrItems, items) {
|
|
722
|
-
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items
|
|
769
|
+
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items ?? indexOrItems, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
|
|
723
770
|
}
|
|
724
771
|
//#endregion
|
|
725
772
|
//#region src/array/intersection.ts
|
|
@@ -789,34 +836,47 @@ function extract(type, array, first, second) {
|
|
|
789
836
|
if (!Array.isArray(array)) return [];
|
|
790
837
|
const { length } = array;
|
|
791
838
|
if (length === 0) return [];
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
const callbacks = second == null ? getArrayCallbacks(first) : getArrayCallbacks(void 0, void 0, first);
|
|
839
|
+
const take = type === ARRAY_SLICE_TAKE;
|
|
840
|
+
return typeof first === "number" ? getSlice(array, length, first, take) : extractSlice(array, length, first, second, take);
|
|
841
|
+
}
|
|
842
|
+
function extractSlice(array, length, first, second, take) {
|
|
843
|
+
const callbacks = getCallbacks(first, second);
|
|
844
|
+
if (callbacks?.bool == null && callbacks?.value == null) return take ? array.slice() : [];
|
|
800
845
|
const isBoolean = callbacks?.bool != null;
|
|
801
|
-
if (callbacks?.bool == null && callbacks?.value == null) return isTake ? array.slice() : [];
|
|
802
846
|
const extracted = [];
|
|
803
847
|
let push = false;
|
|
804
848
|
for (let index = 0; index < length; index += 1) {
|
|
805
849
|
const item = array[index];
|
|
806
|
-
const matches =
|
|
807
|
-
|
|
808
|
-
|
|
850
|
+
const matches = isMatch(item, index, array, callbacks, second, isBoolean);
|
|
851
|
+
const reached = isBoolean ? !matches : matches;
|
|
852
|
+
if (take && reached) break;
|
|
853
|
+
if (push || take) {
|
|
809
854
|
extracted.push(item);
|
|
810
855
|
continue;
|
|
811
856
|
}
|
|
812
|
-
if (
|
|
813
|
-
else if (isBoolean ? !matches : matches) {
|
|
857
|
+
if (reached) {
|
|
814
858
|
push = true;
|
|
815
859
|
if (isBoolean) extracted.push(item);
|
|
816
860
|
}
|
|
817
861
|
}
|
|
818
862
|
return extracted;
|
|
819
863
|
}
|
|
864
|
+
function getCallbacks(first, second) {
|
|
865
|
+
let callbacks;
|
|
866
|
+
if (second == null) callbacks = getArrayCallbacks(first);
|
|
867
|
+
else callbacks = getArrayCallbacks(void 0, void 0, first);
|
|
868
|
+
return callbacks;
|
|
869
|
+
}
|
|
870
|
+
function getSlice(array, length, amount, take) {
|
|
871
|
+
if (Math.abs(amount) >= length) return take ? array.slice() : [];
|
|
872
|
+
if (amount === 0) return take ? [] : array.slice();
|
|
873
|
+
if (take) return amount >= 0 ? array.slice(0, amount) : array.slice(length + amount);
|
|
874
|
+
return amount >= 0 ? array.slice(amount) : array.slice(0, length + amount);
|
|
875
|
+
}
|
|
876
|
+
function isMatch(item, index, array, callbacks, second, isBoolean) {
|
|
877
|
+
if (isBoolean) return callbacks.bool(item, index, array);
|
|
878
|
+
return Object.is(callbacks.value(item, index, array), second);
|
|
879
|
+
}
|
|
820
880
|
function slice(array, first, second) {
|
|
821
881
|
if (!Array.isArray(array) || array.length === 0) return [];
|
|
822
882
|
const firstIsNumber = typeof first === "number";
|
|
@@ -1022,7 +1082,7 @@ const VALUE_MISC_NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed
|
|
|
1022
1082
|
//#endregion
|
|
1023
1083
|
//#region src/models/string/string.misc.model.ts
|
|
1024
1084
|
const STRING_EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
|
|
1025
|
-
const STRING_EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]
|
|
1085
|
+
const STRING_EXPRESSION_WORDS = /([^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+)/g;
|
|
1026
1086
|
const STRING_EXPRESSION_WHITESPACE_PREFIX = /^(\s+)/;
|
|
1027
1087
|
const STRING_MATCH_ENDS_WITH = "endsWith";
|
|
1028
1088
|
const STRING_MATCH_INCLUDES = "includes";
|
|
@@ -1079,18 +1139,11 @@ error.is = isError;
|
|
|
1079
1139
|
ok.is = isOk;
|
|
1080
1140
|
//#endregion
|
|
1081
1141
|
//#region src/result/misc.ts
|
|
1082
|
-
/**
|
|
1083
|
-
* Converts a _Result_ to a _Promise_
|
|
1084
|
-
*
|
|
1085
|
-
* Resolves if ok, rejects for error
|
|
1086
|
-
*
|
|
1087
|
-
* @param result _Result_ to convert
|
|
1088
|
-
* @returns Promised result
|
|
1089
|
-
*/
|
|
1090
1142
|
async function toPromise(result) {
|
|
1091
1143
|
const actual = typeof result === "function" ? result() : result;
|
|
1092
|
-
if (!isResult(actual))
|
|
1093
|
-
|
|
1144
|
+
if (!isResult(actual)) throw new TypeError(RESULT_MESSAGE_PROMISE);
|
|
1145
|
+
if (isOk(actual)) return actual.value;
|
|
1146
|
+
throw actual.error;
|
|
1094
1147
|
}
|
|
1095
1148
|
const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
|
|
1096
1149
|
//#endregion
|
|
@@ -1102,15 +1155,15 @@ async function asyncAttempt(value, err) {
|
|
|
1102
1155
|
else result = value;
|
|
1103
1156
|
if (result instanceof Promise) result = await result;
|
|
1104
1157
|
return ok(result);
|
|
1105
|
-
} catch (
|
|
1106
|
-
return getError(err ??
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
return getError(err ?? error, err == null ? void 0 : error);
|
|
1107
1160
|
}
|
|
1108
1161
|
}
|
|
1109
1162
|
function attempt(callback, err) {
|
|
1110
1163
|
try {
|
|
1111
1164
|
return ok(callback());
|
|
1112
|
-
} catch (
|
|
1113
|
-
return getError(err ??
|
|
1165
|
+
} catch (error) {
|
|
1166
|
+
return getError(err ?? error, err == null ? void 0 : error);
|
|
1114
1167
|
}
|
|
1115
1168
|
}
|
|
1116
1169
|
attempt.async = asyncAttempt;
|
|
@@ -1189,7 +1242,8 @@ function tryEncode(value) {
|
|
|
1189
1242
|
* @returns Array of words found in the string
|
|
1190
1243
|
*/
|
|
1191
1244
|
function words(value) {
|
|
1192
|
-
|
|
1245
|
+
if (typeof value === "string") return value.match(STRING_EXPRESSION_WORDS) ?? [];
|
|
1246
|
+
return [];
|
|
1193
1247
|
}
|
|
1194
1248
|
//#endregion
|
|
1195
1249
|
//#region src/internal/value/handlers.ts
|
|
@@ -1442,7 +1496,7 @@ function isSortedArray(array) {
|
|
|
1442
1496
|
let offset = 0;
|
|
1443
1497
|
if (length >= 100) {
|
|
1444
1498
|
offset = round(length / 10);
|
|
1445
|
-
offset = offset
|
|
1499
|
+
offset = min([offset, 100]);
|
|
1446
1500
|
for (let index = 0; index < offset; index += 1) {
|
|
1447
1501
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
1448
1502
|
const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
|
|
@@ -2088,8 +2142,11 @@ async function asyncRetry(callback, options) {
|
|
|
2088
2142
|
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
2089
2143
|
async function handle() {
|
|
2090
2144
|
const result = await asyncAttempt(async () => callback());
|
|
2091
|
-
if (result.ok)
|
|
2092
|
-
|
|
2145
|
+
if (result.ok) {
|
|
2146
|
+
resolver(result.value);
|
|
2147
|
+
return;
|
|
2148
|
+
}
|
|
2149
|
+
if (attempts >= times || !when(result.error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, result.error));
|
|
2093
2150
|
else {
|
|
2094
2151
|
attempts += 1;
|
|
2095
2152
|
limiter.run();
|
|
@@ -2160,7 +2217,7 @@ const EXPRESSION_WHITESPACE_ONLY = /^\s*$/;
|
|
|
2160
2217
|
*
|
|
2161
2218
|
* @param value Value to check
|
|
2162
2219
|
* @param minimum Minimum value
|
|
2163
|
-
* @param maximum Maximum value
|
|
2220
|
+
* @param maximum Maximum value _(inclusive)_
|
|
2164
2221
|
* @returns `true` if the value is between the minimum and maximum, otherwise `false`
|
|
2165
2222
|
*/
|
|
2166
2223
|
function between(value, minimum, maximum) {
|
|
@@ -2170,7 +2227,8 @@ function between(value, minimum, maximum) {
|
|
|
2170
2227
|
maximum
|
|
2171
2228
|
].every(isNumber)) return false;
|
|
2172
2229
|
if (Object.is(minimum, maximum)) return Object.is(value, minimum);
|
|
2173
|
-
|
|
2230
|
+
const maximumValue = max([maximum, minimum]);
|
|
2231
|
+
return value >= min([maximum, minimum]) && value <= maximumValue;
|
|
2174
2232
|
}
|
|
2175
2233
|
/**
|
|
2176
2234
|
* Clamp a number between a minimum and maximum value
|
|
@@ -2619,7 +2677,7 @@ function equalArray(first, second, options) {
|
|
|
2619
2677
|
let offset = 0;
|
|
2620
2678
|
if (length >= 100) {
|
|
2621
2679
|
offset = round(length / 10);
|
|
2622
|
-
offset = offset
|
|
2680
|
+
offset = min([offset, 100]);
|
|
2623
2681
|
for (let index = 0; index < offset; index += 1) if (!(equalValue(first[index], second[index], options) && equalValue(first[length - index - 1], second[length - index - 1], options))) return false;
|
|
2624
2682
|
}
|
|
2625
2683
|
const end = length - offset;
|
|
@@ -2776,6 +2834,8 @@ const PLAN_FAILURE_ASYNC = "asyncFailure";
|
|
|
2776
2834
|
const PLAN_FAILURE_SYNC = "failure";
|
|
2777
2835
|
const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
2778
2836
|
const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
2837
|
+
const PLAN_MESSAGE_USE_NESTED_FN = "Cannot use nested functions with 'use'";
|
|
2838
|
+
const PLAN_MESSAGE_USE_SYNC_ASYNC = "Cannot use asynchronous values with 'use'";
|
|
2779
2839
|
const PLAN_STEP_ASYNC = "asyncStep";
|
|
2780
2840
|
const PLAN_STEP_SYNC = "step";
|
|
2781
2841
|
const PLAN_SUCCESS_ASYNC = "asyncSuccess";
|
|
@@ -2802,7 +2862,7 @@ function createAborter(value, onAbort) {
|
|
|
2802
2862
|
//#region src/internal/plan/plan.generate.ts
|
|
2803
2863
|
async function asyncGenerate(input, unwrap, first, second) {
|
|
2804
2864
|
const aborter = createAborter(second ?? first, noop);
|
|
2805
|
-
if (aborter
|
|
2865
|
+
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
2806
2866
|
const parameters = Array.isArray(first) ? first : [];
|
|
2807
2867
|
let generator;
|
|
2808
2868
|
if (typeof input === "function") generator = input(...parameters);
|
|
@@ -2811,7 +2871,7 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
2811
2871
|
let lastValue;
|
|
2812
2872
|
try {
|
|
2813
2873
|
while (true) {
|
|
2814
|
-
if (aborter
|
|
2874
|
+
if (aborter?.signal.aborted) await generator.throw(aborter.signal.reason);
|
|
2815
2875
|
const next = await generator.next(lastValue);
|
|
2816
2876
|
const done = next.done === true;
|
|
2817
2877
|
const { value } = next;
|
|
@@ -2827,7 +2887,7 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
2827
2887
|
aborter?.cancel();
|
|
2828
2888
|
await generator.return(lastValue);
|
|
2829
2889
|
}
|
|
2830
|
-
if (aborter
|
|
2890
|
+
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
2831
2891
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
2832
2892
|
throw lastValue;
|
|
2833
2893
|
}
|
|
@@ -3004,21 +3064,6 @@ function attemptRun(input, ...parameters) {
|
|
|
3004
3064
|
}
|
|
3005
3065
|
attemptRun.async = asyncAttemptRun;
|
|
3006
3066
|
//#endregion
|
|
3007
|
-
//#region src/plan/run.ts
|
|
3008
|
-
function asyncRun(input, first, second) {
|
|
3009
|
-
if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
|
|
3010
|
-
if (isAsyncGeneratorFunction(input)) return asyncGenerate(input, false, first, second);
|
|
3011
|
-
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
3012
|
-
}
|
|
3013
|
-
function run(input, ...parameters) {
|
|
3014
|
-
if (isPlan(input)) return input.run(...parameters);
|
|
3015
|
-
if (isGeneratorFunction(input)) return generate(input, parameters, false);
|
|
3016
|
-
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
3017
|
-
}
|
|
3018
|
-
asyncRun.attempt = asyncAttemptRun;
|
|
3019
|
-
run.async = asyncRun;
|
|
3020
|
-
run.attempt = attemptRun;
|
|
3021
|
-
//#endregion
|
|
3022
3067
|
//#region src/plan/index.ts
|
|
3023
3068
|
function AsyncPlan(generator) {
|
|
3024
3069
|
this[PLAN_SYMBOL] = {
|
|
@@ -3099,6 +3144,21 @@ function succeed(value) {
|
|
|
3099
3144
|
fail.async = asyncFail;
|
|
3100
3145
|
succeed.async = asyncSucceed;
|
|
3101
3146
|
//#endregion
|
|
3147
|
+
//#region src/plan/run.ts
|
|
3148
|
+
function asyncRun(input, first, second) {
|
|
3149
|
+
if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
|
|
3150
|
+
if (isAsyncGeneratorFunction(input)) return asyncGenerate(input, false, first, second);
|
|
3151
|
+
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
3152
|
+
}
|
|
3153
|
+
function run(input, ...parameters) {
|
|
3154
|
+
if (isPlan(input)) return input.run(...parameters);
|
|
3155
|
+
if (isGeneratorFunction(input)) return generate(input, parameters, false);
|
|
3156
|
+
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
3157
|
+
}
|
|
3158
|
+
asyncRun.attempt = asyncAttemptRun;
|
|
3159
|
+
run.async = asyncRun;
|
|
3160
|
+
run.attempt = attemptRun;
|
|
3161
|
+
//#endregion
|
|
3102
3162
|
//#region src/plan/use.ts
|
|
3103
3163
|
function AsyncStep(generator) {
|
|
3104
3164
|
this[PLAN_SYMBOL] = {
|
|
@@ -3119,7 +3179,7 @@ function asyncUse(value) {
|
|
|
3119
3179
|
let actual = value;
|
|
3120
3180
|
if (typeof actual === "function") actual = actual();
|
|
3121
3181
|
actual = await actual;
|
|
3122
|
-
if (typeof actual === "function") throw new
|
|
3182
|
+
if (typeof actual === "function") throw new TypeError(PLAN_MESSAGE_USE_NESTED_FN);
|
|
3123
3183
|
if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
|
|
3124
3184
|
if (isAsyncGenerator(actual) || isGenerator(actual)) return yield* actual;
|
|
3125
3185
|
if (isError(actual)) {
|
|
@@ -3157,8 +3217,8 @@ function use(value) {
|
|
|
3157
3217
|
});
|
|
3158
3218
|
}
|
|
3159
3219
|
function validateUseInput(value, resolved) {
|
|
3160
|
-
if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error();
|
|
3161
|
-
if (resolved && typeof value === "function") throw new Error();
|
|
3220
|
+
if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error(PLAN_MESSAGE_USE_SYNC_ASYNC);
|
|
3221
|
+
if (resolved && typeof value === "function") throw new Error(PLAN_MESSAGE_USE_NESTED_FN);
|
|
3162
3222
|
}
|
|
3163
3223
|
use.async = asyncUse;
|
|
3164
3224
|
//#endregion
|
|
@@ -3285,13 +3345,16 @@ function handleResult(status, parameters) {
|
|
|
3285
3345
|
handlers.reject(value);
|
|
3286
3346
|
return;
|
|
3287
3347
|
}
|
|
3288
|
-
|
|
3348
|
+
let resultValue;
|
|
3349
|
+
if (complete) resultValue = status === "fulfilled" ? {
|
|
3289
3350
|
status,
|
|
3290
3351
|
value
|
|
3291
3352
|
} : {
|
|
3292
3353
|
status,
|
|
3293
3354
|
reason: value
|
|
3294
3355
|
};
|
|
3356
|
+
else resultValue = value;
|
|
3357
|
+
data.result[key] = resultValue;
|
|
3295
3358
|
if (index === data.last) {
|
|
3296
3359
|
aborter?.cancel();
|
|
3297
3360
|
handlers.resolve(data.result);
|
|
@@ -3303,7 +3366,7 @@ function settlePromise(settler, value, aborter) {
|
|
|
3303
3366
|
}
|
|
3304
3367
|
async function toResult(value) {
|
|
3305
3368
|
const actual = typeof value === "function" ? value() : value;
|
|
3306
|
-
if (!(actual instanceof Promise))
|
|
3369
|
+
if (!(actual instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT);
|
|
3307
3370
|
return actual.then((result) => ok(result)).catch((reason) => error(reason));
|
|
3308
3371
|
}
|
|
3309
3372
|
//#endregion
|
|
@@ -3345,18 +3408,18 @@ async function getTimedPromise(promise, time, signal) {
|
|
|
3345
3408
|
});
|
|
3346
3409
|
}
|
|
3347
3410
|
async function timed(promise, options) {
|
|
3348
|
-
if (!(promise instanceof Promise))
|
|
3411
|
+
if (!(promise instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED);
|
|
3349
3412
|
const { signal, time } = createPromiseOptions(options);
|
|
3350
|
-
if (signal?.aborted ?? false)
|
|
3413
|
+
if (signal?.aborted ?? false) throw signal?.reason;
|
|
3351
3414
|
return time > 0 ? getTimedPromise(promise, time, signal) : promise;
|
|
3352
3415
|
}
|
|
3353
3416
|
//#endregion
|
|
3354
3417
|
//#region src/promise/index.ts
|
|
3355
3418
|
async function attemptPromise(value, options) {
|
|
3356
3419
|
const isFunction = typeof value === "function";
|
|
3357
|
-
if (!isFunction && !(value instanceof Promise))
|
|
3420
|
+
if (!isFunction && !(value instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT);
|
|
3358
3421
|
const { signal, time } = createPromiseOptions(options);
|
|
3359
|
-
if (signal?.aborted ?? false)
|
|
3422
|
+
if (signal?.aborted ?? false) throw signal?.reason;
|
|
3360
3423
|
const aborter = createAborter(signal, () => {
|
|
3361
3424
|
rejector(signal?.reason);
|
|
3362
3425
|
});
|
|
@@ -3378,8 +3441,8 @@ async function attemptPromise(value, options) {
|
|
|
3378
3441
|
}
|
|
3379
3442
|
async function promises(items, options) {
|
|
3380
3443
|
const { signal, strategy } = createPromisesOptions(options);
|
|
3381
|
-
if (signal?.aborted ?? false)
|
|
3382
|
-
if (!isArrayOrPlainObject(items))
|
|
3444
|
+
if (signal?.aborted ?? false) throw signal?.reason;
|
|
3445
|
+
if (!isArrayOrPlainObject(items)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
|
|
3383
3446
|
const isArray = Array.isArray(items);
|
|
3384
3447
|
const actual = (isArray ? items.map((item, index) => [index, item]) : Object.entries(items)).map(([key, value]) => [key, typeof value === "function" ? value() : value]).filter(([, value]) => value instanceof Promise);
|
|
3385
3448
|
const aborter = createAborter(signal, () => {
|
|
@@ -3442,10 +3505,10 @@ function handleResult$1(result, first, second) {
|
|
|
3442
3505
|
error = second;
|
|
3443
3506
|
}
|
|
3444
3507
|
if (isOk(result)) {
|
|
3445
|
-
if (typeof ok !== "function") throw new
|
|
3508
|
+
if (typeof ok !== "function") throw new TypeError(MATCH_MESSAGE_OK);
|
|
3446
3509
|
return ok(result.value);
|
|
3447
3510
|
}
|
|
3448
|
-
if (typeof error !== "function") throw new
|
|
3511
|
+
if (typeof error !== "function") throw new TypeError(MATCH_MESSAGE_ERROR);
|
|
3449
3512
|
return error(result.error, result.original);
|
|
3450
3513
|
}
|
|
3451
3514
|
function matchResult(result, first, second) {
|
|
@@ -3483,9 +3546,11 @@ attemptFlow.async = attemptAsyncFlow;
|
|
|
3483
3546
|
//#endregion
|
|
3484
3547
|
//#region src/result/work/pipe.ts
|
|
3485
3548
|
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
3486
|
-
return asyncAttempt(() => {
|
|
3549
|
+
return asyncAttempt(async () => {
|
|
3487
3550
|
if (isError(initial)) throw initial.error;
|
|
3488
|
-
|
|
3551
|
+
let value;
|
|
3552
|
+
if (typeof initial === "function") value = initial();
|
|
3553
|
+
else value = isOk(initial) ? initial.value : initial;
|
|
3489
3554
|
if (first == null) return value;
|
|
3490
3555
|
return asyncPipe(value, ...[first, ...seconds]);
|
|
3491
3556
|
});
|
|
@@ -3493,7 +3558,9 @@ async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
|
3493
3558
|
function attemptPipe(initial, first, ...seconds) {
|
|
3494
3559
|
return attempt(() => {
|
|
3495
3560
|
if (isError(initial)) throw initial.error;
|
|
3496
|
-
|
|
3561
|
+
let value;
|
|
3562
|
+
if (typeof initial === "function") value = initial();
|
|
3563
|
+
else value = isOk(initial) ? initial.value : initial;
|
|
3497
3564
|
if (first == null) return value;
|
|
3498
3565
|
return pipe(value, ...[first, ...seconds]);
|
|
3499
3566
|
});
|
|
@@ -3568,7 +3635,7 @@ Object.defineProperties(Fuzzy.prototype, {
|
|
|
3568
3635
|
}
|
|
3569
3636
|
});
|
|
3570
3637
|
function createFuzzyItems(items) {
|
|
3571
|
-
return items.
|
|
3638
|
+
return items.toSorted((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
3572
3639
|
}
|
|
3573
3640
|
function createFuzzyOptions(input, state) {
|
|
3574
3641
|
const options = isPlainObject(input) ? input : {};
|
|
@@ -3751,7 +3818,7 @@ function dedent(value, ...values) {
|
|
|
3751
3818
|
}
|
|
3752
3819
|
if (lengths.length === 0) return actual.trim();
|
|
3753
3820
|
const minimum = min(lengths);
|
|
3754
|
-
const pattern = new RegExp(
|
|
3821
|
+
const pattern = new RegExp(String.raw`^\s{0,${minimum}}`);
|
|
3755
3822
|
let result = "";
|
|
3756
3823
|
for (let index = 0; index < length; index += 1) {
|
|
3757
3824
|
const line = lines[index];
|
|
@@ -4020,7 +4087,7 @@ function clone(value, options) {
|
|
|
4020
4087
|
function cloneAny(value, parameters, depth, options) {
|
|
4021
4088
|
switch (true) {
|
|
4022
4089
|
case value === null || CLONE_PRIMITIVES[typeof value]: return value;
|
|
4023
|
-
case value instanceof Date: return new Date(value
|
|
4090
|
+
case value instanceof Date: return new Date(value);
|
|
4024
4091
|
case typeof value === "function":
|
|
4025
4092
|
parameters.options ??= createCloneOptions(options);
|
|
4026
4093
|
return parameters.options.copyFunctions ? value : void 0;
|
|
@@ -4384,7 +4451,9 @@ freeze.is = isFrozen;
|
|
|
4384
4451
|
//#region src/internal/value/partial.ts
|
|
4385
4452
|
function partial(value, providedKeys, omit) {
|
|
4386
4453
|
if (!isPlainObject(value)) return {};
|
|
4387
|
-
|
|
4454
|
+
let keys;
|
|
4455
|
+
if (omit) keys = Object.keys(value);
|
|
4456
|
+
else keys = Array.isArray(providedKeys) ? providedKeys : [];
|
|
4388
4457
|
const { length } = keys;
|
|
4389
4458
|
if (length === 0) return omit ? value : {};
|
|
4390
4459
|
const partials = {};
|
|
@@ -4557,6 +4626,12 @@ function createMergingOptions(input) {
|
|
|
4557
4626
|
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
4558
4627
|
return actual;
|
|
4559
4628
|
}
|
|
4629
|
+
function getFullKey(prefix, key, options) {
|
|
4630
|
+
let full;
|
|
4631
|
+
if (options.replaceableObjects == null) full = void 0;
|
|
4632
|
+
else full = prefix == null ? key : `${prefix}.${key}`;
|
|
4633
|
+
return full;
|
|
4634
|
+
}
|
|
4560
4635
|
function getReplaceableObjects(value) {
|
|
4561
4636
|
const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
|
|
4562
4637
|
if (items.length === 0) return;
|
|
@@ -4584,6 +4659,9 @@ function initializeAssigner(options) {
|
|
|
4584
4659
|
function initializeMerger(options) {
|
|
4585
4660
|
return new Merger(createMergingOptions(options));
|
|
4586
4661
|
}
|
|
4662
|
+
function isMergeable(next, previous, options, full) {
|
|
4663
|
+
return isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false);
|
|
4664
|
+
}
|
|
4587
4665
|
/**
|
|
4588
4666
|
* Merge multiple arrays or objects into a single one
|
|
4589
4667
|
*
|
|
@@ -4610,9 +4688,9 @@ function mergeObjects(values, options, destination, prefix) {
|
|
|
4610
4688
|
const key = keys[innerIndex];
|
|
4611
4689
|
const next = item[key];
|
|
4612
4690
|
const previous = merged[key];
|
|
4613
|
-
if (next
|
|
4614
|
-
const
|
|
4615
|
-
if (
|
|
4691
|
+
if (skipMerge(next, options, isArray)) continue;
|
|
4692
|
+
const fullKey = getFullKey(prefix, key, options);
|
|
4693
|
+
if (isMergeable(next, previous, options, fullKey)) merged[key] = mergeObjects([previous, next], options, destination == null ? void 0 : merged[key], fullKey);
|
|
4616
4694
|
else merged[key] = next;
|
|
4617
4695
|
}
|
|
4618
4696
|
}
|
|
@@ -4624,7 +4702,11 @@ function mergeValues(values, options, prefix) {
|
|
|
4624
4702
|
if (actual.length === 0) return {};
|
|
4625
4703
|
if (options.assignValues && actual.length === 2 && !Array.isArray(actual[0]) && Object.keys(actual[0]).length === 0) return Object.assign(actual[0], actual[1]);
|
|
4626
4704
|
if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
|
|
4627
|
-
|
|
4705
|
+
if (options.assignValues) return actual[0];
|
|
4706
|
+
return Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
|
|
4707
|
+
}
|
|
4708
|
+
function skipMerge(next, options, isArray) {
|
|
4709
|
+
return next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays);
|
|
4628
4710
|
}
|
|
4629
4711
|
assign.initialize = initializeAssigner;
|
|
4630
4712
|
merge.initialize = initializeMerger;
|
|
@@ -4805,7 +4887,7 @@ function createSubscriptionsProperty(input) {
|
|
|
4805
4887
|
const values = isPlainObject(input) ? input : {};
|
|
4806
4888
|
return {
|
|
4807
4889
|
key: typeof values.key === "string" ? values.key : SUBSCRIPTION_PROPERTY,
|
|
4808
|
-
value: values.value
|
|
4890
|
+
value: values.value ?? "subscription"
|
|
4809
4891
|
};
|
|
4810
4892
|
}
|
|
4811
4893
|
function createSubscriptionsState(property, keys) {
|
|
@@ -5340,7 +5422,8 @@ function setColorAlpha(value) {
|
|
|
5340
5422
|
//#endregion
|
|
5341
5423
|
//#region src/color/misc/get.ts
|
|
5342
5424
|
function getClampedValue(value, minimum, maximum, rounding) {
|
|
5343
|
-
|
|
5425
|
+
if (typeof value !== "number" || Number.isNaN(value)) return minimum;
|
|
5426
|
+
return clamp(rounding ?? false ? round(value) : value, minimum, maximum);
|
|
5344
5427
|
}
|
|
5345
5428
|
function getForegroundColor(value, hex) {
|
|
5346
5429
|
const { blue, green, red } = getColorFromState(getColorState(value), COLOR_TYPE.rgb);
|
|
@@ -5848,7 +5931,7 @@ function getHexaColor$1() {
|
|
|
5848
5931
|
* @returns Normalized hex color
|
|
5849
5932
|
*/
|
|
5850
5933
|
function getNormalizedHex(value, alpha) {
|
|
5851
|
-
const includeAlpha = alpha
|
|
5934
|
+
const includeAlpha = alpha === true;
|
|
5852
5935
|
if (!isHexColor(value)) return `${COLOR_DEFAULTS.hexBlack}${includeAlpha ? COLOR_ALPHA.fullHexLong : ""}`;
|
|
5853
5936
|
const normalized = value.replace(COLOR_EXPRESSION.prefix, "");
|
|
5854
5937
|
if (normalized.length < COLOR_LENGTHS.hexLong) return join(`${normalized.slice(0, COLOR_LENGTHS.hexShort)}${includeAlpha ? normalized[COLOR_LENGTHS.hexShort] ?? COLOR_ALPHA.fullHexShort : ""}`.split("").map((character) => character.repeat(2)));
|
|
@@ -7128,14 +7211,13 @@ async function run$1(state) {
|
|
|
7128
7211
|
state.runners += 1;
|
|
7129
7212
|
let item = state.items.shift();
|
|
7130
7213
|
while (item != null) {
|
|
7214
|
+
const next = item;
|
|
7131
7215
|
let error = false;
|
|
7132
7216
|
let result;
|
|
7133
7217
|
const attempted = await asyncAttempt(async () => {
|
|
7134
|
-
if (
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
}
|
|
7138
|
-
throw new Error();
|
|
7218
|
+
if (next.aborter?.signal?.aborted) throw next.aborter.signal.reason;
|
|
7219
|
+
const parameters = next.key == null ? next.parameters : [next.key, ...next.parameters];
|
|
7220
|
+
return await state.callback(...parameters);
|
|
7139
7221
|
});
|
|
7140
7222
|
if (attempted.ok) result = attempted.value;
|
|
7141
7223
|
else {
|
|
@@ -7166,7 +7248,7 @@ const RANDOM_HEX_CHARACTERS = "0123456789ABCDEF";
|
|
|
7166
7248
|
* @returns Random boolean
|
|
7167
7249
|
*/
|
|
7168
7250
|
function getRandomBoolean() {
|
|
7169
|
-
return
|
|
7251
|
+
return getRandom() > RANDOM_BOOLEAN_MODIFIER;
|
|
7170
7252
|
}
|
|
7171
7253
|
/**
|
|
7172
7254
|
* Get a random string of characters with a specified length
|
|
@@ -7271,4 +7353,4 @@ var SizedSet = class extends Set {
|
|
|
7271
7353
|
}
|
|
7272
7354
|
};
|
|
7273
7355
|
//#endregion
|
|
7274
|
-
export { CancelablePromise, Logger, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncAttemptRun, asyncDebounce, asyncFail, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncSucceed, asyncThrottle, asyncUse, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, attemptRun, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, fail, filter, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncFailure, isAsyncGenerator, isAsyncGeneratorFunction, isAsyncOnce, isAsyncPlan, isAsyncStep, isAsyncSuccess, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFailure, isFrozen, isFulfilled, isFuzzy, isGenerator, isGeneratorFunction, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPlan, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isStep, isSubscription, isSubscriptions, isSuccess, isTemplateStringsArray, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, mapAndFilter, mapAndFilter as reverseSelect, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, plan, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, run, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, succeed, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, use, words };
|
|
7356
|
+
export { CancelablePromise, Logger, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, push as append, push, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncAttemptRun, asyncDebounce, asyncFail, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncRun, asyncSucceed, asyncThrottle, asyncUse, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, attemptRun, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, fail, filter, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandom, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncFailure, isAsyncGenerator, isAsyncGeneratorFunction, isAsyncOnce, isAsyncPlan, isAsyncStep, isAsyncSuccess, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFailure, isFrozen, isFulfilled, isFuzzy, isGenerator, isGeneratorFunction, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPlan, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isStep, isSubscription, isSubscriptions, isSuccess, isTemplateStringsArray, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, mapAndFilter, mapAndFilter as reverseSelect, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, plan, promises, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, run, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, succeed, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, use, words };
|