@oscarpalmer/atoms 0.217.0 → 0.219.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/filter.d.mts +38 -4
- package/dist/array/find.d.mts +34 -0
- package/dist/array/first.d.mts +40 -4
- package/dist/array/insert.mjs +1 -1
- package/dist/array/last.d.mts +46 -10
- package/dist/array/partition.d.mts +24 -8
- package/dist/array/reverse.d.mts +6 -0
- package/dist/array/reverse.mjs +6 -0
- package/dist/array/select.d.mts +97 -116
- package/dist/array/select.mjs +19 -15
- package/dist/array/single.d.mts +22 -0
- package/dist/array/single.mjs +1 -1
- package/dist/array/slice.mjs +27 -14
- package/dist/array/sort.d.mts +54 -0
- package/dist/array/sort.mjs +2 -1
- package/dist/color/misc/get.mjs +3 -1
- package/dist/color/space/hex.d.mts +8 -0
- package/dist/color/space/hex.mjs +9 -1
- package/dist/function/retry.d.mts +1 -1
- package/dist/function/retry.mjs +5 -2
- package/dist/index.d.mts +879 -324
- package/dist/index.mjs +480 -173
- package/dist/internal/array/callbacks.mjs +1 -1
- package/dist/internal/array/find.d.mts +3 -3
- package/dist/internal/array/find.mjs +90 -48
- 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/array/shuffle.d.mts +5 -0
- package/dist/internal/array/shuffle.mjs +5 -0
- package/dist/internal/math/aggregate.d.mts +69 -21
- package/dist/internal/math/aggregate.mjs +4 -1
- package/dist/internal/math/misc.d.mts +14 -0
- package/dist/internal/math/misc.mjs +14 -0
- package/dist/internal/number.d.mts +19 -1
- package/dist/internal/number.mjs +22 -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/case.d.mts +63 -0
- package/dist/internal/string/case.mjs +63 -0
- package/dist/internal/string/misc.d.mts +20 -0
- package/dist/internal/string/misc.mjs +22 -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/logger.d.mts +12 -0
- package/dist/logger.mjs +12 -0
- package/dist/math.d.mts +90 -0
- package/dist/math.mjs +7 -0
- package/dist/models/array/array.find.model.d.mts +26 -0
- package/dist/models/array/array.misc.model.d.mts +2 -4
- package/dist/models/index.d.mts +1 -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 +4 -4
- 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.d.mts +6 -0
- package/dist/promise/misc.mjs +11 -2
- package/dist/promise/timed.d.mts +3 -0
- package/dist/promise/timed.mjs +5 -2
- package/dist/queue.d.mts +0 -1
- package/dist/queue.mjs +5 -6
- 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.d.mts +15 -1
- package/dist/string/index.mjs +16 -2
- package/dist/string/match.d.mts +24 -0
- package/dist/string/match.mjs +24 -0
- package/dist/string/template.d.mts +4 -0
- package/dist/value/clone.mjs +1 -1
- package/dist/value/merge.mjs +17 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ function getArrayCallback(value) {
|
|
|
8
8
|
switch (typeof value) {
|
|
9
9
|
case "function": return value;
|
|
10
10
|
case "number":
|
|
11
|
-
case "string": return
|
|
11
|
+
case "string": return (obj) => obj?.[value];
|
|
12
12
|
default: return;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -21,6 +21,15 @@ function getArrayCallbacks(bool, key, value) {
|
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/internal/array/find.ts
|
|
24
|
+
function addResult(result, mapped, flat) {
|
|
25
|
+
if (!flat) {
|
|
26
|
+
result.matched.push(mapped);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const array = Array.isArray(mapped) ? mapped : [mapped];
|
|
30
|
+
const { length } = array;
|
|
31
|
+
for (let index = 0; index < length; index += 1) result.matched.push(array[index]);
|
|
32
|
+
}
|
|
24
33
|
function createFindParameters(original) {
|
|
25
34
|
const { length } = original;
|
|
26
35
|
return {
|
|
@@ -29,15 +38,65 @@ function createFindParameters(original) {
|
|
|
29
38
|
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
30
39
|
};
|
|
31
40
|
}
|
|
41
|
+
function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultValue, reversed) {
|
|
42
|
+
if (parameters.length === 0) {
|
|
43
|
+
if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
|
|
44
|
+
return useDefaultValue ? defaultValue : void 0;
|
|
45
|
+
}
|
|
46
|
+
const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
|
|
47
|
+
if (index === -1) return useDefaultValue ? defaultValue : void 0;
|
|
48
|
+
return array[index];
|
|
49
|
+
}
|
|
50
|
+
function findComplexValues(parameters) {
|
|
51
|
+
const { array, arrayLength, callback, limit, result, type, value } = parameters;
|
|
52
|
+
const keys = /* @__PURE__ */ new Set();
|
|
53
|
+
for (let arrayIndex = 0; arrayIndex < arrayLength; arrayIndex += 1) {
|
|
54
|
+
const arrayItem = array[arrayIndex];
|
|
55
|
+
const keyed = callback == null ? arrayItem : callback(arrayItem, arrayIndex, array);
|
|
56
|
+
const mapped = arrayItem;
|
|
57
|
+
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
58
|
+
keys.add(keyed);
|
|
59
|
+
result.matched.push(mapped);
|
|
60
|
+
if (result.matched.length >= limit) return result;
|
|
61
|
+
} else result.notMatched.push(arrayItem);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
function findSimpleValue(array, value, findIndex, reversed) {
|
|
66
|
+
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
67
|
+
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
68
|
+
}
|
|
69
|
+
function findSimpleValues(parameters) {
|
|
70
|
+
const { array, arrayLength, callback, flat, limit, map, result, value } = parameters;
|
|
71
|
+
const { after, before } = map ?? {};
|
|
72
|
+
const handler = callback ?? ((item) => Object.is(item, value));
|
|
73
|
+
for (let arrayIndex = 0; arrayIndex < arrayLength; arrayIndex += 1) {
|
|
74
|
+
const arrayItem = array[arrayIndex];
|
|
75
|
+
let mapped = before == null ? arrayItem : before(arrayItem, arrayIndex, array);
|
|
76
|
+
if (!flat || after != null) {
|
|
77
|
+
if (handler(mapped, arrayIndex, array)) {
|
|
78
|
+
mapped = after == null ? mapped : after(arrayItem, arrayIndex, array);
|
|
79
|
+
addResult(result, mapped, flat);
|
|
80
|
+
if (result.matched.length >= limit) return result;
|
|
81
|
+
} else result.notMatched.push(arrayItem);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const flatItems = Array.isArray(mapped) ? mapped : [mapped];
|
|
85
|
+
const flatLength = flatItems.length;
|
|
86
|
+
for (let flatIndex = 0; flatIndex < flatLength; flatIndex += 1) {
|
|
87
|
+
const flatItem = flatItems[flatIndex];
|
|
88
|
+
if (handler(flatItem, arrayIndex, array)) result.matched.push(flatItem);
|
|
89
|
+
else result.notMatched.push(flatItem);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
32
94
|
function findValue(type, array, parameters, reversed) {
|
|
33
95
|
const findIndex = type === ARRAY_FIND_VALUE_INDEX;
|
|
34
96
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
35
97
|
const { bool, key, value } = createFindParameters(parameters);
|
|
36
98
|
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
|
-
}
|
|
99
|
+
if (callbacks?.bool == null && callbacks?.keyed == null) return findSimpleValue(array, value, findIndex, reversed);
|
|
41
100
|
if (callbacks.bool != null) {
|
|
42
101
|
const index = reversed ? array.findLastIndex(callbacks.bool) : array.findIndex(callbacks.bool);
|
|
43
102
|
return findIndex ? index : array[index];
|
|
@@ -52,59 +111,42 @@ function findValueInArray(array, callback, value, findIndex, reversed) {
|
|
|
52
111
|
}
|
|
53
112
|
return findIndex ? -1 : void 0;
|
|
54
113
|
}
|
|
55
|
-
function
|
|
56
|
-
if (parameters.length === 0) {
|
|
57
|
-
if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
|
|
58
|
-
return useDefaultValue ? defaultValue : void 0;
|
|
59
|
-
}
|
|
60
|
-
const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
|
|
61
|
-
return index > -1 ? array[index] : useDefaultValue ? defaultValue : void 0;
|
|
62
|
-
}
|
|
63
|
-
function findValues(type, array, parameters, mapper) {
|
|
114
|
+
function findValues(type, array, parameters, options) {
|
|
64
115
|
const result = {
|
|
65
116
|
matched: [],
|
|
66
117
|
notMatched: []
|
|
67
118
|
};
|
|
68
|
-
if (!Array.isArray(array)
|
|
69
|
-
const
|
|
119
|
+
if (!Array.isArray(array)) return result;
|
|
120
|
+
const arrayLength = array.length;
|
|
121
|
+
if (arrayLength === 0) return result;
|
|
70
122
|
const { bool, key, value } = createFindParameters(parameters);
|
|
71
123
|
const callbacks = getArrayCallbacks(bool, key);
|
|
72
|
-
if (type === "unique" && callbacks?.keyed == null &&
|
|
124
|
+
if (type === "unique" && callbacks?.keyed == null && arrayLength >= 100) {
|
|
73
125
|
result.matched = [...new Set(array)];
|
|
74
126
|
return result;
|
|
75
127
|
}
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
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;
|
|
128
|
+
const limit = options?.limit ?? Number.POSITIVE_INFINITY;
|
|
129
|
+
const flat = options?.map?.flat ?? false;
|
|
130
|
+
const mapCallback = getArrayCallback(options?.map?.callback);
|
|
131
|
+
const mapReverse = options?.map?.reverse ?? false;
|
|
132
|
+
let map;
|
|
133
|
+
if (mapCallback != null) map = {
|
|
134
|
+
before: mapReverse ? mapCallback : void 0,
|
|
135
|
+
after: mapReverse ? void 0 : mapCallback
|
|
136
|
+
};
|
|
137
|
+
const simple = callbacks?.bool != null || type === "all" && key == null;
|
|
138
|
+
const findParameters = {
|
|
139
|
+
array,
|
|
140
|
+
arrayLength,
|
|
141
|
+
flat,
|
|
142
|
+
limit,
|
|
143
|
+
map,
|
|
144
|
+
result,
|
|
145
|
+
type,
|
|
146
|
+
value,
|
|
147
|
+
callback: simple ? callbacks?.bool : callbacks?.keyed
|
|
148
|
+
};
|
|
149
|
+
return simple ? findSimpleValues(findParameters) : findComplexValues(findParameters);
|
|
108
150
|
}
|
|
109
151
|
//#endregion
|
|
110
152
|
//#region src/array/filter.ts
|
|
@@ -431,6 +473,21 @@ const arrayMatchStarts = /* @__PURE__ */ new Set([ARRAY_MATCH_COMPARISON_START,
|
|
|
431
473
|
function endsWithArray(haystack, needle, key) {
|
|
432
474
|
return arrayMatchEndings.has(getPosition(haystack, needle, key)[1]);
|
|
433
475
|
}
|
|
476
|
+
function evaluatePosition(haystack, haystackLength, needle, needleLength, key) {
|
|
477
|
+
const callback = getArrayCallback(key);
|
|
478
|
+
const limit = haystackLength - needleLength + 1;
|
|
479
|
+
let needleValues = callback == null ? needle : needle.slice();
|
|
480
|
+
if (callback != null) for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) needleValues[needleIndex] = callback(needle[needleIndex], needleIndex, needle);
|
|
481
|
+
for (let haystackIndex = 0; haystackIndex < limit; haystackIndex += 1) {
|
|
482
|
+
if (!inHaystack(haystack, haystackIndex, needleValues, 0, callback)) continue;
|
|
483
|
+
if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
484
|
+
for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
|
|
485
|
+
if (!inHaystack(haystack, haystackIndex, needleValues, needleIndex, callback)) break;
|
|
486
|
+
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return arrayMatchOutside;
|
|
490
|
+
}
|
|
434
491
|
function getArrayComparison(haystack, needle, key) {
|
|
435
492
|
return getPosition(haystack, needle, key)[1];
|
|
436
493
|
}
|
|
@@ -444,23 +501,12 @@ function getPosition(haystack, needle, key) {
|
|
|
444
501
|
const needleLength = needle.length;
|
|
445
502
|
if (haystackLength === 0 || needleLength === 0) return arrayMatchOutside;
|
|
446
503
|
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;
|
|
504
|
+
return evaluatePosition(haystack, haystackLength, needle, needleLength, key);
|
|
505
|
+
}
|
|
506
|
+
function inHaystack(haystack, haystackIndex, needleValues, needleIndex, callback) {
|
|
507
|
+
const haystackItem = haystack[haystackIndex + needleIndex];
|
|
508
|
+
const haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
|
|
509
|
+
return Object.is(haystackValue, needleValues[needleIndex]);
|
|
464
510
|
}
|
|
465
511
|
function includesArray(haystack, needle, key) {
|
|
466
512
|
return !arrayMatchOutsides.has(getPosition(haystack, needle, key)[1]);
|
|
@@ -479,6 +525,13 @@ function startsWithArray(haystack, needle, key) {
|
|
|
479
525
|
* @param value Number to round down
|
|
480
526
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
481
527
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* floor(10.567, 2); // => 10.56
|
|
532
|
+
* floor(10.567); // => 10
|
|
533
|
+
* floor('abc'); // => Number.NaN
|
|
534
|
+
* ```
|
|
482
535
|
*/
|
|
483
536
|
function floor(value, decimals) {
|
|
484
537
|
return roundNumber(Math.floor, value, decimals);
|
|
@@ -489,6 +542,13 @@ function floor(value, decimals) {
|
|
|
489
542
|
* @param value Number to round
|
|
490
543
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
491
544
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```typescript
|
|
548
|
+
* round(10.567, 2); // => 10.57
|
|
549
|
+
* round(10.567); // => 11
|
|
550
|
+
* round('abc'); // => Number.NaN
|
|
551
|
+
* ```
|
|
492
552
|
*/
|
|
493
553
|
function round(value, decimals) {
|
|
494
554
|
return roundNumber(Math.round, value, decimals);
|
|
@@ -501,12 +561,22 @@ function roundNumber(callback, value, decimals) {
|
|
|
501
561
|
}
|
|
502
562
|
//#endregion
|
|
503
563
|
//#region src/internal/random.ts
|
|
564
|
+
/**
|
|
565
|
+
* Get a random number between 0 _(inclusive)_ and 1 _(exclusive)_
|
|
566
|
+
*
|
|
567
|
+
* @returns Random number
|
|
568
|
+
*/
|
|
569
|
+
function getRandom() {
|
|
570
|
+
/* istanbul ignore if */
|
|
571
|
+
if (globalThis.crypto == null) return Math.random();
|
|
572
|
+
return globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] / RANDOM_DIVISOR;
|
|
573
|
+
}
|
|
504
574
|
function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
|
|
505
575
|
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
506
576
|
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
507
577
|
if (minFloat === maxFloat) return minFloat;
|
|
508
578
|
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
509
|
-
return
|
|
579
|
+
return getRandom() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
510
580
|
}
|
|
511
581
|
/**
|
|
512
582
|
* Get a random floating-point number
|
|
@@ -528,6 +598,7 @@ function getRandomFloatingNumber(minimum, maximum) {
|
|
|
528
598
|
function getRandomInteger(minimum, maximum) {
|
|
529
599
|
return floor(getRandomFloatingNumberValue(true, minimum, maximum));
|
|
530
600
|
}
|
|
601
|
+
const RANDOM_DIVISOR = 2 ** 32;
|
|
531
602
|
//#endregion
|
|
532
603
|
//#region src/internal/array/shuffle.ts
|
|
533
604
|
/**
|
|
@@ -535,6 +606,11 @@ function getRandomInteger(minimum, maximum) {
|
|
|
535
606
|
*
|
|
536
607
|
* @param array Original array
|
|
537
608
|
* @returns Shuffled array
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* ```typescript
|
|
612
|
+
* shuffle([1, 2, 3]); // => [3, 1, 2] (maybe? it's random, you know)
|
|
613
|
+
* ```
|
|
538
614
|
*/
|
|
539
615
|
function shuffle(array) {
|
|
540
616
|
if (!Array.isArray(array)) return [];
|
|
@@ -554,8 +630,14 @@ function compareSets(type, first, second, key) {
|
|
|
554
630
|
const isDifference = type === ARRAY_SETS_COMPARE_DIFFERENCE;
|
|
555
631
|
const isIntersection = type === ARRAY_SETS_COMPARE_INTERSECTION;
|
|
556
632
|
const isUnion = type === ARRAY_SETS_COMPARE_UNION;
|
|
557
|
-
if (first.length === 0)
|
|
633
|
+
if (first.length === 0) {
|
|
634
|
+
if (isDifference) return first.slice();
|
|
635
|
+
return isIntersection ? [] : second.slice();
|
|
636
|
+
}
|
|
558
637
|
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : first.slice();
|
|
638
|
+
return getComparison(first, second, isIntersection, isUnion, key);
|
|
639
|
+
}
|
|
640
|
+
function getComparison(first, second, isIntersection, isUnion, key) {
|
|
559
641
|
const callback = getArrayCallback(key);
|
|
560
642
|
const values = isUnion ? first : second;
|
|
561
643
|
let { length } = values;
|
|
@@ -668,7 +750,10 @@ function getAggregateCallback(key) {
|
|
|
668
750
|
}
|
|
669
751
|
function getAggregated(type, array, key, first) {
|
|
670
752
|
const aggregation = aggregate(type, array, key, first);
|
|
671
|
-
if (aggregation.count === 0)
|
|
753
|
+
if (aggregation.count === 0) {
|
|
754
|
+
if (aggregation.array) return aggregation.first ? void 0 : [];
|
|
755
|
+
return NaN;
|
|
756
|
+
}
|
|
672
757
|
if (aggregation.array) {
|
|
673
758
|
const array = aggregation.items[aggregation.value];
|
|
674
759
|
return aggregation.first ? array[0] : array;
|
|
@@ -696,7 +781,7 @@ const aggregators = {
|
|
|
696
781
|
//#endregion
|
|
697
782
|
//#region src/internal/array/insert.ts
|
|
698
783
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
699
|
-
const actualDeleteCount = deleteCount
|
|
784
|
+
const actualDeleteCount = max([deleteCount, 0]);
|
|
700
785
|
const actualStart = min([max([0, start]), array.length]);
|
|
701
786
|
const chunked = chunk(items);
|
|
702
787
|
const lastIndex = chunked.length - 1;
|
|
@@ -719,7 +804,7 @@ function insertValues(type, array, items, start, deleteCount) {
|
|
|
719
804
|
//#endregion
|
|
720
805
|
//#region src/array/insert.ts
|
|
721
806
|
function insert(array, indexOrItems, items) {
|
|
722
|
-
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items
|
|
807
|
+
return insertValues(ARRAY_INSERT_TYPE_INSERT, array, items ?? indexOrItems, typeof indexOrItems === "number" ? indexOrItems : array?.length, 0);
|
|
723
808
|
}
|
|
724
809
|
//#endregion
|
|
725
810
|
//#region src/array/intersection.ts
|
|
@@ -758,6 +843,12 @@ function push(array, pushed) {
|
|
|
758
843
|
*
|
|
759
844
|
* @param array Array to reverse
|
|
760
845
|
* @returns Reversed array
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* ```typescript
|
|
849
|
+
* reverse([1, 2, 3]); // => [3, 2, 1]
|
|
850
|
+
* reverse(['a', 'b', 'c']); // => ['c', 'b', 'a']
|
|
851
|
+
* ```
|
|
761
852
|
*/
|
|
762
853
|
function reverse(array) {
|
|
763
854
|
if (!Array.isArray(array)) return [];
|
|
@@ -775,7 +866,7 @@ function reverse(array) {
|
|
|
775
866
|
//#endregion
|
|
776
867
|
//#region src/array/single.ts
|
|
777
868
|
function single(array, ...parameters) {
|
|
778
|
-
const { matched } = findValues("all", array, parameters);
|
|
869
|
+
const { matched } = findValues("all", array, parameters, { limit: 2 });
|
|
779
870
|
if (matched.length > 1) throw new Error(SINGLE_MESSAGE);
|
|
780
871
|
return matched[0];
|
|
781
872
|
}
|
|
@@ -789,34 +880,47 @@ function extract(type, array, first, second) {
|
|
|
789
880
|
if (!Array.isArray(array)) return [];
|
|
790
881
|
const { length } = array;
|
|
791
882
|
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);
|
|
883
|
+
const take = type === ARRAY_SLICE_TAKE;
|
|
884
|
+
return typeof first === "number" ? getSlice(array, length, first, take) : extractSlice(array, length, first, second, take);
|
|
885
|
+
}
|
|
886
|
+
function extractSlice(array, length, first, second, take) {
|
|
887
|
+
const callbacks = getCallbacks(first, second);
|
|
888
|
+
if (callbacks?.bool == null && callbacks?.value == null) return take ? array.slice() : [];
|
|
800
889
|
const isBoolean = callbacks?.bool != null;
|
|
801
|
-
if (callbacks?.bool == null && callbacks?.value == null) return isTake ? array.slice() : [];
|
|
802
890
|
const extracted = [];
|
|
803
891
|
let push = false;
|
|
804
892
|
for (let index = 0; index < length; index += 1) {
|
|
805
893
|
const item = array[index];
|
|
806
|
-
const matches =
|
|
807
|
-
|
|
808
|
-
|
|
894
|
+
const matches = isMatch(item, index, array, callbacks, second, isBoolean);
|
|
895
|
+
const reached = isBoolean ? !matches : matches;
|
|
896
|
+
if (take && reached) break;
|
|
897
|
+
if (push || take) {
|
|
809
898
|
extracted.push(item);
|
|
810
899
|
continue;
|
|
811
900
|
}
|
|
812
|
-
if (
|
|
813
|
-
else if (isBoolean ? !matches : matches) {
|
|
901
|
+
if (reached) {
|
|
814
902
|
push = true;
|
|
815
903
|
if (isBoolean) extracted.push(item);
|
|
816
904
|
}
|
|
817
905
|
}
|
|
818
906
|
return extracted;
|
|
819
907
|
}
|
|
908
|
+
function getCallbacks(first, second) {
|
|
909
|
+
let callbacks;
|
|
910
|
+
if (second == null) callbacks = getArrayCallbacks(first);
|
|
911
|
+
else callbacks = getArrayCallbacks(void 0, void 0, first);
|
|
912
|
+
return callbacks;
|
|
913
|
+
}
|
|
914
|
+
function getSlice(array, length, amount, take) {
|
|
915
|
+
if (Math.abs(amount) >= length) return take ? array.slice() : [];
|
|
916
|
+
if (amount === 0) return take ? [] : array.slice();
|
|
917
|
+
if (take) return amount >= 0 ? array.slice(0, amount) : array.slice(length + amount);
|
|
918
|
+
return amount >= 0 ? array.slice(amount) : array.slice(0, length + amount);
|
|
919
|
+
}
|
|
920
|
+
function isMatch(item, index, array, callbacks, second, isBoolean) {
|
|
921
|
+
if (isBoolean) return callbacks.bool(item, index, array);
|
|
922
|
+
return Object.is(callbacks.value(item, index, array), second);
|
|
923
|
+
}
|
|
820
924
|
function slice(array, first, second) {
|
|
821
925
|
if (!Array.isArray(array) || array.length === 0) return [];
|
|
822
926
|
const firstIsNumber = typeof first === "number";
|
|
@@ -993,22 +1097,28 @@ move.indices = moveIndices;
|
|
|
993
1097
|
move.toIndex = moveToIndex;
|
|
994
1098
|
//#endregion
|
|
995
1099
|
//#region src/array/select.ts
|
|
996
|
-
function
|
|
997
|
-
return selectValues(array,
|
|
1100
|
+
function filterAndFlatMap(array, filter, mapper) {
|
|
1101
|
+
return selectValues(array, filter, mapper, true, false);
|
|
1102
|
+
}
|
|
1103
|
+
function filterAndMap(array, filter, mapper) {
|
|
1104
|
+
return selectValues(array, filter, mapper, false, false);
|
|
998
1105
|
}
|
|
999
|
-
function
|
|
1000
|
-
return
|
|
1001
|
-
callback: parameters.shift(),
|
|
1002
|
-
reverse: true
|
|
1003
|
-
}).matched;
|
|
1106
|
+
function flatMapAndFilter(array, mapper, filter) {
|
|
1107
|
+
return selectValues(array, filter, mapper, true, true);
|
|
1004
1108
|
}
|
|
1005
|
-
function
|
|
1006
|
-
return
|
|
1007
|
-
callback: parameters.pop(),
|
|
1008
|
-
reverse: false
|
|
1009
|
-
}).matched;
|
|
1109
|
+
function mapAndFilter(array, mapper, filter) {
|
|
1110
|
+
return selectValues(array, filter, mapper, false, true);
|
|
1010
1111
|
}
|
|
1112
|
+
function selectValues(array, filter, mapper, flat, reverse) {
|
|
1113
|
+
return findValues("all", array, [filter], { map: {
|
|
1114
|
+
flat,
|
|
1115
|
+
reverse,
|
|
1116
|
+
callback: mapper
|
|
1117
|
+
} }).matched;
|
|
1118
|
+
}
|
|
1119
|
+
filterAndMap.flat = filterAndFlatMap;
|
|
1011
1120
|
filterAndMap.reverse = mapAndFilter;
|
|
1121
|
+
mapAndFilter.flat = flatMapAndFilter;
|
|
1012
1122
|
//#endregion
|
|
1013
1123
|
//#region src/models/value/value.misc.model.ts
|
|
1014
1124
|
const COMPARE_NAME = "compare";
|
|
@@ -1022,7 +1132,7 @@ const VALUE_MISC_NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed
|
|
|
1022
1132
|
//#endregion
|
|
1023
1133
|
//#region src/models/string/string.misc.model.ts
|
|
1024
1134
|
const STRING_EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
|
|
1025
|
-
const STRING_EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]
|
|
1135
|
+
const STRING_EXPRESSION_WORDS = /([^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+)/g;
|
|
1026
1136
|
const STRING_EXPRESSION_WHITESPACE_PREFIX = /^(\s+)/;
|
|
1027
1137
|
const STRING_MATCH_ENDS_WITH = "endsWith";
|
|
1028
1138
|
const STRING_MATCH_INCLUDES = "includes";
|
|
@@ -1079,18 +1189,11 @@ error.is = isError;
|
|
|
1079
1189
|
ok.is = isOk;
|
|
1080
1190
|
//#endregion
|
|
1081
1191
|
//#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
1192
|
async function toPromise(result) {
|
|
1091
1193
|
const actual = typeof result === "function" ? result() : result;
|
|
1092
|
-
if (!isResult(actual))
|
|
1093
|
-
|
|
1194
|
+
if (!isResult(actual)) throw new TypeError(RESULT_MESSAGE_PROMISE);
|
|
1195
|
+
if (isOk(actual)) return actual.value;
|
|
1196
|
+
throw actual.error;
|
|
1094
1197
|
}
|
|
1095
1198
|
const RESULT_MESSAGE_PROMISE = "toPromise expected to receive a Result";
|
|
1096
1199
|
//#endregion
|
|
@@ -1102,15 +1205,15 @@ async function asyncAttempt(value, err) {
|
|
|
1102
1205
|
else result = value;
|
|
1103
1206
|
if (result instanceof Promise) result = await result;
|
|
1104
1207
|
return ok(result);
|
|
1105
|
-
} catch (
|
|
1106
|
-
return getError(err ??
|
|
1208
|
+
} catch (error) {
|
|
1209
|
+
return getError(err ?? error, err == null ? void 0 : error);
|
|
1107
1210
|
}
|
|
1108
1211
|
}
|
|
1109
1212
|
function attempt(callback, err) {
|
|
1110
1213
|
try {
|
|
1111
1214
|
return ok(callback());
|
|
1112
|
-
} catch (
|
|
1113
|
-
return getError(err ??
|
|
1215
|
+
} catch (error) {
|
|
1216
|
+
return getError(err ?? error, err == null ? void 0 : error);
|
|
1114
1217
|
}
|
|
1115
1218
|
}
|
|
1116
1219
|
attempt.async = asyncAttempt;
|
|
@@ -1141,9 +1244,15 @@ function getString(value) {
|
|
|
1141
1244
|
const asString = String(value.valueOf?.() ?? value);
|
|
1142
1245
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
1143
1246
|
}
|
|
1247
|
+
/**
|
|
1248
|
+
* @internal
|
|
1249
|
+
*/
|
|
1144
1250
|
function ignoreKey(key) {
|
|
1145
1251
|
return STRING_EXPRESSION_IGNORED.test(key);
|
|
1146
1252
|
}
|
|
1253
|
+
/**
|
|
1254
|
+
* @internal
|
|
1255
|
+
*/
|
|
1147
1256
|
function interpolate(strings, values) {
|
|
1148
1257
|
const { length } = strings;
|
|
1149
1258
|
let interpolated = "";
|
|
@@ -1161,6 +1270,14 @@ function interpolate(strings, values) {
|
|
|
1161
1270
|
* @param array Array of values
|
|
1162
1271
|
* @param delimiter Delimiter to use between values
|
|
1163
1272
|
* @returns Joined string
|
|
1273
|
+
* @example
|
|
1274
|
+
* ```typescript
|
|
1275
|
+
* join(['a', 'b', 'c']); // => 'abc'
|
|
1276
|
+
* join(['a', 'b', 'c'], ', '); // => 'a, b, c'
|
|
1277
|
+
* join(['a', '', 'c']); // => 'ac'
|
|
1278
|
+
* join([null, 'b', undefined]); // => 'b'
|
|
1279
|
+
* join([]); // => ''
|
|
1280
|
+
* ```
|
|
1164
1281
|
*/
|
|
1165
1282
|
function join(array, delimiter) {
|
|
1166
1283
|
if (!Array.isArray(array)) return "";
|
|
@@ -1176,9 +1293,15 @@ function join(array, delimiter) {
|
|
|
1176
1293
|
function tryCallback(value, callback) {
|
|
1177
1294
|
return unwrap(attempt(() => callback(value)), value);
|
|
1178
1295
|
}
|
|
1296
|
+
/**
|
|
1297
|
+
* @internal
|
|
1298
|
+
*/
|
|
1179
1299
|
function tryDecode(value) {
|
|
1180
1300
|
return tryCallback(value, decodeURIComponent);
|
|
1181
1301
|
}
|
|
1302
|
+
/**
|
|
1303
|
+
* @internal
|
|
1304
|
+
*/
|
|
1182
1305
|
function tryEncode(value) {
|
|
1183
1306
|
return tryCallback(value, encodeURIComponent);
|
|
1184
1307
|
}
|
|
@@ -1189,7 +1312,8 @@ function tryEncode(value) {
|
|
|
1189
1312
|
* @returns Array of words found in the string
|
|
1190
1313
|
*/
|
|
1191
1314
|
function words(value) {
|
|
1192
|
-
|
|
1315
|
+
if (typeof value === "string") return value.match(STRING_EXPRESSION_WORDS) ?? [];
|
|
1316
|
+
return [];
|
|
1193
1317
|
}
|
|
1194
1318
|
//#endregion
|
|
1195
1319
|
//#region src/internal/value/handlers.ts
|
|
@@ -1442,7 +1566,7 @@ function isSortedArray(array) {
|
|
|
1442
1566
|
let offset = 0;
|
|
1443
1567
|
if (length >= 100) {
|
|
1444
1568
|
offset = round(length / 10);
|
|
1445
|
-
offset = offset
|
|
1569
|
+
offset = min([offset, 100]);
|
|
1446
1570
|
for (let index = 0; index < offset; index += 1) {
|
|
1447
1571
|
const [firstItem, firstOffset] = [array[index], array[index + 1]];
|
|
1448
1572
|
const [secondItem, secondOffset] = [array[length - index - 2], array[length - index - 1]];
|
|
@@ -2088,8 +2212,11 @@ async function asyncRetry(callback, options) {
|
|
|
2088
2212
|
if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
|
|
2089
2213
|
async function handle() {
|
|
2090
2214
|
const result = await asyncAttempt(async () => callback());
|
|
2091
|
-
if (result.ok)
|
|
2092
|
-
|
|
2215
|
+
if (result.ok) {
|
|
2216
|
+
resolver(result.value);
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
if (attempts >= times || !when(result.error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, result.error));
|
|
2093
2220
|
else {
|
|
2094
2221
|
attempts += 1;
|
|
2095
2222
|
limiter.run();
|
|
@@ -2160,8 +2287,15 @@ const EXPRESSION_WHITESPACE_ONLY = /^\s*$/;
|
|
|
2160
2287
|
*
|
|
2161
2288
|
* @param value Value to check
|
|
2162
2289
|
* @param minimum Minimum value
|
|
2163
|
-
* @param maximum Maximum value
|
|
2290
|
+
* @param maximum Maximum value _(inclusive)_
|
|
2164
2291
|
* @returns `true` if the value is between the minimum and maximum, otherwise `false`
|
|
2292
|
+
*
|
|
2293
|
+
* @example
|
|
2294
|
+
* ```typescript
|
|
2295
|
+
* between(5, 1, 10); // => true
|
|
2296
|
+
* between(0, 1, 10); // => false
|
|
2297
|
+
* between(10, 10, 10); // => true
|
|
2298
|
+
* ```
|
|
2165
2299
|
*/
|
|
2166
2300
|
function between(value, minimum, maximum) {
|
|
2167
2301
|
if (![
|
|
@@ -2170,7 +2304,8 @@ function between(value, minimum, maximum) {
|
|
|
2170
2304
|
maximum
|
|
2171
2305
|
].every(isNumber)) return false;
|
|
2172
2306
|
if (Object.is(minimum, maximum)) return Object.is(value, minimum);
|
|
2173
|
-
|
|
2307
|
+
const maximumValue = max([maximum, minimum]);
|
|
2308
|
+
return value >= min([maximum, minimum]) && value <= maximumValue;
|
|
2174
2309
|
}
|
|
2175
2310
|
/**
|
|
2176
2311
|
* Clamp a number between a minimum and maximum value
|
|
@@ -2203,6 +2338,17 @@ function clamp(value, minimum, maximum, loop) {
|
|
|
2203
2338
|
*
|
|
2204
2339
|
* @param value Original value
|
|
2205
2340
|
* @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
|
|
2341
|
+
*
|
|
2342
|
+
* @example
|
|
2343
|
+
* ```typescript
|
|
2344
|
+
* getNumber(null) // => Number.NaN
|
|
2345
|
+
* getNumber('foo') // => Number.NaN
|
|
2346
|
+
* getNumber('123') // => 123
|
|
2347
|
+
* getNumber(true) // => 1
|
|
2348
|
+
* getNumber([1, 2, 3]) // => Number.NaN
|
|
2349
|
+
* getNumber({a: 1}) // => Number.NaN
|
|
2350
|
+
* getNumber(() => 123) // => 123
|
|
2351
|
+
* ```
|
|
2206
2352
|
*/
|
|
2207
2353
|
function getNumber(value) {
|
|
2208
2354
|
if (typeof value === "number") return value;
|
|
@@ -2435,6 +2581,14 @@ const STRING_REPLACEMENT_CAMEL_CASE = "$1-$2";
|
|
|
2435
2581
|
*
|
|
2436
2582
|
* @param value String to convert
|
|
2437
2583
|
* @returns Camel-cased string
|
|
2584
|
+
*
|
|
2585
|
+
* @example
|
|
2586
|
+
* ```typescript
|
|
2587
|
+
* camelCase('this is camel case'); // => 'thisIsCamelCase'
|
|
2588
|
+
* camelCase('ThisIsCamelCase'); // => 'thisIsCamelCase'
|
|
2589
|
+
* camelCase('this-is-camel-case'); // => 'thisIsCamelCase'
|
|
2590
|
+
* camelCase('this_is_camel_case'); // => 'thisIsCamelCase'
|
|
2591
|
+
* ```
|
|
2438
2592
|
*/
|
|
2439
2593
|
function camelCase(value) {
|
|
2440
2594
|
return toCase(STRING_CASE_CAMEL, value, true, false);
|
|
@@ -2444,6 +2598,14 @@ function camelCase(value) {
|
|
|
2444
2598
|
*
|
|
2445
2599
|
* @param value String to capitalize
|
|
2446
2600
|
* @returns Capitalized string
|
|
2601
|
+
*
|
|
2602
|
+
* @example
|
|
2603
|
+
* ```typescript
|
|
2604
|
+
* capitalize('this is a test'); // => 'This is a test'
|
|
2605
|
+
* capitalize('This Is A Test'); // => 'This is a test'
|
|
2606
|
+
* capitalize('t'); // => 'T'
|
|
2607
|
+
* capitalize(''); // => ''
|
|
2608
|
+
* ```
|
|
2447
2609
|
*/
|
|
2448
2610
|
function capitalize(value) {
|
|
2449
2611
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -2455,6 +2617,14 @@ function capitalize(value) {
|
|
|
2455
2617
|
*
|
|
2456
2618
|
* @param value String to convert
|
|
2457
2619
|
* @returns Kebab-cased string
|
|
2620
|
+
*
|
|
2621
|
+
* @example
|
|
2622
|
+
* ```typescript
|
|
2623
|
+
* kebabCase('this is kebab case'); // => 'this-is-kebab-case'
|
|
2624
|
+
* kebabCase('ThisIsKebabCase'); // => 'this-is-kebab-case'
|
|
2625
|
+
* kebabCase('this-is-kebab-case'); // => 'this-is-kebab-case'
|
|
2626
|
+
* kebabCase('this_is_kebab_case'); // => 'this-is-kebab-case'
|
|
2627
|
+
* ```
|
|
2458
2628
|
*/
|
|
2459
2629
|
function kebabCase(value) {
|
|
2460
2630
|
return toCase(STRING_CASE_KEBAB, value, false, false);
|
|
@@ -2464,6 +2634,13 @@ function kebabCase(value) {
|
|
|
2464
2634
|
*
|
|
2465
2635
|
* @param value String to convert
|
|
2466
2636
|
* @returns Lower-cased string
|
|
2637
|
+
*
|
|
2638
|
+
* @example
|
|
2639
|
+
* ```typescript
|
|
2640
|
+
* lowerCase('THIS IS A TEST'); // => 'this is a test'
|
|
2641
|
+
* lowerCase('this is a test'); // => 'this is a test'
|
|
2642
|
+
* lowerCase('t'); // => 't'
|
|
2643
|
+
* ```
|
|
2467
2644
|
*/
|
|
2468
2645
|
function lowerCase(value) {
|
|
2469
2646
|
if (typeof value !== "string") return "";
|
|
@@ -2475,6 +2652,14 @@ function lowerCase(value) {
|
|
|
2475
2652
|
*
|
|
2476
2653
|
* @param value String to convert
|
|
2477
2654
|
* @returns Pascal-cased string
|
|
2655
|
+
*
|
|
2656
|
+
* @example
|
|
2657
|
+
* ```typescript
|
|
2658
|
+
* pascalCase('this is pascal case'); // => 'ThisIsPascalCase'
|
|
2659
|
+
* pascalCase('ThisIsPascalCase'); // => 'ThisIsPascalCase'
|
|
2660
|
+
* pascalCase('this-is-pascal-case'); // => 'ThisIsPascalCase'
|
|
2661
|
+
* pascalCase('this_is_pascal_case'); // => 'ThisIsPascalCase'
|
|
2662
|
+
* ```
|
|
2478
2663
|
*/
|
|
2479
2664
|
function pascalCase(value) {
|
|
2480
2665
|
return toCase(STRING_CASE_PASCAL, value, true, true);
|
|
@@ -2484,6 +2669,14 @@ function pascalCase(value) {
|
|
|
2484
2669
|
*
|
|
2485
2670
|
* @param value String to convert
|
|
2486
2671
|
* @returns Snake-cased string
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* ```typescript
|
|
2675
|
+
* snakeCase('this is snake case'); // => 'this_is_snake_case'
|
|
2676
|
+
* snakeCase('ThisIsSnakeCase'); // => 'this_is_snake_case'
|
|
2677
|
+
* snakeCase('this-is-snake-case'); // => 'this_is_snake_case'
|
|
2678
|
+
* snakeCase('this_is_snake_case'); // => 'this_is_snake_case'
|
|
2679
|
+
* ```
|
|
2487
2680
|
*/
|
|
2488
2681
|
function snakeCase(value) {
|
|
2489
2682
|
return toCase(STRING_CASE_SNAKE, value, false, false);
|
|
@@ -2493,6 +2686,14 @@ function snakeCase(value) {
|
|
|
2493
2686
|
*
|
|
2494
2687
|
* @param value String to convert
|
|
2495
2688
|
* @returns Title-cased string
|
|
2689
|
+
*
|
|
2690
|
+
* @example
|
|
2691
|
+
* ```typescript
|
|
2692
|
+
* titleCase('this is a test'); // => 'This Is A Test'
|
|
2693
|
+
* titleCase('This Is A Test'); // => 'This Is A Test'
|
|
2694
|
+
* titleCase('t'); // => 'T'
|
|
2695
|
+
* titleCase(''); // => ''
|
|
2696
|
+
* ```
|
|
2496
2697
|
*/
|
|
2497
2698
|
function titleCase(value) {
|
|
2498
2699
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -2535,6 +2736,14 @@ function toCaseCallback(value) {
|
|
|
2535
2736
|
*
|
|
2536
2737
|
* @param value String to convert
|
|
2537
2738
|
* @returns Upper-cased string
|
|
2739
|
+
*
|
|
2740
|
+
* @example
|
|
2741
|
+
* ```typescript
|
|
2742
|
+
* upperCase('this is a test'); // => 'THIS IS A TEST'
|
|
2743
|
+
* upperCase('This Is A Test'); // => 'THIS IS A TEST'
|
|
2744
|
+
* upperCase('t'); // => 'T'
|
|
2745
|
+
* upperCase(''); // => ''
|
|
2746
|
+
* ```
|
|
2538
2747
|
*/
|
|
2539
2748
|
function upperCase(value) {
|
|
2540
2749
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -2619,7 +2828,7 @@ function equalArray(first, second, options) {
|
|
|
2619
2828
|
let offset = 0;
|
|
2620
2829
|
if (length >= 100) {
|
|
2621
2830
|
offset = round(length / 10);
|
|
2622
|
-
offset = offset
|
|
2831
|
+
offset = min([offset, 100]);
|
|
2623
2832
|
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
2833
|
}
|
|
2625
2834
|
const end = length - offset;
|
|
@@ -2776,6 +2985,8 @@ const PLAN_FAILURE_ASYNC = "asyncFailure";
|
|
|
2776
2985
|
const PLAN_FAILURE_SYNC = "failure";
|
|
2777
2986
|
const PLAN_MESSAGE_PLAN_INPUT = "plan requires a generator function";
|
|
2778
2987
|
const PLAN_MESSAGE_RUN_INPUT = "run requires a plan or a generator function";
|
|
2988
|
+
const PLAN_MESSAGE_USE_NESTED_FN = "Cannot use nested functions with 'use'";
|
|
2989
|
+
const PLAN_MESSAGE_USE_SYNC_ASYNC = "Cannot use asynchronous values with 'use'";
|
|
2779
2990
|
const PLAN_STEP_ASYNC = "asyncStep";
|
|
2780
2991
|
const PLAN_STEP_SYNC = "step";
|
|
2781
2992
|
const PLAN_SUCCESS_ASYNC = "asyncSuccess";
|
|
@@ -2802,7 +3013,7 @@ function createAborter(value, onAbort) {
|
|
|
2802
3013
|
//#region src/internal/plan/plan.generate.ts
|
|
2803
3014
|
async function asyncGenerate(input, unwrap, first, second) {
|
|
2804
3015
|
const aborter = createAborter(second ?? first, noop);
|
|
2805
|
-
if (aborter
|
|
3016
|
+
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
2806
3017
|
const parameters = Array.isArray(first) ? first : [];
|
|
2807
3018
|
let generator;
|
|
2808
3019
|
if (typeof input === "function") generator = input(...parameters);
|
|
@@ -2811,7 +3022,7 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
2811
3022
|
let lastValue;
|
|
2812
3023
|
try {
|
|
2813
3024
|
while (true) {
|
|
2814
|
-
if (aborter
|
|
3025
|
+
if (aborter?.signal.aborted) await generator.throw(aborter.signal.reason);
|
|
2815
3026
|
const next = await generator.next(lastValue);
|
|
2816
3027
|
const done = next.done === true;
|
|
2817
3028
|
const { value } = next;
|
|
@@ -2827,7 +3038,7 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
2827
3038
|
aborter?.cancel();
|
|
2828
3039
|
await generator.return(lastValue);
|
|
2829
3040
|
}
|
|
2830
|
-
if (aborter
|
|
3041
|
+
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
2831
3042
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
2832
3043
|
throw lastValue;
|
|
2833
3044
|
}
|
|
@@ -3004,21 +3215,6 @@ function attemptRun(input, ...parameters) {
|
|
|
3004
3215
|
}
|
|
3005
3216
|
attemptRun.async = asyncAttemptRun;
|
|
3006
3217
|
//#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
3218
|
//#region src/plan/index.ts
|
|
3023
3219
|
function AsyncPlan(generator) {
|
|
3024
3220
|
this[PLAN_SYMBOL] = {
|
|
@@ -3099,6 +3295,21 @@ function succeed(value) {
|
|
|
3099
3295
|
fail.async = asyncFail;
|
|
3100
3296
|
succeed.async = asyncSucceed;
|
|
3101
3297
|
//#endregion
|
|
3298
|
+
//#region src/plan/run.ts
|
|
3299
|
+
function asyncRun(input, first, second) {
|
|
3300
|
+
if (isAsyncPlan(input)) return asyncGenerate(input[PLAN_SYMBOL], false, first, second);
|
|
3301
|
+
if (isAsyncGeneratorFunction(input)) return asyncGenerate(input, false, first, second);
|
|
3302
|
+
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
3303
|
+
}
|
|
3304
|
+
function run(input, ...parameters) {
|
|
3305
|
+
if (isPlan(input)) return input.run(...parameters);
|
|
3306
|
+
if (isGeneratorFunction(input)) return generate(input, parameters, false);
|
|
3307
|
+
throw new Error(PLAN_MESSAGE_RUN_INPUT);
|
|
3308
|
+
}
|
|
3309
|
+
asyncRun.attempt = asyncAttemptRun;
|
|
3310
|
+
run.async = asyncRun;
|
|
3311
|
+
run.attempt = attemptRun;
|
|
3312
|
+
//#endregion
|
|
3102
3313
|
//#region src/plan/use.ts
|
|
3103
3314
|
function AsyncStep(generator) {
|
|
3104
3315
|
this[PLAN_SYMBOL] = {
|
|
@@ -3119,7 +3330,7 @@ function asyncUse(value) {
|
|
|
3119
3330
|
let actual = value;
|
|
3120
3331
|
if (typeof actual === "function") actual = actual();
|
|
3121
3332
|
actual = await actual;
|
|
3122
|
-
if (typeof actual === "function") throw new
|
|
3333
|
+
if (typeof actual === "function") throw new TypeError(PLAN_MESSAGE_USE_NESTED_FN);
|
|
3123
3334
|
if (typeof actual === "object" && actual !== null && PLAN_SYMBOL in actual) return yield* actual;
|
|
3124
3335
|
if (isAsyncGenerator(actual) || isGenerator(actual)) return yield* actual;
|
|
3125
3336
|
if (isError(actual)) {
|
|
@@ -3157,8 +3368,8 @@ function use(value) {
|
|
|
3157
3368
|
});
|
|
3158
3369
|
}
|
|
3159
3370
|
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();
|
|
3371
|
+
if (value instanceof Promise || isAsyncFailure(value) || isAsyncGenerator(value) || isAsyncGeneratorFunction(value) || isAsyncPlan(value) || isAsyncStep(value) || isAsyncSuccess(value)) throw new Error(PLAN_MESSAGE_USE_SYNC_ASYNC);
|
|
3372
|
+
if (resolved && typeof value === "function") throw new Error(PLAN_MESSAGE_USE_NESTED_FN);
|
|
3162
3373
|
}
|
|
3163
3374
|
use.async = asyncUse;
|
|
3164
3375
|
//#endregion
|
|
@@ -3277,6 +3488,9 @@ function isRejected(value) {
|
|
|
3277
3488
|
function cancelable(executor) {
|
|
3278
3489
|
return new CancelablePromise(executor);
|
|
3279
3490
|
}
|
|
3491
|
+
/**
|
|
3492
|
+
* @internal
|
|
3493
|
+
*/
|
|
3280
3494
|
function handleResult(status, parameters) {
|
|
3281
3495
|
const { aborter, complete, data, handlers, index, key, value } = parameters;
|
|
3282
3496
|
if (aborter?.signal.aborted ?? false) return;
|
|
@@ -3285,25 +3499,31 @@ function handleResult(status, parameters) {
|
|
|
3285
3499
|
handlers.reject(value);
|
|
3286
3500
|
return;
|
|
3287
3501
|
}
|
|
3288
|
-
|
|
3502
|
+
let resultValue;
|
|
3503
|
+
if (complete) resultValue = status === "fulfilled" ? {
|
|
3289
3504
|
status,
|
|
3290
3505
|
value
|
|
3291
3506
|
} : {
|
|
3292
3507
|
status,
|
|
3293
3508
|
reason: value
|
|
3294
3509
|
};
|
|
3510
|
+
else resultValue = value;
|
|
3511
|
+
data.result[key] = resultValue;
|
|
3295
3512
|
if (index === data.last) {
|
|
3296
3513
|
aborter?.cancel();
|
|
3297
3514
|
handlers.resolve(data.result);
|
|
3298
3515
|
}
|
|
3299
3516
|
}
|
|
3517
|
+
/**
|
|
3518
|
+
* @internal
|
|
3519
|
+
*/
|
|
3300
3520
|
function settlePromise(settler, value, aborter) {
|
|
3301
3521
|
aborter?.cancel();
|
|
3302
3522
|
settler(value);
|
|
3303
3523
|
}
|
|
3304
3524
|
async function toResult(value) {
|
|
3305
3525
|
const actual = typeof value === "function" ? value() : value;
|
|
3306
|
-
if (!(actual instanceof Promise))
|
|
3526
|
+
if (!(actual instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT);
|
|
3307
3527
|
return actual.then((result) => ok(result)).catch((reason) => error(reason));
|
|
3308
3528
|
}
|
|
3309
3529
|
//#endregion
|
|
@@ -3327,6 +3547,9 @@ function delay(options) {
|
|
|
3327
3547
|
}
|
|
3328
3548
|
//#endregion
|
|
3329
3549
|
//#region src/promise/timed.ts
|
|
3550
|
+
/**
|
|
3551
|
+
* @internal
|
|
3552
|
+
*/
|
|
3330
3553
|
async function getTimedPromise(promise, time, signal) {
|
|
3331
3554
|
const aborter = createAborter(signal, () => {
|
|
3332
3555
|
limiter.cancel();
|
|
@@ -3345,18 +3568,18 @@ async function getTimedPromise(promise, time, signal) {
|
|
|
3345
3568
|
});
|
|
3346
3569
|
}
|
|
3347
3570
|
async function timed(promise, options) {
|
|
3348
|
-
if (!(promise instanceof Promise))
|
|
3571
|
+
if (!(promise instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED);
|
|
3349
3572
|
const { signal, time } = createPromiseOptions(options);
|
|
3350
|
-
if (signal?.aborted ?? false)
|
|
3573
|
+
if (signal?.aborted ?? false) throw signal?.reason;
|
|
3351
3574
|
return time > 0 ? getTimedPromise(promise, time, signal) : promise;
|
|
3352
3575
|
}
|
|
3353
3576
|
//#endregion
|
|
3354
3577
|
//#region src/promise/index.ts
|
|
3355
3578
|
async function attemptPromise(value, options) {
|
|
3356
3579
|
const isFunction = typeof value === "function";
|
|
3357
|
-
if (!isFunction && !(value instanceof Promise))
|
|
3580
|
+
if (!isFunction && !(value instanceof Promise)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT);
|
|
3358
3581
|
const { signal, time } = createPromiseOptions(options);
|
|
3359
|
-
if (signal?.aborted ?? false)
|
|
3582
|
+
if (signal?.aborted ?? false) throw signal?.reason;
|
|
3360
3583
|
const aborter = createAborter(signal, () => {
|
|
3361
3584
|
rejector(signal?.reason);
|
|
3362
3585
|
});
|
|
@@ -3378,8 +3601,8 @@ async function attemptPromise(value, options) {
|
|
|
3378
3601
|
}
|
|
3379
3602
|
async function promises(items, options) {
|
|
3380
3603
|
const { signal, strategy } = createPromisesOptions(options);
|
|
3381
|
-
if (signal?.aborted ?? false)
|
|
3382
|
-
if (!isArrayOrPlainObject(items))
|
|
3604
|
+
if (signal?.aborted ?? false) throw signal?.reason;
|
|
3605
|
+
if (!isArrayOrPlainObject(items)) throw new TypeError(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
|
|
3383
3606
|
const isArray = Array.isArray(items);
|
|
3384
3607
|
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
3608
|
const aborter = createAborter(signal, () => {
|
|
@@ -3442,10 +3665,10 @@ function handleResult$1(result, first, second) {
|
|
|
3442
3665
|
error = second;
|
|
3443
3666
|
}
|
|
3444
3667
|
if (isOk(result)) {
|
|
3445
|
-
if (typeof ok !== "function") throw new
|
|
3668
|
+
if (typeof ok !== "function") throw new TypeError(MATCH_MESSAGE_OK);
|
|
3446
3669
|
return ok(result.value);
|
|
3447
3670
|
}
|
|
3448
|
-
if (typeof error !== "function") throw new
|
|
3671
|
+
if (typeof error !== "function") throw new TypeError(MATCH_MESSAGE_ERROR);
|
|
3449
3672
|
return error(result.error, result.original);
|
|
3450
3673
|
}
|
|
3451
3674
|
function matchResult(result, first, second) {
|
|
@@ -3483,9 +3706,11 @@ attemptFlow.async = attemptAsyncFlow;
|
|
|
3483
3706
|
//#endregion
|
|
3484
3707
|
//#region src/result/work/pipe.ts
|
|
3485
3708
|
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
3486
|
-
return asyncAttempt(() => {
|
|
3709
|
+
return asyncAttempt(async () => {
|
|
3487
3710
|
if (isError(initial)) throw initial.error;
|
|
3488
|
-
|
|
3711
|
+
let value;
|
|
3712
|
+
if (typeof initial === "function") value = initial();
|
|
3713
|
+
else value = isOk(initial) ? initial.value : initial;
|
|
3489
3714
|
if (first == null) return value;
|
|
3490
3715
|
return asyncPipe(value, ...[first, ...seconds]);
|
|
3491
3716
|
});
|
|
@@ -3493,7 +3718,9 @@ async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
|
3493
3718
|
function attemptPipe(initial, first, ...seconds) {
|
|
3494
3719
|
return attempt(() => {
|
|
3495
3720
|
if (isError(initial)) throw initial.error;
|
|
3496
|
-
|
|
3721
|
+
let value;
|
|
3722
|
+
if (typeof initial === "function") value = initial();
|
|
3723
|
+
else value = isOk(initial) ? initial.value : initial;
|
|
3497
3724
|
if (first == null) return value;
|
|
3498
3725
|
return pipe(value, ...[first, ...seconds]);
|
|
3499
3726
|
});
|
|
@@ -3514,6 +3741,14 @@ const FUZZY_SYMBOL = Symbol(FUZZY_PROPERTY);
|
|
|
3514
3741
|
* @param needle String to look for
|
|
3515
3742
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
3516
3743
|
* @returns `true` if the string ends with the given substring, otherwise `false`
|
|
3744
|
+
*
|
|
3745
|
+
* @example
|
|
3746
|
+
* ```typescript
|
|
3747
|
+
* endsWith('this is a test', 'test'); // => true
|
|
3748
|
+
* endsWith('this is a test', 'Test'); // => false
|
|
3749
|
+
* endsWith('this is a test', 'Test', true); // => true
|
|
3750
|
+
* endsWith('this is a test', 'not'); // => false
|
|
3751
|
+
* ```
|
|
3517
3752
|
*/
|
|
3518
3753
|
function endsWith(haystack, needle, ignoreCase) {
|
|
3519
3754
|
return match(STRING_MATCH_ENDS_WITH, haystack, needle, ignoreCase === true);
|
|
@@ -3525,6 +3760,14 @@ function endsWith(haystack, needle, ignoreCase) {
|
|
|
3525
3760
|
* @param needle String to look for
|
|
3526
3761
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
3527
3762
|
* @returns `true` if the string includes the given substring, otherwise `false`
|
|
3763
|
+
*
|
|
3764
|
+
* @example
|
|
3765
|
+
* ```typescript
|
|
3766
|
+
* includes('this is a test', 'is'); // => true
|
|
3767
|
+
* includes('this is a test', 'Is'); // => false
|
|
3768
|
+
* includes('this is a test', 'Is', true); // => true
|
|
3769
|
+
* includes('this is a test', 'not'); // => false
|
|
3770
|
+
* ```
|
|
3528
3771
|
*/
|
|
3529
3772
|
function includes(haystack, needle, ignoreCase) {
|
|
3530
3773
|
return match(STRING_MATCH_INCLUDES, haystack, needle, ignoreCase === true);
|
|
@@ -3544,6 +3787,14 @@ function matchCallback(haystack, needle, ignoreCase) {
|
|
|
3544
3787
|
* @param needle String to look for
|
|
3545
3788
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
3546
3789
|
* @returns `true` if the string starts with the given substring, otherwise `false`
|
|
3790
|
+
*
|
|
3791
|
+
* @example
|
|
3792
|
+
* ```typescript
|
|
3793
|
+
* startsWith('this is a test', 'this'); // => true
|
|
3794
|
+
* startsWith('this is a test', 'This'); // => false
|
|
3795
|
+
* startsWith('this is a test', 'This', true); // => true
|
|
3796
|
+
* startsWith('this is a test', 'not'); // => false
|
|
3797
|
+
* ```
|
|
3547
3798
|
*/
|
|
3548
3799
|
function startsWith(haystack, needle, ignoreCase) {
|
|
3549
3800
|
return match(STRING_MATCH_STARTS_WITH, haystack, needle, ignoreCase === true);
|
|
@@ -3568,7 +3819,7 @@ Object.defineProperties(Fuzzy.prototype, {
|
|
|
3568
3819
|
}
|
|
3569
3820
|
});
|
|
3570
3821
|
function createFuzzyItems(items) {
|
|
3571
|
-
return items.
|
|
3822
|
+
return items.toSorted((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
3572
3823
|
}
|
|
3573
3824
|
function createFuzzyOptions(input, state) {
|
|
3574
3825
|
const options = isPlainObject(input) ? input : {};
|
|
@@ -3751,7 +4002,7 @@ function dedent(value, ...values) {
|
|
|
3751
4002
|
}
|
|
3752
4003
|
if (lengths.length === 0) return actual.trim();
|
|
3753
4004
|
const minimum = min(lengths);
|
|
3754
|
-
const pattern = new RegExp(
|
|
4005
|
+
const pattern = new RegExp(String.raw`^\s{0,${minimum}}`);
|
|
3755
4006
|
let result = "";
|
|
3756
4007
|
for (let index = 0; index < length; index += 1) {
|
|
3757
4008
|
const line = lines[index];
|
|
@@ -3788,7 +4039,7 @@ function getUuid(html) {
|
|
|
3788
4039
|
*
|
|
3789
4040
|
* @param value JSON string to parse
|
|
3790
4041
|
* @param reviver Reviver function to transform the parsed values
|
|
3791
|
-
* @returns Parsed value or `undefined` if parsing fails
|
|
4042
|
+
* @returns Parsed value, or `undefined` if parsing fails
|
|
3792
4043
|
*/
|
|
3793
4044
|
function parse(value, reviver) {
|
|
3794
4045
|
try {
|
|
@@ -3802,6 +4053,13 @@ function parse(value, reviver) {
|
|
|
3802
4053
|
*
|
|
3803
4054
|
* @param value String to trim
|
|
3804
4055
|
* @returns Trimmed string
|
|
4056
|
+
* @example
|
|
4057
|
+
* ```typescript
|
|
4058
|
+
* trim(' this is a test '); // => 'this is a test'
|
|
4059
|
+
* trim('this is a test'); // => 'this is a test'
|
|
4060
|
+
* trim(' '); // => ''
|
|
4061
|
+
* trim(''); // => ''
|
|
4062
|
+
* ```
|
|
3805
4063
|
*/
|
|
3806
4064
|
function trim(value) {
|
|
3807
4065
|
return typeof value === "string" ? value.trim() : "";
|
|
@@ -3813,6 +4071,13 @@ function trim(value) {
|
|
|
3813
4071
|
* @param length Maximum length of the string after truncation
|
|
3814
4072
|
* @param suffix Suffix to append to the truncated string
|
|
3815
4073
|
* @returns Truncated string
|
|
4074
|
+
* @example
|
|
4075
|
+
* ```typescript
|
|
4076
|
+
* truncate('this is a test', 7); // => 'this is'
|
|
4077
|
+
* truncate('this is a test', 7, '...'); // => 'this ...'
|
|
4078
|
+
* truncate('this is a test', 20); // => 'this is a test'
|
|
4079
|
+
* truncate('this is a test', 0); // => ''
|
|
4080
|
+
* ```
|
|
3816
4081
|
*/
|
|
3817
4082
|
function truncate(value, length, suffix) {
|
|
3818
4083
|
if (typeof value !== "string" || typeof length !== "number" || length === 0) return "";
|
|
@@ -4020,7 +4285,7 @@ function clone(value, options) {
|
|
|
4020
4285
|
function cloneAny(value, parameters, depth, options) {
|
|
4021
4286
|
switch (true) {
|
|
4022
4287
|
case value === null || CLONE_PRIMITIVES[typeof value]: return value;
|
|
4023
|
-
case value instanceof Date: return new Date(value
|
|
4288
|
+
case value instanceof Date: return new Date(value);
|
|
4024
4289
|
case typeof value === "function":
|
|
4025
4290
|
parameters.options ??= createCloneOptions(options);
|
|
4026
4291
|
return parameters.options.copyFunctions ? value : void 0;
|
|
@@ -4384,7 +4649,9 @@ freeze.is = isFrozen;
|
|
|
4384
4649
|
//#region src/internal/value/partial.ts
|
|
4385
4650
|
function partial(value, providedKeys, omit) {
|
|
4386
4651
|
if (!isPlainObject(value)) return {};
|
|
4387
|
-
|
|
4652
|
+
let keys;
|
|
4653
|
+
if (omit) keys = Object.keys(value);
|
|
4654
|
+
else keys = Array.isArray(providedKeys) ? providedKeys : [];
|
|
4388
4655
|
const { length } = keys;
|
|
4389
4656
|
if (length === 0) return omit ? value : {};
|
|
4390
4657
|
const partials = {};
|
|
@@ -4557,6 +4824,12 @@ function createMergingOptions(input) {
|
|
|
4557
4824
|
actual.skipNullableInArrays = options.skipNullableInArrays === true;
|
|
4558
4825
|
return actual;
|
|
4559
4826
|
}
|
|
4827
|
+
function getFullKey(prefix, key, options) {
|
|
4828
|
+
let full;
|
|
4829
|
+
if (options.replaceableObjects == null) full = void 0;
|
|
4830
|
+
else full = prefix == null ? key : `${prefix}.${key}`;
|
|
4831
|
+
return full;
|
|
4832
|
+
}
|
|
4560
4833
|
function getReplaceableObjects(value) {
|
|
4561
4834
|
const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
|
|
4562
4835
|
if (items.length === 0) return;
|
|
@@ -4584,6 +4857,9 @@ function initializeAssigner(options) {
|
|
|
4584
4857
|
function initializeMerger(options) {
|
|
4585
4858
|
return new Merger(createMergingOptions(options));
|
|
4586
4859
|
}
|
|
4860
|
+
function isMergeable(next, previous, options, full) {
|
|
4861
|
+
return isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false);
|
|
4862
|
+
}
|
|
4587
4863
|
/**
|
|
4588
4864
|
* Merge multiple arrays or objects into a single one
|
|
4589
4865
|
*
|
|
@@ -4610,9 +4886,9 @@ function mergeObjects(values, options, destination, prefix) {
|
|
|
4610
4886
|
const key = keys[innerIndex];
|
|
4611
4887
|
const next = item[key];
|
|
4612
4888
|
const previous = merged[key];
|
|
4613
|
-
if (next
|
|
4614
|
-
const
|
|
4615
|
-
if (
|
|
4889
|
+
if (skipMerge(next, options, isArray)) continue;
|
|
4890
|
+
const fullKey = getFullKey(prefix, key, options);
|
|
4891
|
+
if (isMergeable(next, previous, options, fullKey)) merged[key] = mergeObjects([previous, next], options, destination == null ? void 0 : merged[key], fullKey);
|
|
4616
4892
|
else merged[key] = next;
|
|
4617
4893
|
}
|
|
4618
4894
|
}
|
|
@@ -4624,7 +4900,11 @@ function mergeValues(values, options, prefix) {
|
|
|
4624
4900
|
if (actual.length === 0) return {};
|
|
4625
4901
|
if (options.assignValues && actual.length === 2 && !Array.isArray(actual[0]) && Object.keys(actual[0]).length === 0) return Object.assign(actual[0], actual[1]);
|
|
4626
4902
|
if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
|
|
4627
|
-
|
|
4903
|
+
if (options.assignValues) return actual[0];
|
|
4904
|
+
return Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
|
|
4905
|
+
}
|
|
4906
|
+
function skipMerge(next, options, isArray) {
|
|
4907
|
+
return next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays);
|
|
4628
4908
|
}
|
|
4629
4909
|
assign.initialize = initializeAssigner;
|
|
4630
4910
|
merge.initialize = initializeMerger;
|
|
@@ -4805,7 +5085,7 @@ function createSubscriptionsProperty(input) {
|
|
|
4805
5085
|
const values = isPlainObject(input) ? input : {};
|
|
4806
5086
|
return {
|
|
4807
5087
|
key: typeof values.key === "string" ? values.key : SUBSCRIPTION_PROPERTY,
|
|
4808
|
-
value: values.value
|
|
5088
|
+
value: values.value ?? "subscription"
|
|
4809
5089
|
};
|
|
4810
5090
|
}
|
|
4811
5091
|
function createSubscriptionsState(property, keys) {
|
|
@@ -5340,7 +5620,8 @@ function setColorAlpha(value) {
|
|
|
5340
5620
|
//#endregion
|
|
5341
5621
|
//#region src/color/misc/get.ts
|
|
5342
5622
|
function getClampedValue(value, minimum, maximum, rounding) {
|
|
5343
|
-
|
|
5623
|
+
if (typeof value !== "number" || Number.isNaN(value)) return minimum;
|
|
5624
|
+
return clamp(rounding ?? false ? round(value) : value, minimum, maximum);
|
|
5344
5625
|
}
|
|
5345
5626
|
function getForegroundColor(value, hex) {
|
|
5346
5627
|
const { blue, green, red } = getColorFromState(getColorState(value), COLOR_TYPE.rgb);
|
|
@@ -5846,9 +6127,17 @@ function getHexaColor$1() {
|
|
|
5846
6127
|
* @param value Value to normalize
|
|
5847
6128
|
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
5848
6129
|
* @returns Normalized hex color
|
|
6130
|
+
*
|
|
6131
|
+
* @example
|
|
6132
|
+
* ```typescript
|
|
6133
|
+
* getNormalizedHex('#abc'); // => '#aabbcc'
|
|
6134
|
+
* getNormalizedHex('#abc', true); // => '#aabbccff'
|
|
6135
|
+
* getNormalizedHex(123); // => '#000000'
|
|
6136
|
+
* getNormalizedHex(123, true); // => '#000000ff'
|
|
6137
|
+
* ```
|
|
5849
6138
|
*/
|
|
5850
6139
|
function getNormalizedHex(value, alpha) {
|
|
5851
|
-
const includeAlpha = alpha
|
|
6140
|
+
const includeAlpha = alpha === true;
|
|
5852
6141
|
if (!isHexColor(value)) return `${COLOR_DEFAULTS.hexBlack}${includeAlpha ? COLOR_ALPHA.fullHexLong : ""}`;
|
|
5853
6142
|
const normalized = value.replace(COLOR_EXPRESSION.prefix, "");
|
|
5854
6143
|
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)));
|
|
@@ -6620,12 +6909,24 @@ function getTimeLoggerStop() {
|
|
|
6620
6909
|
}
|
|
6621
6910
|
return noop;
|
|
6622
6911
|
}
|
|
6912
|
+
/**
|
|
6913
|
+
* Is the value a _Logger_?
|
|
6914
|
+
*
|
|
6915
|
+
* @param value Value to check
|
|
6916
|
+
* @returns `true` if the value is a _Logger_, otherwise `false`
|
|
6917
|
+
*/
|
|
6623
6918
|
function isLogger(value) {
|
|
6624
6919
|
return isLoggerInstance(LOGGER_NAME, value);
|
|
6625
6920
|
}
|
|
6626
6921
|
function isLoggerInstance(name, value) {
|
|
6627
6922
|
return typeof value === "object" && value !== null && "$logger" in value && value["$logger"] === name;
|
|
6628
6923
|
}
|
|
6924
|
+
/**
|
|
6925
|
+
* Is the value a _TimeLogger_?
|
|
6926
|
+
*
|
|
6927
|
+
* @param value Value to check
|
|
6928
|
+
* @returns `true` if the value is a _TimeLogger_, otherwise `false`
|
|
6929
|
+
*/
|
|
6629
6930
|
function isTimeLogger(value) {
|
|
6630
6931
|
return isLoggerInstance(LOGGER_NAME_TIMED, value);
|
|
6631
6932
|
}
|
|
@@ -6651,6 +6952,13 @@ function average(array, key) {
|
|
|
6651
6952
|
* @param value Number to round up
|
|
6652
6953
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
6653
6954
|
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
6955
|
+
*
|
|
6956
|
+
* @example
|
|
6957
|
+
* ```typescript
|
|
6958
|
+
* ceil(1.234, 2); // => 1.24
|
|
6959
|
+
* ceil(1.234); // => 2
|
|
6960
|
+
* ceil('abc'); // => Number.NaN
|
|
6961
|
+
* ```
|
|
6654
6962
|
*/
|
|
6655
6963
|
function ceil(value, decimals) {
|
|
6656
6964
|
return roundNumber(Math.ceil, value, decimals);
|
|
@@ -7128,14 +7436,13 @@ async function run$1(state) {
|
|
|
7128
7436
|
state.runners += 1;
|
|
7129
7437
|
let item = state.items.shift();
|
|
7130
7438
|
while (item != null) {
|
|
7439
|
+
const next = item;
|
|
7131
7440
|
let error = false;
|
|
7132
7441
|
let result;
|
|
7133
7442
|
const attempted = await asyncAttempt(async () => {
|
|
7134
|
-
if (
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
}
|
|
7138
|
-
throw new Error();
|
|
7443
|
+
if (next.aborter?.signal?.aborted) throw next.aborter.signal.reason;
|
|
7444
|
+
const parameters = next.key == null ? next.parameters : [next.key, ...next.parameters];
|
|
7445
|
+
return await state.callback(...parameters);
|
|
7139
7446
|
});
|
|
7140
7447
|
if (attempted.ok) result = attempted.value;
|
|
7141
7448
|
else {
|
|
@@ -7166,7 +7473,7 @@ const RANDOM_HEX_CHARACTERS = "0123456789ABCDEF";
|
|
|
7166
7473
|
* @returns Random boolean
|
|
7167
7474
|
*/
|
|
7168
7475
|
function getRandomBoolean() {
|
|
7169
|
-
return
|
|
7476
|
+
return getRandom() > RANDOM_BOOLEAN_MODIFIER;
|
|
7170
7477
|
}
|
|
7171
7478
|
/**
|
|
7172
7479
|
* Get a random string of characters with a specified length
|
|
@@ -7271,4 +7578,4 @@ var SizedSet = class extends Set {
|
|
|
7271
7578
|
}
|
|
7272
7579
|
};
|
|
7273
7580
|
//#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,
|
|
7581
|
+
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, filterAndFlatMap, filterAndMap, filterAndMap as select, find, findLast, first, firstOrDefault, flatFreeze, flatMapAndFilter, 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, 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 };
|