@oscarpalmer/atoms 0.222.0 → 0.223.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/difference.mjs +1 -1
- package/dist/array/exists.mjs +10 -4
- package/dist/array/filter.mjs +14 -4
- package/dist/array/find.mjs +8 -3
- package/dist/array/first.mjs +9 -3
- package/dist/array/index.d.mts +4 -4
- package/dist/array/insert.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/last.mjs +11 -3
- package/dist/array/partition.mjs +23 -3
- package/dist/array/push.mjs +1 -1
- package/dist/array/select.mjs +39 -7
- package/dist/array/single.mjs +8 -5
- package/dist/array/sort.mjs +1 -1
- package/dist/array/splice.mjs +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unique.mjs +17 -3
- package/dist/beacon.d.mts +3 -11
- package/dist/beacon.mjs +10 -20
- package/dist/color/constants.d.mts +1 -5
- package/dist/color/constants.mjs +2 -9
- package/dist/color/index.mjs +3 -3
- package/dist/color/instance.mjs +4 -6
- package/dist/color/misc/get.mjs +1 -1
- package/dist/color/misc/is.d.mts +0 -8
- package/dist/color/misc/is.mjs +3 -14
- package/dist/color/misc/state.mjs +3 -3
- package/dist/color/space/hex.mjs +1 -1
- package/dist/color/space/hsl.mjs +1 -1
- package/dist/color/space/hwb.mjs +2 -2
- package/dist/function/limit.d.mts +1 -1
- package/dist/function/limit.mjs +1 -1
- package/dist/function/once.d.mts +1 -1
- package/dist/function/once.mjs +7 -7
- package/dist/function/retry.d.mts +1 -1
- package/dist/function/retry.mjs +10 -10
- package/dist/herald.d.mts +2 -2
- package/dist/herald.mjs +1 -1
- package/dist/index.d.mts +80 -91
- package/dist/index.mjs +352 -334
- package/dist/internal/array/callbacks.d.mts +1 -1
- package/dist/internal/array/find.d.mts +2 -6
- package/dist/internal/array/find.mjs +30 -122
- package/dist/internal/array/index-of.mjs +9 -3
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/match.d.mts +1 -1
- package/dist/internal/array/match.mjs +1 -1
- package/dist/internal/array/sets.mjs +4 -4
- package/dist/internal/function/assert.d.mts +1 -1
- package/dist/internal/function/limit.d.mts +1 -1
- package/dist/internal/function/limit.mjs +7 -7
- package/dist/internal/function/memoize.d.mts +1 -1
- package/dist/internal/function/memoize.mjs +3 -3
- package/dist/internal/function/work.d.mts +1 -1
- package/dist/internal/function/work.mjs +1 -1
- package/dist/internal/herald.d.mts +2 -10
- package/dist/internal/herald.mjs +8 -31
- package/dist/internal/math/aggregate.mjs +1 -1
- package/dist/internal/number.mjs +1 -1
- package/dist/internal/plan/index.mjs +1 -1
- package/dist/internal/plan/plan.generate.mjs +67 -21
- package/dist/internal/sized/map.d.mts +3 -0
- package/dist/internal/sized/map.mjs +3 -0
- package/dist/internal/string/case.mjs +2 -2
- package/dist/internal/string/misc.mjs +1 -1
- package/dist/internal/subscription.mjs +15 -27
- package/dist/internal/value/compare.mjs +1 -1
- package/dist/internal/value/equal.d.mts +1 -1
- package/dist/internal/value/equal.mjs +2 -2
- package/dist/internal/value/set.mjs +1 -1
- package/dist/is.mjs +1 -1
- package/dist/logger.mjs +6 -5
- package/dist/math.mjs +1 -1
- package/dist/models/array/array.misc.model.d.mts +12 -1
- package/dist/models/array/array.misc.model.mjs +2 -1
- package/dist/models/beacon.model.d.mts +4 -4
- package/dist/models/beacon.model.mjs +2 -8
- package/dist/models/color.model.d.mts +2 -2
- package/dist/models/function/limiter.model.d.mts +1 -1
- package/dist/models/function/limiter.model.mjs +1 -2
- package/dist/models/function/memoize.model.d.mts +1 -1
- package/dist/models/function/once.model.d.mts +0 -1
- package/dist/models/function/once.model.mjs +2 -3
- package/dist/models/function/work.model.d.mts +1 -1
- package/dist/models/herald.model.d.mts +8 -5
- package/dist/models/herald.model.mjs +2 -8
- package/dist/models/logger.model.d.mts +0 -1
- package/dist/models/logger.model.mjs +2 -3
- package/dist/models/plan.model.d.mts +35 -35
- package/dist/models/promise.model.d.mts +7 -7
- package/dist/models/promise.model.mjs +3 -3
- package/dist/models/queue.model.d.mts +0 -1
- package/dist/models/queue.model.mjs +2 -3
- package/dist/models/string/string.fuzzy.model.d.mts +0 -1
- package/dist/models/string/string.fuzzy.model.mjs +2 -3
- package/dist/models/subscription.model.d.mts +3 -20
- package/dist/models/subscription.model.mjs +2 -3
- package/dist/plan/index.mjs +1 -1
- package/dist/plan/misc.mjs +1 -1
- package/dist/plan/models.d.mts +2 -2
- package/dist/plan/result.d.mts +7 -7
- package/dist/plan/result.mjs +1 -1
- package/dist/plan/run.d.mts +7 -7
- package/dist/plan/run.mjs +1 -1
- package/dist/plan/use.mjs +13 -7
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.mjs +4 -4
- package/dist/promise/misc.d.mts +1 -1
- package/dist/promise/misc.mjs +1 -1
- package/dist/promise/models.d.mts +2 -2
- package/dist/promise/models.mjs +1 -1
- package/dist/promise/timed.mjs +3 -3
- package/dist/query.mjs +1 -1
- package/dist/queue.mjs +10 -10
- package/dist/random.mjs +1 -1
- package/dist/result/work/flow.mjs +1 -1
- package/dist/result/work/pipe.mjs +1 -1
- package/dist/sized/set.d.mts +3 -0
- package/dist/sized/set.mjs +3 -0
- package/dist/string/fuzzy.mjs +4 -5
- package/dist/string/index.mjs +1 -1
- package/dist/string/match.mjs +1 -1
- package/dist/string/normalize.mjs +2 -2
- package/dist/subscription.d.mts +2 -2
- package/dist/value/clone.d.mts +1 -1
- package/dist/value/clone.mjs +1 -1
- package/dist/value/freeze.mjs +1 -1
- package/dist/value/handle.mjs +1 -1
- package/dist/value/smush.mjs +1 -1
- package/package.json +6 -6
- package/dist/models/array/array.find.model.d.mts +0 -46
- package/dist/models/array/array.find.model.mjs +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericCallback } from "../../models/index.mjs";
|
|
2
1
|
import { ArrayGetCallbacks } from "../../models/array/array.misc.model.mjs";
|
|
2
|
+
import { GenericCallback } from "../../models/index.mjs";
|
|
3
3
|
export declare function getArrayCallback(value: unknown): GenericCallback | undefined;
|
|
4
4
|
export declare function getArrayCallbacks(bool?: unknown, key?: unknown, value?: unknown): ArrayGetCallbacks | undefined;
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
|
|
4
|
-
export declare function findValue(type: Exclude<ArrayFindValueType, "item">, array: unknown[], parameters: unknown[], reversed: boolean): number;
|
|
5
|
-
export declare function findValue(type: Exclude<ArrayFindValueType, "index">, array: unknown[], parameters: unknown[], reversed: boolean): unknown;
|
|
6
|
-
export declare function findValues(type: ArrayFindValuesType, array: unknown[], parameters: unknown[], options?: ArrayFindOptions): ArrayFindValuesResult;
|
|
1
|
+
import { ArrayFindParameters, ArrayFindResult } from "../../models/array/array.misc.model.mjs";
|
|
2
|
+
export declare function findValue(array: unknown[], parameters: ArrayFindParameters): ArrayFindResult | undefined;
|
|
@@ -1,131 +1,39 @@
|
|
|
1
|
-
import { ARRAY_FIND_VALUE_INDEX } from "../../models/array/array.find.model.mjs";
|
|
2
|
-
import { getArrayCallback, getArrayCallbacks } from "./callbacks.mjs";
|
|
3
1
|
// src/internal/array/find.ts
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
function createFindParameters(original) {
|
|
14
|
-
const { length } = original;
|
|
15
|
-
return {
|
|
16
|
-
bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
|
|
17
|
-
key: length === 2 ? original[0] : void 0,
|
|
18
|
-
value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultValue, reversed) {
|
|
22
|
-
if (parameters.length === 0) {
|
|
23
|
-
if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
|
|
24
|
-
return useDefaultValue ? defaultValue : void 0;
|
|
25
|
-
}
|
|
26
|
-
const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
|
|
27
|
-
if (index === -1) return useDefaultValue ? defaultValue : void 0;
|
|
28
|
-
return array[index];
|
|
29
|
-
}
|
|
30
|
-
function findComplexValues(parameters) {
|
|
31
|
-
const { array, arrayLength, callback, limit, result, type, value } = parameters;
|
|
32
|
-
const keys = /* @__PURE__ */ new Set();
|
|
33
|
-
for (let arrayIndex = 0; arrayIndex < arrayLength; arrayIndex += 1) {
|
|
34
|
-
const arrayItem = array[arrayIndex];
|
|
35
|
-
const keyed = callback == null ? arrayItem : callback(arrayItem, arrayIndex, array);
|
|
36
|
-
const mapped = arrayItem;
|
|
37
|
-
if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
|
|
38
|
-
keys.add(keyed);
|
|
39
|
-
result.matched.push(mapped);
|
|
40
|
-
if (result.matched.length >= limit) return result;
|
|
41
|
-
} else result.notMatched.push(arrayItem);
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
function findSimpleValue(array, value, findIndex, reversed) {
|
|
46
|
-
if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
|
|
47
|
-
return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
|
|
48
|
-
}
|
|
49
|
-
function findSimpleValues(parameters) {
|
|
50
|
-
const { array, arrayLength, callback, flat, limit, map, result, value } = parameters;
|
|
51
|
-
const { after, before } = map ?? {};
|
|
52
|
-
const handler = callback ?? ((item) => Object.is(item, value));
|
|
53
|
-
for (let arrayIndex = 0; arrayIndex < arrayLength; arrayIndex += 1) {
|
|
54
|
-
const arrayItem = array[arrayIndex];
|
|
55
|
-
let mapped = before == null ? arrayItem : before(arrayItem, arrayIndex, array);
|
|
56
|
-
if (!flat || after != null) {
|
|
57
|
-
if (handler(mapped, arrayIndex, array)) {
|
|
58
|
-
mapped = after == null ? mapped : after(arrayItem, arrayIndex, array);
|
|
59
|
-
addResult(result, mapped, flat);
|
|
60
|
-
if (result.matched.length >= limit) return result;
|
|
61
|
-
} else result.notMatched.push(arrayItem);
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const flatItems = Array.isArray(mapped) ? mapped : [mapped];
|
|
65
|
-
const flatLength = flatItems.length;
|
|
66
|
-
for (let flatIndex = 0; flatIndex < flatLength; flatIndex += 1) {
|
|
67
|
-
const flatItem = flatItems[flatIndex];
|
|
68
|
-
if (handler(flatItem, arrayIndex, array)) result.matched.push(flatItem);
|
|
69
|
-
else result.notMatched.push(flatItem);
|
|
70
|
-
}
|
|
2
|
+
function findComplexValues(array, length, parameters, callback) {
|
|
3
|
+
let result;
|
|
4
|
+
for (let index = 0; index < length; index += 1) {
|
|
5
|
+
const item = array[parameters.reverse ? length - 1 - index : index];
|
|
6
|
+
if (!callback(item, index, array)) continue;
|
|
7
|
+
result ??= { values: [] };
|
|
8
|
+
result.values.push(parameters.indiced ? index : item);
|
|
9
|
+
if (parameters.limit == null || result.values.length === parameters.limit) return result;
|
|
71
10
|
}
|
|
72
11
|
return result;
|
|
73
12
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
77
|
-
const { bool, key, value } = createFindParameters(parameters);
|
|
78
|
-
const callbacks = getArrayCallbacks(bool, key);
|
|
79
|
-
if (callbacks?.bool == null && callbacks?.keyed == null) return findSimpleValue(array, value, findIndex, reversed);
|
|
80
|
-
if (callbacks.bool != null) {
|
|
81
|
-
const index = reversed ? array.findLastIndex(callbacks.bool) : array.findIndex(callbacks.bool);
|
|
82
|
-
return findIndex ? index : array[index];
|
|
83
|
-
}
|
|
84
|
-
return findValueInArray(array, callbacks.keyed, value, findIndex, reversed);
|
|
13
|
+
function findBareValue(array, reverse) {
|
|
14
|
+
return { values: [array[reverse ? array.length - 1 : 0]] };
|
|
85
15
|
}
|
|
86
|
-
function
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (Object.is(callback?.(item, index, array), value)) return findIndex ? index : item;
|
|
91
|
-
}
|
|
92
|
-
return findIndex ? -1 : void 0;
|
|
16
|
+
function findSimpleValue(array, first, indiced, reverse) {
|
|
17
|
+
const method = reverse ? "findLastIndex" : "findIndex";
|
|
18
|
+
const index = typeof first === "function" ? array[method](first) : array[method]((item) => Object.is(item, first));
|
|
19
|
+
return index === -1 ? void 0 : { values: [indiced ? index : array[index]] };
|
|
93
20
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
matched: [],
|
|
97
|
-
notMatched: []
|
|
98
|
-
};
|
|
99
|
-
if (!Array.isArray(array)) return result;
|
|
21
|
+
function findValue(array, parameters) {
|
|
22
|
+
if (!Array.isArray(array)) return;
|
|
100
23
|
const arrayLength = array.length;
|
|
101
|
-
if (arrayLength === 0) return
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
24
|
+
if (arrayLength === 0) return;
|
|
25
|
+
const inputLength = parameters.input.length;
|
|
26
|
+
if (inputLength === 0 && parameters.bare) return findBareValue(array, parameters.reverse ?? false);
|
|
27
|
+
const [first, second] = parameters.input;
|
|
28
|
+
if (inputLength === 1 && !parameters.limit) return findSimpleValue(array, first, parameters.indiced ?? false, parameters.reverse ?? false);
|
|
29
|
+
const callback = inputLength === 1 && typeof first === "function" ? first : getCallback(first, second);
|
|
30
|
+
return callback == null ? void 0 : findComplexValues(array, arrayLength, parameters, callback);
|
|
31
|
+
}
|
|
32
|
+
function getCallback(first, second) {
|
|
33
|
+
switch (true) {
|
|
34
|
+
case typeof first === "function": return (item, index, array) => Object.is(first(item, index, array), second);
|
|
35
|
+
case typeof first === "number" || typeof first === "string": return (item) => Object.is(item[first], second);
|
|
36
|
+
default: return;
|
|
107
37
|
}
|
|
108
|
-
const limit = options?.limit ?? Number.POSITIVE_INFINITY;
|
|
109
|
-
const flat = options?.map?.flat ?? false;
|
|
110
|
-
const mapCallback = getArrayCallback(options?.map?.callback);
|
|
111
|
-
const mapReverse = options?.map?.reverse ?? false;
|
|
112
|
-
let map;
|
|
113
|
-
if (mapCallback != null) map = {
|
|
114
|
-
before: mapReverse ? mapCallback : void 0,
|
|
115
|
-
after: mapReverse ? void 0 : mapCallback
|
|
116
|
-
};
|
|
117
|
-
const simple = callbacks?.bool != null || type === "all" && key == null;
|
|
118
|
-
const findParameters = {
|
|
119
|
-
array,
|
|
120
|
-
arrayLength,
|
|
121
|
-
flat,
|
|
122
|
-
limit,
|
|
123
|
-
map,
|
|
124
|
-
result,
|
|
125
|
-
type,
|
|
126
|
-
value,
|
|
127
|
-
callback: simple ? callbacks?.bool : callbacks?.keyed
|
|
128
|
-
};
|
|
129
|
-
return simple ? findSimpleValues(findParameters) : findComplexValues(findParameters);
|
|
130
38
|
}
|
|
131
|
-
export {
|
|
39
|
+
export { findValue };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { ARRAY_FIND_VALUE_INDEX } from "../../models/array/array.find.model.mjs";
|
|
2
1
|
import { findValue } from "./find.mjs";
|
|
3
2
|
// src/internal/array/index-of.ts
|
|
4
3
|
function indexOf(array, ...parameters) {
|
|
5
|
-
return findValue(
|
|
4
|
+
return findValue(array, {
|
|
5
|
+
indiced: true,
|
|
6
|
+
input: parameters
|
|
7
|
+
})?.values[0] ?? -1;
|
|
6
8
|
}
|
|
7
9
|
function lastIndexOf(array, ...parameters) {
|
|
8
|
-
return findValue(
|
|
10
|
+
return findValue(array, {
|
|
11
|
+
indiced: true,
|
|
12
|
+
input: parameters,
|
|
13
|
+
reverse: true
|
|
14
|
+
})?.values[0] ?? -1;
|
|
9
15
|
}
|
|
10
16
|
indexOf.last = lastIndexOf;
|
|
11
17
|
export { indexOf, lastIndexOf };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../../models/array/array.misc.model.mjs";
|
|
2
|
-
import { chunk } from "./chunk.mjs";
|
|
3
2
|
import { max, min } from "../math/aggregate.mjs";
|
|
3
|
+
import { chunk } from "./chunk.mjs";
|
|
4
4
|
// src/internal/array/insert.ts
|
|
5
5
|
function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
6
6
|
const actualDeleteCount = max([deleteCount, 0]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getArrayCallback } from "./callbacks.mjs";
|
|
2
1
|
import { ARRAY_MATCH_COMPARISON_INSIDE, ARRAY_MATCH_COMPARISON_SAME, ARRAY_MATCH_COMPARISON_START, arrayMatchEndings, arrayMatchInvalid, arrayMatchOutside, arrayMatchOutsides, arrayMatchStarts } from "../../models/array/array.match.model.mjs";
|
|
2
|
+
import { getArrayCallback } from "./callbacks.mjs";
|
|
3
3
|
// src/internal/array/match.ts
|
|
4
4
|
function endsWithArray(haystack, needle, key) {
|
|
5
5
|
return arrayMatchEndings.has(getPosition(haystack, needle, key)[1]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getArrayCallback } from "./callbacks.mjs";
|
|
2
1
|
import { ARRAY_SETS_COMPARE_DIFFERENCE, ARRAY_SETS_COMPARE_INTERSECTION, ARRAY_SETS_COMPARE_UNION } from "../../models/array/array.misc.model.mjs";
|
|
2
|
+
import { getArrayCallback } from "./callbacks.mjs";
|
|
3
3
|
// src/internal/array/sets.ts
|
|
4
4
|
function compareSets(type, first, second, key) {
|
|
5
5
|
if (!Array.isArray(first)) return [];
|
|
@@ -24,12 +24,12 @@ function getComparison(first, second, isIntersection, isUnion, key) {
|
|
|
24
24
|
}
|
|
25
25
|
const source = isUnion ? second : first;
|
|
26
26
|
length = source.length;
|
|
27
|
-
const
|
|
27
|
+
const compared = isUnion ? first.slice() : [];
|
|
28
28
|
for (let index = 0; index < length; index += 1) {
|
|
29
29
|
const item = source[index];
|
|
30
30
|
const value = callback?.(item, index, source) ?? item;
|
|
31
|
-
if (isIntersection ? set.has(value) : !set.has(value))
|
|
31
|
+
if (isIntersection ? set.has(value) : !set.has(value)) compared.push(item);
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return compared;
|
|
34
34
|
}
|
|
35
35
|
export { compareSets };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Constructor, NestedKeys, NestedValue, PlainObject } from "../../models/index.mjs";
|
|
2
1
|
import { AssertNestedPick, Asserter } from "../../models/function/assert.model.mjs";
|
|
2
|
+
import { Constructor, NestedKeys, NestedValue, PlainObject } from "../../models/index.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Asserts that a condition is true, throwing an error if it is not
|
|
5
5
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericAsyncCallback, GenericCallback } from "../../models/index.mjs";
|
|
2
1
|
import { AsyncLimiter, Limiter, LimiterType } from "../../models/function/limiter.model.mjs";
|
|
2
|
+
import { GenericAsyncCallback, GenericCallback } from "../../models/index.mjs";
|
|
3
3
|
export declare function getAsyncLimiter<Callback extends GenericAsyncCallback | GenericCallback>(type: LimiterType, callback: Callback, time?: number): AsyncLimiter<Callback>;
|
|
4
4
|
export declare function getLimiter<Callback extends GenericCallback>(type: LimiterType, callback: Callback, time?: number): Limiter<Callback>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LIMITER_NAME_ASYNC, LIMITER_NAME_SYNC, LIMITER_PROPERTY, LIMITER_SYMBOL, LIMITER_THROTTLE, clearTimer, startTimer } from "../../models/function/limiter.model.mjs";
|
|
1
|
+
import { LIMITER_NAME_ASYNC, LIMITER_NAME_SYNC, LIMITER_SYMBOL, LIMITER_THROTTLE, clearTimer, startTimer } from "../../models/function/limiter.model.mjs";
|
|
3
2
|
import { getNumberOrDefault } from "../defaults.mjs";
|
|
3
|
+
import { asyncAttempt } from "../result/attempt.mjs";
|
|
4
4
|
// src/internal/function/limit.ts
|
|
5
5
|
function AsyncLimiter(type, callback, time) {
|
|
6
6
|
this[LIMITER_SYMBOL] = {
|
|
7
7
|
callback,
|
|
8
8
|
type,
|
|
9
9
|
interval: getNumberOrDefault(time, 0),
|
|
10
|
+
name: LIMITER_NAME_ASYNC,
|
|
10
11
|
parameters: [],
|
|
11
12
|
throttle: type === LIMITER_THROTTLE
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
AsyncLimiter.prototype[LIMITER_PROPERTY] = LIMITER_NAME_ASYNC;
|
|
15
15
|
AsyncLimiter.prototype.cancel = cancelAsyncLimiter;
|
|
16
16
|
AsyncLimiter.prototype.run = runAsyncLimiter;
|
|
17
17
|
function Limiter(type, callback, time) {
|
|
@@ -19,11 +19,11 @@ function Limiter(type, callback, time) {
|
|
|
19
19
|
callback,
|
|
20
20
|
type,
|
|
21
21
|
interval: getNumberOrDefault(time, 0),
|
|
22
|
+
name: LIMITER_NAME_SYNC,
|
|
22
23
|
parameters: [],
|
|
23
24
|
throttle: type === LIMITER_THROTTLE
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
Limiter.prototype[LIMITER_PROPERTY] = LIMITER_NAME_SYNC;
|
|
27
27
|
Limiter.prototype.cancel = cancelLimiter;
|
|
28
28
|
Limiter.prototype.run = runLimiter;
|
|
29
29
|
function cancelAsyncLimiter() {
|
|
@@ -50,13 +50,13 @@ async function handleAsyncLimiter(state, item) {
|
|
|
50
50
|
if (state.interval === 0 || now - state.start >= state.interval - 5) {
|
|
51
51
|
state.start = state.throttle ? now : void 0;
|
|
52
52
|
item.running = true;
|
|
53
|
-
const
|
|
53
|
+
const attempted = await asyncAttempt(async () => {
|
|
54
54
|
let value = state.callback(...item.parameters);
|
|
55
55
|
if (value instanceof Promise) value = await value;
|
|
56
56
|
return value;
|
|
57
57
|
});
|
|
58
|
-
if (
|
|
59
|
-
else item.reject(
|
|
58
|
+
if (attempted.ok) item.resolve(attempted.value);
|
|
59
|
+
else item.reject(attempted.error);
|
|
60
60
|
item.running = false;
|
|
61
61
|
} else state.timer = startTimer(() => handleAsyncLimiter(state, item));
|
|
62
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericCallback } from "../../models/index.mjs";
|
|
2
1
|
import { Memoized, MemoizedOptions, MemoizedStateOptions } from "../../models/function/memoize.model.mjs";
|
|
2
|
+
import { GenericCallback } from "../../models/index.mjs";
|
|
3
3
|
declare function Memoized(this: any, callback: GenericCallback, options: MemoizedStateOptions): void;
|
|
4
4
|
/**
|
|
5
5
|
* Memoize a function, caching and retrieving results based on the first parameter
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isPlainObject } from "../is.mjs";
|
|
2
|
-
import { getString, join } from "../string/misc.mjs";
|
|
3
|
-
import { getNumberOrDefault } from "../defaults.mjs";
|
|
4
1
|
import { MEMOIZED_CACHE_SIZE_DEFAULT, MEMOIZED_CALLBACK, MEMOIZED_SYMBOL } from "../../models/function/memoize.model.mjs";
|
|
2
|
+
import { getNumberOrDefault } from "../defaults.mjs";
|
|
3
|
+
import { isPlainObject } from "../is.mjs";
|
|
5
4
|
import { SizedMap } from "../sized/map.mjs";
|
|
5
|
+
import { getString, join } from "../string/misc.mjs";
|
|
6
6
|
// src/internal/function/memoize.ts
|
|
7
7
|
function Memoized(callback, options) {
|
|
8
8
|
this[MEMOIZED_SYMBOL] = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { AsyncFlow, Flow } from "../../models/function/work.model.mjs";
|
|
1
2
|
import { GenericCallback } from "../../models/index.mjs";
|
|
2
3
|
import { UnwrapValue } from "../../models/result.model.mjs";
|
|
3
|
-
import { AsyncFlow, Flow } from "../../models/function/work.model.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Create an asynchronous _Flow_, a function that pipes values through a function
|
|
6
6
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { unwrapWork } from "./misc.mjs";
|
|
2
1
|
import { WORK_MESSAGE_FLOW_PROMISE, WORK_MESSAGE_NESTING, WORK_MESSAGE_PIPE_PROMISE, assertFlowFunctions, assertPipeFunctions } from "../../models/function/work.model.mjs";
|
|
2
|
+
import { unwrapWork } from "./misc.mjs";
|
|
3
3
|
// src/internal/function/work.ts
|
|
4
4
|
function asyncFlow(...fns) {
|
|
5
5
|
assertFlowFunctions(fns);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { GenericCallback } from "../models/index.mjs";
|
|
2
|
-
import { Subscription } from "../models/subscription.model.mjs";
|
|
3
1
|
import { Herald, HeraldEvents, HeraldOptions } from "../models/herald.model.mjs";
|
|
2
|
+
import { GenericCallback } from "../models/index.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Create a _Herald_ for announcing named events
|
|
6
5
|
*
|
|
@@ -22,11 +21,4 @@ export declare function isHerald<Events extends Record<string, GenericCallback>
|
|
|
22
21
|
* @param value Value to check
|
|
23
22
|
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
24
23
|
*/
|
|
25
|
-
export declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
|
26
|
-
/**
|
|
27
|
-
* Is the value a herald subscription?
|
|
28
|
-
*
|
|
29
|
-
* @param value Value to check
|
|
30
|
-
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
31
|
-
*/
|
|
32
|
-
export declare function isHeraldSubscription(value: unknown): value is Subscription;
|
|
24
|
+
export declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
package/dist/internal/herald.mjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
import { HERALD_MESSAGE_ARRAY, HERALD_MESSAGE_ONCREATE, HERALD_NAME_EVENTS, HERALD_NAME_HERALD, HERALD_SYMBOL } from "../models/herald.model.mjs";
|
|
1
2
|
import { isPlainObject } from "./is.mjs";
|
|
2
|
-
import "
|
|
3
|
-
import { isSubscription, subscriptions } from "./subscription.mjs";
|
|
4
|
-
import { HERALD_MESSAGE_ARRAY, HERALD_MESSAGE_ONCREATE, HERALD_MESSAGE_PROPERTY, HERALD_NAME_EVENTS, HERALD_NAME_HERALD, HERALD_PROPERTY, HERALD_SYMBOL, heraldSubscription } from "../models/herald.model.mjs";
|
|
3
|
+
import { subscriptions } from "./subscription.mjs";
|
|
5
4
|
// src/internal/herald.ts
|
|
6
5
|
function Events(herald, state) {
|
|
6
|
+
this[HERALD_SYMBOL] = { name: HERALD_NAME_EVENTS };
|
|
7
7
|
for (const key of state.keys) Object.defineProperty(this, key, { value: (callback, signal) => herald.subscribe(key, callback, signal) });
|
|
8
8
|
}
|
|
9
|
-
Events.prototype[HERALD_PROPERTY] = HERALD_NAME_EVENTS;
|
|
10
9
|
function Herald(state) {
|
|
11
10
|
this[HERALD_SYMBOL] = {
|
|
12
11
|
state,
|
|
13
|
-
events: new Events(this, state)
|
|
12
|
+
events: new Events(this, state),
|
|
13
|
+
name: HERALD_NAME_HERALD
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
Herald.prototype[HERALD_PROPERTY] = HERALD_NAME_HERALD;
|
|
17
16
|
Herald.prototype.clear = clearHerald;
|
|
18
17
|
Herald.prototype.emit = emitForHerald;
|
|
19
18
|
Herald.prototype.observed = eventIsObserved;
|
|
@@ -30,25 +29,12 @@ function createHeraldState(input) {
|
|
|
30
29
|
if (!Array.isArray(options.names) || options.names.length === 0 || !options.names.every((name) => typeof name === "string")) throw new Error(HERALD_MESSAGE_ARRAY);
|
|
31
30
|
if (options.onCreate != null && typeof options.onCreate !== "function") throw new Error(HERALD_MESSAGE_ONCREATE);
|
|
32
31
|
const keys = new Set(options.names);
|
|
33
|
-
const property = createHeraldSubscriptionProperty(options.property);
|
|
34
32
|
return {
|
|
35
33
|
keys,
|
|
36
|
-
store: subscriptions({
|
|
37
|
-
keys,
|
|
38
|
-
property
|
|
39
|
-
}),
|
|
34
|
+
store: subscriptions({ keys }),
|
|
40
35
|
onCreate: options.onCreate
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
|
-
function createHeraldSubscriptionProperty(input) {
|
|
44
|
-
if (input == null) return heraldSubscription;
|
|
45
|
-
const property = isPlainObject(input) ? input : {};
|
|
46
|
-
if (typeof property.key !== "string" || property.value != null && typeof property.value !== "string") throw new Error(HERALD_MESSAGE_PROPERTY);
|
|
47
|
-
return {
|
|
48
|
-
key: property.key,
|
|
49
|
-
value: property.value
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
38
|
function emitForHerald(event, ...parameters) {
|
|
53
39
|
const { state } = this[HERALD_SYMBOL];
|
|
54
40
|
const items = state.store.values.from.keyed?.get(event);
|
|
@@ -90,16 +76,7 @@ function isHeraldEvents(value) {
|
|
|
90
76
|
return isHeraldInstance(HERALD_NAME_EVENTS, value);
|
|
91
77
|
}
|
|
92
78
|
function isHeraldInstance(name, value) {
|
|
93
|
-
return typeof value === "object" && value !== null &&
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Is the value a herald subscription?
|
|
97
|
-
*
|
|
98
|
-
* @param value Value to check
|
|
99
|
-
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
100
|
-
*/
|
|
101
|
-
function isHeraldSubscription(value) {
|
|
102
|
-
return isSubscription(value) && "$herald" in value && value["$herald"] === "subscription";
|
|
79
|
+
return typeof value === "object" && value !== null && HERALD_SYMBOL in value && value[HERALD_SYMBOL].name === name;
|
|
103
80
|
}
|
|
104
81
|
function subscribeToHerald(key, callback, signal) {
|
|
105
82
|
const { state } = this[HERALD_SYMBOL];
|
|
@@ -111,4 +88,4 @@ function subscribeToHerald(key, callback, signal) {
|
|
|
111
88
|
if (!existing) state.onCreate?.(key, callback, subscription);
|
|
112
89
|
return subscription;
|
|
113
90
|
}
|
|
114
|
-
export { herald, isHerald, isHeraldEvents
|
|
91
|
+
export { herald, isHerald, isHeraldEvents };
|
package/dist/internal/number.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { EXPRESSION_NUMBER_BINARY, EXPRESSION_NUMBER_OCTAL, EXPRESSION_NUMBER_ZEROISH } from "../models/misc.model.mjs";
|
|
1
2
|
import { isNumber } from "./is.mjs";
|
|
2
3
|
import { max, min } from "./math/aggregate.mjs";
|
|
3
|
-
import { EXPRESSION_NUMBER_BINARY, EXPRESSION_NUMBER_OCTAL, EXPRESSION_NUMBER_ZEROISH } from "../models/misc.model.mjs";
|
|
4
4
|
// src/internal/number.ts
|
|
5
5
|
/**
|
|
6
6
|
* Is the number between a minimum and maximum value?
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { attempt } from "../result/attempt.mjs";
|
|
2
1
|
import { PLAN_SYMBOL } from "../../models/plan.model.mjs";
|
|
2
|
+
import { attempt } from "../result/attempt.mjs";
|
|
3
3
|
import { asyncGenerate, generate } from "./plan.generate.mjs";
|
|
4
4
|
// src/internal/plan/index.ts
|
|
5
5
|
function attemptRunPlan(...parameters) {
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import { isError, isOk } from "../result/misc.mjs";
|
|
2
|
-
import { noop } from "../function/misc.mjs";
|
|
3
1
|
import { createAborter } from "../aborter.mjs";
|
|
2
|
+
import { noop } from "../function/misc.mjs";
|
|
3
|
+
import { isError, isOk } from "../result/misc.mjs";
|
|
4
4
|
// src/internal/plan/plan.generate.ts
|
|
5
|
+
async function asyncCleanup(generator, input) {
|
|
6
|
+
try {
|
|
7
|
+
const returned = await generator.return(input);
|
|
8
|
+
if (returned.done) return;
|
|
9
|
+
let cleanupValue = returned.value;
|
|
10
|
+
while (true) {
|
|
11
|
+
const { done, value } = await generator.next(cleanupValue);
|
|
12
|
+
if (done) break;
|
|
13
|
+
cleanupValue = value;
|
|
14
|
+
}
|
|
15
|
+
} catch {}
|
|
16
|
+
}
|
|
5
17
|
async function asyncGenerate(input, unwrap, first, second) {
|
|
6
18
|
const aborter = createAborter(second ?? first, noop);
|
|
7
19
|
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
@@ -9,53 +21,87 @@ async function asyncGenerate(input, unwrap, first, second) {
|
|
|
9
21
|
let generator;
|
|
10
22
|
if (typeof input === "function") generator = input(...parameters);
|
|
11
23
|
else generator = input.generator(...parameters);
|
|
24
|
+
let aborted = false;
|
|
12
25
|
let success = true;
|
|
26
|
+
let throwing = false;
|
|
27
|
+
let lastError;
|
|
13
28
|
let lastValue;
|
|
14
29
|
try {
|
|
15
30
|
while (true) {
|
|
16
|
-
if (aborter?.signal.aborted)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
if (aborter?.signal.aborted) {
|
|
32
|
+
if (aborted) break;
|
|
33
|
+
aborted = true;
|
|
34
|
+
lastError = aborter.signal.reason;
|
|
35
|
+
throwing = true;
|
|
36
|
+
}
|
|
37
|
+
const { done, value } = await asyncResume(generator, throwing ? lastError : lastValue, throwing);
|
|
38
|
+
if (value instanceof Error || isError(value)) {
|
|
39
|
+
const errorValue = value instanceof Error ? value : value.error;
|
|
40
|
+
if (done) throw errorValue;
|
|
41
|
+
lastError = errorValue;
|
|
42
|
+
lastValue = void 0;
|
|
43
|
+
throwing = true;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
lastError = void 0;
|
|
22
47
|
lastValue = value;
|
|
23
|
-
|
|
48
|
+
throwing = false;
|
|
49
|
+
if (done) break;
|
|
24
50
|
}
|
|
25
51
|
} catch (error) {
|
|
26
|
-
|
|
52
|
+
lastError = error;
|
|
27
53
|
success = false;
|
|
28
54
|
} finally {
|
|
29
55
|
aborter?.cancel();
|
|
30
|
-
await generator
|
|
56
|
+
await asyncCleanup(generator, lastValue);
|
|
31
57
|
}
|
|
32
58
|
if (aborter?.signal.aborted) throw aborter.signal.reason;
|
|
33
59
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
34
|
-
throw
|
|
60
|
+
throw lastError;
|
|
61
|
+
}
|
|
62
|
+
async function asyncResume(generator, input, throwing) {
|
|
63
|
+
const { done, value } = await (throwing ? generator.throw(input) : generator.next(input));
|
|
64
|
+
return {
|
|
65
|
+
value,
|
|
66
|
+
done: done === true
|
|
67
|
+
};
|
|
35
68
|
}
|
|
36
69
|
function generate(input, parameters, unwrap) {
|
|
37
70
|
let generator;
|
|
38
71
|
if (typeof input === "function") generator = input(...parameters);
|
|
39
72
|
else generator = input.generator(...parameters);
|
|
40
73
|
let success = true;
|
|
74
|
+
let throwing = false;
|
|
75
|
+
let lastError;
|
|
41
76
|
let lastValue;
|
|
42
77
|
try {
|
|
43
78
|
while (true) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
79
|
+
const { done, value } = resume(generator, throwing ? lastError : lastValue, throwing);
|
|
80
|
+
if (value instanceof Error || isError(value)) {
|
|
81
|
+
const errorValue = value instanceof Error ? value : value.error;
|
|
82
|
+
if (done) throw errorValue;
|
|
83
|
+
lastError = errorValue;
|
|
84
|
+
lastValue = void 0;
|
|
85
|
+
throwing = true;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
lastError = void 0;
|
|
49
89
|
lastValue = value;
|
|
90
|
+
throwing = false;
|
|
50
91
|
if (done) break;
|
|
51
92
|
}
|
|
52
93
|
} catch (error) {
|
|
53
|
-
|
|
94
|
+
lastError = error;
|
|
54
95
|
success = false;
|
|
55
|
-
} finally {
|
|
56
|
-
generator.return(lastValue);
|
|
57
96
|
}
|
|
58
97
|
if (success) return unwrap && isOk(lastValue) ? lastValue.value : lastValue;
|
|
59
|
-
throw
|
|
98
|
+
throw lastError;
|
|
99
|
+
}
|
|
100
|
+
function resume(generator, input, throwing) {
|
|
101
|
+
const { done, value } = throwing ? generator.throw(input) : generator.next(input);
|
|
102
|
+
return {
|
|
103
|
+
value,
|
|
104
|
+
done: done === true
|
|
105
|
+
};
|
|
60
106
|
}
|
|
61
107
|
export { asyncGenerate, generate };
|
|
@@ -9,6 +9,9 @@ export declare class SizedMap<SizedKey = unknown, SizedValue = unknown> extends
|
|
|
9
9
|
* Is the _Map_ full?
|
|
10
10
|
*/
|
|
11
11
|
get full(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The maximum size of the _Map_
|
|
14
|
+
*/
|
|
12
15
|
get maximum(): number;
|
|
13
16
|
/**
|
|
14
17
|
* Create a new _SizedMap_ with entries and a maximum size _(2^20)_
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { join, words } from "./misc.mjs";
|
|
2
|
-
import { memoize } from "../function/memoize.mjs";
|
|
3
1
|
import { STRING_CASE_CAMEL, STRING_CASE_CAPITALIZE, STRING_CASE_KEBAB, STRING_CASE_LOWER, STRING_CASE_PASCAL, STRING_CASE_SNAKE, STRING_CASE_TITLE, STRING_CASE_UPPER, STRING_EXPRESSION_ACRONYM, STRING_EXPRESSION_CAMEL_CASE, STRING_REPLACEMENT_CAMEL_CASE, ignoreCachingCases } from "../../models/string/string.case.model.mjs";
|
|
2
|
+
import { memoize } from "../function/memoize.mjs";
|
|
3
|
+
import { join, words } from "./misc.mjs";
|
|
4
4
|
// src/internal/string/case.ts
|
|
5
5
|
/**
|
|
6
6
|
* Convert a string to camel case _(thisIsCamelCase)_
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { unwrap } from "../result/misc.mjs";
|
|
2
1
|
import { STRING_EXPRESSION_IGNORED, STRING_EXPRESSION_WORDS } from "../../models/string/string.misc.model.mjs";
|
|
2
|
+
import { unwrap } from "../result/misc.mjs";
|
|
3
3
|
import { attempt } from "../result/attempt.mjs";
|
|
4
4
|
// src/internal/string/misc.ts
|
|
5
5
|
/**
|