@oscarpalmer/atoms 0.216.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/array/swap.d.mts +2 -1
- package/dist/color/constants.d.mts +2 -1
- package/dist/color/misc/get.mjs +3 -1
- package/dist/color/space/hex.mjs +1 -1
- package/dist/color/space/rgb.d.mts +1 -0
- package/dist/function/index.mjs +1 -2
- package/dist/function/retry.d.mts +1 -1
- package/dist/function/retry.mjs +5 -2
- package/dist/herald.mjs +1 -2
- package/dist/index.d.mts +335 -113
- package/dist/index.mjs +483 -241
- 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/index.d.mts +7 -0
- package/dist/internal/plan/index.mjs +18 -0
- package/dist/{plan/generate.d.mts → internal/plan/plan.generate.d.mts} +2 -2
- package/dist/{plan/generate.mjs → internal/plan/plan.generate.mjs} +7 -7
- 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/color.model.d.mts +2 -1
- package/dist/models/function/once.model.d.mts +2 -1
- package/dist/models/index.d.mts +2 -1
- package/dist/models/plan.model.d.mts +160 -29
- package/dist/models/plan.model.mjs +15 -5
- package/dist/models/queue.model.d.mts +2 -1
- package/dist/models/result.model.d.mts +2 -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.equal.model.d.mts +2 -1
- package/dist/models/value/value.merge.model.d.mts +3 -2
- package/dist/models/value/value.misc.model.d.mts +2 -1
- package/dist/number.mjs +1 -2
- package/dist/plan/index.d.mts +1 -4
- package/dist/plan/index.mjs +14 -15
- package/dist/plan/is.d.mts +59 -3
- package/dist/plan/is.mjs +82 -10
- package/dist/plan/misc.d.mts +51 -3
- package/dist/plan/misc.mjs +47 -30
- package/dist/plan/models.d.mts +2 -2
- package/dist/plan/result.d.mts +15 -3
- package/dist/plan/result.mjs +5 -11
- package/dist/plan/run.d.mts +1 -3
- package/dist/plan/run.mjs +5 -11
- package/dist/plan/use.d.mts +36 -0
- package/dist/plan/use.mjs +69 -0
- 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/models.mjs +1 -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/index.mjs +1 -2
- package/dist/result/match.mjs +2 -2
- package/dist/result/misc.mjs +3 -10
- package/dist/result/work/pipe.d.mts +26 -23
- package/dist/result/work/pipe.mjs +7 -3
- package/dist/string/fuzzy.mjs +1 -1
- package/dist/string/index.mjs +1 -1
- package/dist/subscription.mjs +1 -2
- package/dist/value/clone.mjs +1 -1
- package/dist/value/merge.mjs +17 -4
- package/package.json +8 -10
|
@@ -9,15 +9,47 @@ function createFindParameters(original) {
|
|
|
9
9
|
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
function findComplexValues(parameters) {
|
|
13
|
+
const { array, keyCallback, length, mapAfter, mapBefore, result, type, value } = parameters;
|
|
14
|
+
const keys = /* @__PURE__ */ new Set();
|
|
15
|
+
for (let index = 0; index < length; index += 1) {
|
|
16
|
+
const item = array[index];
|
|
17
|
+
let keyed;
|
|
18
|
+
let transformed;
|
|
19
|
+
if (mapBefore == null) {
|
|
20
|
+
keyed = keyCallback?.(item, index, array) ?? item;
|
|
21
|
+
transformed = item;
|
|
22
|
+
} else {
|
|
23
|
+
transformed = mapBefore(item, index, array);
|
|
24
|
+
keyed = keyCallback?.(transformed, index, array) ?? transformed;
|
|
25
|
+
}
|
|
26
|
+
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
27
|
+
keys.add(keyed);
|
|
28
|
+
result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
29
|
+
} else result.notMatched.push(item);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
function findSimpleValue(array, value, findIndex, reversed) {
|
|
34
|
+
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
35
|
+
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
36
|
+
}
|
|
37
|
+
function findSimpleValues(array, length, value, boolCallback, mapBefore, mapAfter, result) {
|
|
38
|
+
const callback = boolCallback ?? ((item) => Object.is(item, value));
|
|
39
|
+
for (let index = 0; index < length; index += 1) {
|
|
40
|
+
const item = array[index];
|
|
41
|
+
const transformed = mapBefore?.(item, index, array) ?? item;
|
|
42
|
+
if (callback(transformed, index, array)) result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
43
|
+
else result.notMatched.push(item);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
12
47
|
function findValue(type, array, parameters, reversed) {
|
|
13
48
|
const findIndex = type === ARRAY_FIND_VALUE_INDEX;
|
|
14
49
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
15
50
|
const { bool, key, value } = createFindParameters(parameters);
|
|
16
51
|
const callbacks = getArrayCallbacks(bool, key);
|
|
17
|
-
if (callbacks?.bool == null && callbacks?.keyed == null)
|
|
18
|
-
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
19
|
-
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
20
|
-
}
|
|
52
|
+
if (callbacks?.bool == null && callbacks?.keyed == null) return findSimpleValue(array, value, findIndex, reversed);
|
|
21
53
|
if (callbacks.bool != null) {
|
|
22
54
|
const index = reversed ? array.findLastIndex(callbacks.bool) : array.findIndex(callbacks.bool);
|
|
23
55
|
return findIndex ? index : array[index];
|
|
@@ -38,7 +70,8 @@ function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultV
|
|
|
38
70
|
return useDefaultValue ? defaultValue : void 0;
|
|
39
71
|
}
|
|
40
72
|
const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
|
|
41
|
-
|
|
73
|
+
if (index === -1) return useDefaultValue ? defaultValue : void 0;
|
|
74
|
+
return array[index];
|
|
42
75
|
}
|
|
43
76
|
function findValues(type, array, parameters, mapper) {
|
|
44
77
|
const result = {
|
|
@@ -55,36 +88,26 @@ function findValues(type, array, parameters, mapper) {
|
|
|
55
88
|
}
|
|
56
89
|
const mapCallback = getArrayCallback(mapper?.callback);
|
|
57
90
|
const mapReverse = mapper?.reverse ?? false;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
else result.notMatched.push(item);
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
91
|
+
let mapAfter;
|
|
92
|
+
let mapBefore;
|
|
93
|
+
if (mapCallback == null) {
|
|
94
|
+
mapAfter = void 0;
|
|
95
|
+
mapBefore = void 0;
|
|
96
|
+
} else {
|
|
97
|
+
mapAfter = mapReverse ? void 0 : mapCallback;
|
|
98
|
+
mapBefore = mapReverse ? mapCallback : void 0;
|
|
69
99
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
83
|
-
keys.add(keyed);
|
|
84
|
-
result.matched.push(mapAfter?.(item, index, array) ?? transformed);
|
|
85
|
-
} else result.notMatched.push(item);
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
100
|
+
if (callbacks?.bool != null || type === "all" && key == null) return findSimpleValues(array, length, value, callbacks?.bool, mapBefore, mapAfter, result);
|
|
101
|
+
return findComplexValues({
|
|
102
|
+
array,
|
|
103
|
+
length,
|
|
104
|
+
mapAfter,
|
|
105
|
+
mapBefore,
|
|
106
|
+
result,
|
|
107
|
+
type,
|
|
108
|
+
value,
|
|
109
|
+
keyCallback: callbacks?.keyed
|
|
110
|
+
});
|
|
88
111
|
}
|
|
89
112
|
//#endregion
|
|
90
113
|
export { createFindParameters, findAbsoluteValueOrDefault, findValue, findValues };
|
|
@@ -3,7 +3,7 @@ import { chunk } from "./chunk.mjs";
|
|
|
3
3
|
import { max, min } from "../math/aggregate.mjs";
|
|
4
4
|
//#region src/internal/array/insert.ts
|
|
5
5
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
6
|
-
const actualDeleteCount = deleteCount
|
|
6
|
+
const actualDeleteCount = max([deleteCount, 0]);
|
|
7
7
|
const actualStart = min([max([0, start]), array.length]);
|
|
8
8
|
const chunked = chunk(items);
|
|
9
9
|
const lastIndex = chunked.length - 1;
|
|
@@ -4,6 +4,21 @@ import { ARRAY_MATCH_COMPARISON_INSIDE, ARRAY_MATCH_COMPARISON_SAME, ARRAY_MATCH
|
|
|
4
4
|
function endsWithArray(haystack, needle, key) {
|
|
5
5
|
return arrayMatchEndings.has(getPosition(haystack, needle, key)[1]);
|
|
6
6
|
}
|
|
7
|
+
function evaluatePosition(haystack, haystackLength, needle, needleLength, key) {
|
|
8
|
+
const callback = getArrayCallback(key);
|
|
9
|
+
const limit = haystackLength - needleLength + 1;
|
|
10
|
+
let needleValues = callback == null ? needle : needle.slice();
|
|
11
|
+
if (callback != null) for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) needleValues[needleIndex] = callback(needle[needleIndex], needleIndex, needle);
|
|
12
|
+
for (let haystackIndex = 0; haystackIndex < limit; haystackIndex += 1) {
|
|
13
|
+
if (!inHaystack(haystack, haystackIndex, needleValues, 0, callback)) continue;
|
|
14
|
+
if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
15
|
+
for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
|
|
16
|
+
if (!inHaystack(haystack, haystackIndex, needleValues, needleIndex, callback)) break;
|
|
17
|
+
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return arrayMatchOutside;
|
|
21
|
+
}
|
|
7
22
|
function getArrayComparison(haystack, needle, key) {
|
|
8
23
|
return getPosition(haystack, needle, key)[1];
|
|
9
24
|
}
|
|
@@ -17,23 +32,12 @@ function getPosition(haystack, needle, key) {
|
|
|
17
32
|
const needleLength = needle.length;
|
|
18
33
|
if (haystackLength === 0 || needleLength === 0) return arrayMatchOutside;
|
|
19
34
|
if (needleLength > haystackLength) return arrayMatchOutside;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let haystackValue = callback?.(haystackItem, haystackIndex, haystack) ?? haystackItem;
|
|
27
|
-
if (!Object.is(haystackValue, needleValues[0])) continue;
|
|
28
|
-
if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
29
|
-
for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
|
|
30
|
-
haystackItem = haystack[haystackIndex + needleIndex];
|
|
31
|
-
haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
|
|
32
|
-
if (!Object.is(haystackValue, needleValues[needleIndex])) break;
|
|
33
|
-
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return arrayMatchOutside;
|
|
35
|
+
return evaluatePosition(haystack, haystackLength, needle, needleLength, key);
|
|
36
|
+
}
|
|
37
|
+
function inHaystack(haystack, haystackIndex, needleValues, needleIndex, callback) {
|
|
38
|
+
const haystackItem = haystack[haystackIndex + needleIndex];
|
|
39
|
+
const haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
|
|
40
|
+
return Object.is(haystackValue, needleValues[needleIndex]);
|
|
37
41
|
}
|
|
38
42
|
function includesArray(haystack, needle, key) {
|
|
39
43
|
return !arrayMatchOutsides.has(getPosition(haystack, needle, key)[1]);
|
|
@@ -6,8 +6,14 @@ function compareSets(type, first, second, key) {
|
|
|
6
6
|
const isDifference = type === ARRAY_SETS_COMPARE_DIFFERENCE;
|
|
7
7
|
const isIntersection = type === ARRAY_SETS_COMPARE_INTERSECTION;
|
|
8
8
|
const isUnion = type === ARRAY_SETS_COMPARE_UNION;
|
|
9
|
-
if (first.length === 0)
|
|
9
|
+
if (first.length === 0) {
|
|
10
|
+
if (isDifference) return first.slice();
|
|
11
|
+
return isIntersection ? [] : second.slice();
|
|
12
|
+
}
|
|
10
13
|
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : first.slice();
|
|
14
|
+
return getComparison(first, second, isIntersection, isUnion, key);
|
|
15
|
+
}
|
|
16
|
+
function getComparison(first, second, isIntersection, isUnion, key) {
|
|
11
17
|
const callback = getArrayCallback(key);
|
|
12
18
|
const values = isUnion ? first : second;
|
|
13
19
|
let { length } = values;
|
|
@@ -44,7 +44,10 @@ function getAggregateCallback(key) {
|
|
|
44
44
|
}
|
|
45
45
|
function getAggregated(type, array, key, first) {
|
|
46
46
|
const aggregation = aggregate(type, array, key, first);
|
|
47
|
-
if (aggregation.count === 0)
|
|
47
|
+
if (aggregation.count === 0) {
|
|
48
|
+
if (aggregation.array) return aggregation.first ? void 0 : [];
|
|
49
|
+
return NaN;
|
|
50
|
+
}
|
|
48
51
|
if (aggregation.array) {
|
|
49
52
|
const array = aggregation.items[aggregation.value];
|
|
50
53
|
return aggregation.first ? array[0] : array;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param value Value to check
|
|
6
6
|
* @param minimum Minimum value
|
|
7
|
-
* @param maximum Maximum value
|
|
7
|
+
* @param maximum Maximum value _(inclusive)_
|
|
8
8
|
* @returns `true` if the value is between the minimum and maximum, otherwise `false`
|
|
9
9
|
*/
|
|
10
10
|
export declare function between(value: number, minimum: number, maximum: number): boolean;
|
package/dist/internal/number.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isNumber } from "./is.mjs";
|
|
2
|
+
import { max, min } from "./math/aggregate.mjs";
|
|
2
3
|
import { EXPRESSION_NUMBER_BINARY, EXPRESSION_NUMBER_OCTAL, EXPRESSION_NUMBER_ZEROISH } from "../models/misc.model.mjs";
|
|
3
4
|
//#region src/internal/number.ts
|
|
4
5
|
/**
|
|
@@ -6,7 +7,7 @@ import { EXPRESSION_NUMBER_BINARY, EXPRESSION_NUMBER_OCTAL, EXPRESSION_NUMBER_ZE
|
|
|
6
7
|
*
|
|
7
8
|
* @param value Value to check
|
|
8
9
|
* @param minimum Minimum value
|
|
9
|
-
* @param maximum Maximum value
|
|
10
|
+
* @param maximum Maximum value _(inclusive)_
|
|
10
11
|
* @returns `true` if the value is between the minimum and maximum, otherwise `false`
|
|
11
12
|
*/
|
|
12
13
|
function between(value, minimum, maximum) {
|
|
@@ -16,7 +17,8 @@ function between(value, minimum, maximum) {
|
|
|
16
17
|
maximum
|
|
17
18
|
].every(isNumber)) return false;
|
|
18
19
|
if (Object.is(minimum, maximum)) return Object.is(value, minimum);
|
|
19
|
-
|
|
20
|
+
const maximumValue = max([maximum, minimum]);
|
|
21
|
+
return value >= min([maximum, minimum]) && value <= maximumValue;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Clamp a number between a minimum and maximum value
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GenericPlanItem, InternalAsyncPlan, InternalPlan } from "../../models/plan.model.mjs";
|
|
2
|
+
//#region src/internal/plan/index.d.ts
|
|
3
|
+
export declare function attemptRunPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
4
|
+
export declare function getGenerator(this: GenericPlanItem): AsyncGenerator | Generator;
|
|
5
|
+
export declare function runAsyncPlan(this: InternalAsyncPlan, first: never, second: never): Promise<unknown>;
|
|
6
|
+
export declare function runPlan(this: InternalPlan, ...parameters: unknown[]): unknown;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { attempt } from "../result/attempt.mjs";
|
|
2
|
+
import { PLAN_SYMBOL } from "../../models/plan.model.mjs";
|
|
3
|
+
import { asyncGenerate, generate } from "./plan.generate.mjs";
|
|
4
|
+
//#region src/internal/plan/index.ts
|
|
5
|
+
function attemptRunPlan(...parameters) {
|
|
6
|
+
return attempt(() => generate(this[PLAN_SYMBOL], parameters, true));
|
|
7
|
+
}
|
|
8
|
+
function getGenerator() {
|
|
9
|
+
return this[PLAN_SYMBOL].generator();
|
|
10
|
+
}
|
|
11
|
+
function runAsyncPlan(first, second) {
|
|
12
|
+
return asyncGenerate(this[PLAN_SYMBOL], false, first, second);
|
|
13
|
+
}
|
|
14
|
+
function runPlan(...parameters) {
|
|
15
|
+
return generate(this[PLAN_SYMBOL], parameters, false);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { attemptRunPlan, getGenerator, runAsyncPlan, runPlan };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AsyncPlanState, PlanState } from "
|
|
2
|
-
//#region src/plan/generate.d.ts
|
|
1
|
+
import { AsyncPlanState, PlanState } from "../../models/plan.model.mjs";
|
|
2
|
+
//#region src/internal/plan/plan.generate.d.ts
|
|
3
3
|
export declare function asyncGenerate(input: AsyncPlanState | ((...args: unknown[]) => AsyncGenerator), unwrap: boolean, first?: unknown, second?: unknown): Promise<unknown>;
|
|
4
4
|
export declare function generate(input: PlanState | ((...parameters: unknown[]) => Generator), parameters: unknown[], unwrap: boolean): unknown;
|
|
5
5
|
//#endregion
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { noop } from "../
|
|
2
|
-
import { createAborter } from "../
|
|
3
|
-
import { isError, isOk } from "../
|
|
4
|
-
//#region src/plan/generate.ts
|
|
1
|
+
import { noop } from "../function/misc.mjs";
|
|
2
|
+
import { createAborter } from "../aborter.mjs";
|
|
3
|
+
import { isError, isOk } from "../result/misc.mjs";
|
|
4
|
+
//#region src/internal/plan/plan.generate.ts
|
|
5
5
|
async function asyncGenerate(input, unwrap, first, second) {
|
|
6
6
|
const aborter = createAborter(second ?? first, noop);
|
|
7
|
-
if (aborter
|
|
7
|
+
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
8
8
|
const parameters = Array.isArray(first) ? first : [];
|
|
9
9
|
let generator;
|
|
10
10
|
if (typeof input === "function") generator = input(...parameters);
|
|
@@ -13,7 +13,7 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
13
13
|
let lastValue;
|
|
14
14
|
try {
|
|
15
15
|
while (true) {
|
|
16
|
-
if (aborter
|
|
16
|
+
if (aborter?.signal.aborted) await generator.throw(aborter.signal.reason);
|
|
17
17
|
const next = await generator.next(lastValue);
|
|
18
18
|
const done = next.done === true;
|
|
19
19
|
const { value } = next;
|
|
@@ -29,7 +29,7 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
29
29
|
aborter?.cancel();
|
|
30
30
|
await generator.return(lastValue);
|
|
31
31
|
}
|
|
32
|
-
if (aborter
|
|
32
|
+
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
33
33
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
34
34
|
throw lastValue;
|
|
35
35
|
}
|
package/dist/internal/random.mjs
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { isNumber } from "./is.mjs";
|
|
2
2
|
import { floor } from "./math/misc.mjs";
|
|
3
3
|
//#region src/internal/random.ts
|
|
4
|
+
/**
|
|
5
|
+
* Get a random number between 0 _(inclusive)_ and 1 _(exclusive)_
|
|
6
|
+
*
|
|
7
|
+
* @returns Random number
|
|
8
|
+
*/
|
|
9
|
+
function getRandom() {
|
|
10
|
+
/* istanbul ignore if */
|
|
11
|
+
if (globalThis.crypto == null) return Math.random();
|
|
12
|
+
return globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] / RANDOM_DIVISOR;
|
|
13
|
+
}
|
|
4
14
|
function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
|
|
5
15
|
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
6
16
|
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
7
17
|
if (minFloat === maxFloat) return minFloat;
|
|
8
18
|
if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
|
|
9
|
-
return
|
|
19
|
+
return getRandom() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
|
|
10
20
|
}
|
|
11
21
|
/**
|
|
12
22
|
* Get a random floating-point number
|
|
@@ -28,5 +38,6 @@ function getRandomFloatingNumber(minimum, maximum) {
|
|
|
28
38
|
function getRandomInteger(minimum, maximum) {
|
|
29
39
|
return floor(getRandomFloatingNumberValue(true, minimum, maximum));
|
|
30
40
|
}
|
|
41
|
+
const RANDOM_DIVISOR = 2 ** 32;
|
|
31
42
|
//#endregion
|
|
32
|
-
export { getRandomFloatingNumber, getRandomInteger };
|
|
43
|
+
export { getRandom, getRandomFloatingNumber, getRandomInteger };
|
|
@@ -7,16 +7,16 @@ async function asyncAttempt(value, err) {
|
|
|
7
7
|
else result = value;
|
|
8
8
|
if (result instanceof Promise) result = await result;
|
|
9
9
|
return ok(result);
|
|
10
|
-
} catch (
|
|
11
|
-
return getError(err ??
|
|
10
|
+
} catch (error) {
|
|
11
|
+
return getError(err ?? error, err == null ? void 0 : error);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
function attempt(callback, err) {
|
|
15
15
|
try {
|
|
16
16
|
const value = callback();
|
|
17
17
|
return ok(value);
|
|
18
|
-
} catch (
|
|
19
|
-
return getError(err ??
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return getError(err ?? error, err == null ? void 0 : error);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
attempt.async = asyncAttempt;
|
|
@@ -75,7 +75,8 @@ function tryEncode(value) {
|
|
|
75
75
|
* @returns Array of words found in the string
|
|
76
76
|
*/
|
|
77
77
|
function words(value) {
|
|
78
|
-
|
|
78
|
+
if (typeof value === "string") return value.match(STRING_EXPRESSION_WORDS) ?? [];
|
|
79
|
+
return [];
|
|
79
80
|
}
|
|
80
81
|
//#endregion
|
|
81
82
|
export { getString, ignoreKey, interpolate, join, tryDecode, tryEncode, words };
|
|
@@ -125,7 +125,7 @@ function createSubscriptionsProperty(input) {
|
|
|
125
125
|
const values = isPlainObject(input) ? input : {};
|
|
126
126
|
return {
|
|
127
127
|
key: typeof values.key === "string" ? values.key : SUBSCRIPTION_PROPERTY,
|
|
128
|
-
value: values.value
|
|
128
|
+
value: values.value ?? "subscription"
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
function createSubscriptionsState(property, keys) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isNonPlainObject, isPlainObject, isPrimitive, isTypedArray } from "../is.mjs";
|
|
2
2
|
import { round } from "../math/misc.mjs";
|
|
3
|
+
import { min } from "../math/aggregate.mjs";
|
|
3
4
|
import { createCompareHandler } from "./handlers.mjs";
|
|
4
5
|
import { EQUAL_ERROR_PROPERTIES, EQUAL_EXPRESSION_PROPERTIES, EQUAL_SYMBOL } from "../../models/value/value.equal.model.mjs";
|
|
5
6
|
//#region src/internal/value/equal.ts
|
|
@@ -63,7 +64,7 @@ function equalArray(first, second, options) {
|
|
|
63
64
|
let offset = 0;
|
|
64
65
|
if (length >= 100) {
|
|
65
66
|
offset = round(length / 10);
|
|
66
|
-
offset = offset
|
|
67
|
+
offset = min([offset, 100]);
|
|
67
68
|
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;
|
|
68
69
|
}
|
|
69
70
|
const end = length - offset;
|
|
@@ -2,7 +2,9 @@ import { isPlainObject } from "../is.mjs";
|
|
|
2
2
|
//#region src/internal/value/partial.ts
|
|
3
3
|
function partial(value, providedKeys, omit) {
|
|
4
4
|
if (!isPlainObject(value)) return {};
|
|
5
|
-
|
|
5
|
+
let keys;
|
|
6
|
+
if (omit) keys = Object.keys(value);
|
|
7
|
+
else keys = Array.isArray(providedKeys) ? providedKeys : [];
|
|
6
8
|
const { length } = keys;
|
|
7
9
|
if (length === 0) return omit ? value : {};
|
|
8
10
|
const partials = {};
|
|
@@ -73,4 +73,5 @@ export declare const ONCE_PROPERTY = "$once";
|
|
|
73
73
|
export declare const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
74
74
|
export declare const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
75
75
|
export declare const ONCE_SYMBOL: unique symbol;
|
|
76
|
-
//#endregion
|
|
76
|
+
//#endregion
|
|
77
|
+
export {};
|
package/dist/models/index.d.mts
CHANGED