@oscarpalmer/atoms 0.212.0 → 0.214.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.d.mts +1 -1
- package/dist/array/difference.mjs +3 -2
- package/dist/array/exists.d.mts +1 -1
- package/dist/array/exists.mjs +3 -2
- package/dist/array/filter.d.mts +1 -1
- package/dist/array/filter.mjs +1 -0
- package/dist/array/find.d.mts +1 -1
- package/dist/array/find.mjs +4 -3
- package/dist/array/first.d.mts +1 -1
- package/dist/array/flatten.d.mts +1 -1
- package/dist/array/group-by.d.mts +1 -1
- package/dist/array/index.d.mts +2 -2
- package/dist/array/insert.mjs +3 -2
- package/dist/array/intersection.mjs +3 -2
- package/dist/array/last.d.mts +1 -1
- package/dist/array/move.d.mts +1 -1
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/partition.mjs +1 -0
- package/dist/array/push.mjs +3 -2
- package/dist/array/select.d.mts +10 -12
- package/dist/array/select.mjs +1 -0
- package/dist/array/single.d.mts +1 -1
- package/dist/array/single.mjs +1 -0
- package/dist/array/slice.d.mts +1 -1
- package/dist/array/slice.mjs +4 -5
- package/dist/array/sort.d.mts +4 -103
- package/dist/array/sort.mjs +6 -14
- package/dist/array/splice.mjs +3 -2
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/to-map.d.mts +1 -1
- package/dist/array/to-record.d.mts +1 -1
- package/dist/array/to-set.d.mts +1 -1
- package/dist/array/toggle.d.mts +1 -1
- package/dist/array/union.mjs +3 -2
- package/dist/array/unique.d.mts +1 -1
- package/dist/array/unique.mjs +3 -2
- package/dist/array/update.d.mts +1 -1
- package/dist/beacon.d.mts +6 -92
- package/dist/beacon.mjs +6 -16
- package/dist/color/constants.d.mts +2 -2
- package/dist/color/constants.mjs +1 -1
- package/dist/color/index.d.mts +1 -1
- package/dist/color/instance.d.mts +1 -1
- package/dist/color/instance.mjs +0 -1
- package/dist/color/misc/alpha.d.mts +1 -1
- package/dist/color/misc/format.d.mts +1 -1
- package/dist/color/misc/get.d.mts +1 -1
- package/dist/color/misc/is.d.mts +2 -2
- package/dist/color/misc/is.mjs +1 -0
- package/dist/color/misc/state.d.mts +1 -1
- package/dist/color/space/hex.d.mts +1 -1
- package/dist/color/space/hsl.d.mts +1 -1
- package/dist/color/space/hwb.d.mts +1 -1
- package/dist/color/space/rgb.d.mts +1 -1
- package/dist/function/limit.d.mts +2 -2
- package/dist/function/limit.mjs +2 -1
- package/dist/function/once.d.mts +7 -3
- package/dist/function/once.mjs +5 -10
- package/dist/function/retry.d.mts +4 -14
- package/dist/function/retry.mjs +3 -15
- package/dist/herald.d.mts +2 -2
- package/dist/index.d.mts +466 -351
- package/dist/index.mjs +491 -439
- package/dist/internal/aborter.d.mts +1 -6
- package/dist/internal/aborter.mjs +3 -4
- package/dist/internal/array/callbacks.d.mts +3 -7
- package/dist/internal/array/chunk.mjs +2 -2
- package/dist/internal/array/find.d.mts +5 -23
- package/dist/internal/array/find.mjs +5 -9
- package/dist/internal/array/get.d.mts +1 -1
- package/dist/internal/array/group.d.mts +1 -1
- package/dist/internal/array/index-of.d.mts +1 -1
- package/dist/internal/array/index-of.mjs +4 -3
- package/dist/internal/array/insert.d.mts +2 -5
- package/dist/internal/array/insert.mjs +2 -4
- package/dist/internal/array/match.d.mts +2 -5
- package/dist/internal/array/match.mjs +10 -20
- package/dist/internal/array/overlap.d.mts +2 -10
- package/dist/internal/array/sets.d.mts +2 -5
- package/dist/internal/array/sets.mjs +5 -7
- package/dist/internal/function/assert.d.mts +5 -12
- package/dist/internal/function/assert.mjs +2 -2
- package/dist/internal/function/limit.d.mts +2 -37
- package/dist/internal/function/limit.mjs +4 -15
- package/dist/internal/function/memoize.d.mts +5 -70
- package/dist/internal/function/memoize.mjs +2 -5
- package/dist/internal/function/work.d.mts +16 -22
- package/dist/internal/function/work.mjs +1 -8
- package/dist/internal/herald.d.mts +3 -3
- package/dist/internal/herald.mjs +2 -1
- package/dist/internal/is.d.mts +1 -1
- package/dist/internal/math/aggregate.d.mts +2 -14
- package/dist/internal/math/aggregate.mjs +2 -5
- package/dist/internal/number.mjs +4 -7
- package/dist/internal/result/attempt.d.mts +1 -1
- package/dist/internal/result/misc.d.mts +1 -1
- package/dist/internal/string/case.mjs +6 -16
- package/dist/internal/string/misc.mjs +1 -3
- package/dist/internal/subscription.d.mts +1 -100
- package/dist/internal/subscription.mjs +3 -9
- package/dist/internal/value/compare.d.mts +4 -4
- package/dist/internal/value/compare.mjs +1 -1
- package/dist/internal/value/equal.d.mts +6 -57
- package/dist/internal/value/equal.mjs +5 -10
- package/dist/internal/value/get.d.mts +1 -1
- package/dist/internal/value/handlers.d.mts +2 -21
- package/dist/internal/value/has.d.mts +2 -2
- package/dist/internal/value/misc.d.mts +1 -1
- package/dist/internal/value/misc.mjs +8 -14
- package/dist/internal/value/set.d.mts +1 -1
- package/dist/internal/value/set.mjs +2 -2
- package/dist/is.mjs +3 -3
- package/dist/logger.d.mts +3 -70
- package/dist/logger.mjs +2 -5
- package/dist/math.d.mts +1 -1
- package/dist/math.mjs +2 -1
- package/dist/models/aborter.model.d.mts +12 -0
- package/dist/models/aborter.model.mjs +5 -0
- package/dist/models/array/array.find.model.d.mts +22 -0
- package/dist/models/array/array.find.model.mjs +8 -0
- package/dist/models/array/array.match.model.d.mts +14 -0
- package/dist/models/array/array.match.model.mjs +14 -0
- package/dist/models/array/array.misc.model.d.mts +36 -0
- package/dist/models/array/array.misc.model.mjs +12 -0
- package/dist/models/array/array.sort.model.d.mts +122 -0
- package/dist/models/array/array.sort.model.mjs +12 -0
- package/dist/models/beacon.model.d.mts +119 -0
- package/dist/models/beacon.model.mjs +16 -0
- package/dist/{color/models.d.mts → models/color.model.d.mts} +4 -4
- package/dist/models/function/assert.model.d.mts +13 -0
- package/dist/models/function/assert.model.mjs +4 -0
- package/dist/models/function/limiter.model.d.mts +71 -0
- package/dist/models/function/limiter.model.mjs +15 -0
- package/dist/models/function/memoize.model.d.mts +88 -0
- package/dist/models/function/memoize.model.mjs +7 -0
- package/dist/models/function/once.model.d.mts +76 -0
- package/dist/models/function/once.model.mjs +9 -0
- package/dist/models/function/retry.model.d.mts +17 -0
- package/dist/models/function/retry.model.mjs +17 -0
- package/dist/models/function/work.model.d.mts +20 -0
- package/dist/models/function/work.model.mjs +11 -0
- package/dist/{internal/models → models}/herald.model.d.mts +3 -3
- package/dist/{internal/models → models}/herald.model.mjs +2 -2
- package/dist/{models.d.mts → models/index.d.mts} +8 -50
- package/dist/models/logger.model.d.mts +83 -0
- package/dist/models/logger.model.mjs +7 -0
- package/dist/models/math.model.d.mts +16 -0
- package/dist/models/math.model.mjs +7 -0
- package/dist/models/misc.model.d.mts +10 -0
- package/dist/models/misc.model.mjs +11 -0
- package/dist/{internal/models → models}/plan.model.d.mts +17 -15
- package/dist/{internal/models → models}/plan.model.mjs +1 -1
- package/dist/models/promise.model.d.mts +119 -0
- package/dist/models/promise.model.mjs +47 -0
- package/dist/models/query.model.d.mts +9 -0
- package/dist/models/query.model.mjs +14 -0
- package/dist/models/queue.model.d.mts +251 -0
- package/dist/models/queue.model.mjs +29 -0
- package/dist/models/random.model.d.mts +6 -0
- package/dist/models/random.model.mjs +7 -0
- package/dist/{internal/models → models}/result.model.d.mts +10 -2
- package/dist/models/string/string.case.model.d.mts +19 -0
- package/dist/models/string/string.case.model.mjs +14 -0
- package/dist/models/string/string.fuzzy.model.d.mts +108 -0
- package/dist/models/string/string.fuzzy.model.mjs +9 -0
- package/dist/models/string/string.misc.model.d.mts +13 -0
- package/dist/models/string/string.misc.model.mjs +13 -0
- package/dist/models/string/string.normalize.model.d.mts +85 -0
- package/dist/models/string/string.normalize.model.mjs +43 -0
- package/dist/models/string/string.template.model.d.mts +50 -0
- package/dist/models/string/string.template.model.mjs +5 -0
- package/dist/models/subscription.model.d.mts +127 -0
- package/dist/models/subscription.model.mjs +10 -0
- package/dist/models/value/value.clone.model.d.mts +56 -0
- package/dist/models/value/value.clone.model.mjs +24 -0
- package/dist/models/value/value.diff.model.d.mts +61 -0
- package/dist/models/value/value.diff.model.mjs +6 -0
- package/dist/models/value/value.equal.model.d.mts +76 -0
- package/dist/models/value/value.equal.model.mjs +9 -0
- package/dist/models/value/value.handler.model.d.mts +27 -0
- package/dist/models/value/value.handler.model.mjs +1 -0
- package/dist/models/value/value.merge.model.d.mts +82 -0
- package/dist/models/value/value.merge.model.mjs +5 -0
- package/dist/models/value/value.misc.model.d.mts +33 -0
- package/dist/models/value/value.misc.model.mjs +12 -0
- package/dist/models/value/value.transform.model.d.mts +28 -0
- package/dist/models/value/value.transform.model.mjs +4 -0
- package/dist/plan/generate.d.mts +3 -2
- package/dist/plan/generate.mjs +14 -10
- package/dist/plan/index.d.mts +1 -1
- package/dist/plan/index.mjs +2 -2
- package/dist/plan/is.d.mts +31 -2
- package/dist/plan/is.mjs +45 -1
- package/dist/plan/misc.d.mts +21 -2
- package/dist/plan/misc.mjs +32 -2
- package/dist/plan/models.d.mts +1 -1
- package/dist/plan/result.d.mts +7 -7
- package/dist/plan/result.mjs +6 -6
- package/dist/plan/run.d.mts +5 -5
- package/dist/plan/run.mjs +6 -6
- package/dist/promise/delay.d.mts +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +6 -6
- package/dist/promise/index.d.mts +2 -2
- package/dist/promise/index.mjs +1 -1
- package/dist/promise/misc.d.mts +3 -3
- package/dist/promise/misc.mjs +7 -4
- package/dist/promise/models.d.mts +2 -106
- package/dist/promise/models.mjs +1 -35
- package/dist/promise/timed.d.mts +2 -2
- package/dist/promise/timed.mjs +3 -3
- package/dist/query.d.mts +1 -1
- package/dist/query.mjs +5 -15
- package/dist/queue.d.mts +6 -200
- package/dist/queue.mjs +9 -34
- package/dist/random.mjs +2 -5
- package/dist/result/match.d.mts +1 -1
- package/dist/result/match.mjs +27 -15
- package/dist/result/misc.d.mts +1 -1
- package/dist/result/work/flow.d.mts +13 -21
- package/dist/result/work/flow.mjs +0 -1
- package/dist/result/work/pipe.d.mts +2 -2
- package/dist/result/work/pipe.mjs +0 -1
- package/dist/string/fuzzy.d.mts +5 -87
- package/dist/string/fuzzy.mjs +6 -11
- package/dist/string/index.mjs +6 -8
- package/dist/string/match.mjs +4 -6
- package/dist/string/normalize.d.mts +4 -40
- package/dist/string/normalize.mjs +9 -48
- package/dist/string/template.d.mts +5 -43
- package/dist/string/template.mjs +1 -2
- package/dist/subscription.d.mts +2 -1
- package/dist/value/clone.d.mts +6 -42
- package/dist/value/clone.mjs +10 -30
- package/dist/value/collection.mjs +2 -0
- package/dist/value/diff.d.mts +3 -44
- package/dist/value/diff.mjs +1 -3
- package/dist/value/freeze.d.mts +1 -5
- package/dist/value/index.d.mts +4 -3
- package/dist/value/merge.d.mts +6 -64
- package/dist/value/merge.mjs +8 -8
- package/dist/value/omit.d.mts +1 -1
- package/dist/value/pick.d.mts +1 -1
- package/dist/value/shake.d.mts +4 -6
- package/dist/value/smush.d.mts +4 -6
- package/dist/value/smush.mjs +2 -2
- package/dist/value/transform.d.mts +6 -22
- package/dist/value/transform.mjs +1 -1
- package/dist/value/unsmush.d.mts +4 -10
- package/package.json +12 -3
- package/dist/internal/plan.d.mts +0 -45
- package/dist/internal/plan.mjs +0 -70
- package/dist/promise/constants.d.mts +0 -17
- package/dist/promise/constants.mjs +0 -15
- /package/dist/{color/models.mjs → models/color.model.mjs} +0 -0
- /package/dist/{internal/models/result.model.mjs → models/index.mjs} +0 -0
- /package/dist/{models.mjs → models/result.model.mjs} +0 -0
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Aborter } from "../models/aborter.model.mjs";
|
|
2
2
|
//#region src/internal/aborter.d.ts
|
|
3
|
-
export type Aborter = {
|
|
4
|
-
callback: GenericCallback;
|
|
5
|
-
cancel(): void;
|
|
6
|
-
signal: AbortSignal;
|
|
7
|
-
};
|
|
8
3
|
export declare function createAborter(value: unknown, onAbort: () => void): Aborter | undefined;
|
|
9
4
|
//#endregion
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import { ABORTER_EVENT, ABORTER_OPTIONS } from "../models/aborter.model.mjs";
|
|
1
2
|
//#region src/internal/aborter.ts
|
|
2
3
|
function createAborter(value, onAbort) {
|
|
3
4
|
if (!(value instanceof AbortSignal)) return;
|
|
4
|
-
value.addEventListener(
|
|
5
|
+
value.addEventListener(ABORTER_EVENT, onAbort, ABORTER_OPTIONS);
|
|
5
6
|
return {
|
|
6
7
|
callback: onAbort,
|
|
7
8
|
signal: value,
|
|
8
|
-
cancel: () => value.removeEventListener(
|
|
9
|
+
cancel: () => value.removeEventListener(ABORTER_EVENT, onAbort)
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
|
-
const ABORT_EVENT = "abort";
|
|
12
|
-
const ABORT_OPTIONS = { once: true };
|
|
13
12
|
//#endregion
|
|
14
13
|
export { createAborter };
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { GenericCallback } from "../../models.mjs";
|
|
1
|
+
import { GenericCallback } from "../../models/index.mjs";
|
|
2
|
+
import { ArrayGetCallbacks } from "../../models/array/array.misc.model.mjs";
|
|
2
3
|
//#region src/internal/array/callbacks.d.ts
|
|
3
|
-
export type Callbacks = {
|
|
4
|
-
bool?: GenericCallback;
|
|
5
|
-
keyed?: GenericCallback;
|
|
6
|
-
value?: GenericCallback;
|
|
7
|
-
};
|
|
8
4
|
export declare function getArrayCallback(value: unknown): GenericCallback | undefined;
|
|
9
|
-
export declare function getArrayCallbacks(bool?: unknown, key?: unknown, value?: unknown):
|
|
5
|
+
export declare function getArrayCallbacks(bool?: unknown, key?: unknown, value?: unknown): ArrayGetCallbacks | undefined;
|
|
10
6
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ARRAY_CHUNK_MAX_SIZE } from "../../models/array/array.misc.model.mjs";
|
|
1
2
|
//#region src/internal/array/chunk.ts
|
|
2
3
|
/**
|
|
3
4
|
* Chunk an array into smaller arrays
|
|
@@ -15,7 +16,7 @@ function chunk(array, size) {
|
|
|
15
16
|
if (!Array.isArray(array)) return [];
|
|
16
17
|
if (array.length === 0) return [];
|
|
17
18
|
const { length } = array;
|
|
18
|
-
const actualSize = typeof size === "number" && size > 0 && size <=
|
|
19
|
+
const actualSize = typeof size === "number" && size > 0 && size <= 5e3 ? size : ARRAY_CHUNK_MAX_SIZE;
|
|
19
20
|
if (length <= actualSize) return [array];
|
|
20
21
|
const chunks = [];
|
|
21
22
|
let index = 0;
|
|
@@ -25,6 +26,5 @@ function chunk(array, size) {
|
|
|
25
26
|
}
|
|
26
27
|
return chunks;
|
|
27
28
|
}
|
|
28
|
-
const CHUNK_MAX_SIZE = 5e3;
|
|
29
29
|
//#endregion
|
|
30
30
|
export { chunk };
|
|
@@ -1,26 +1,8 @@
|
|
|
1
|
+
import { ArrayFindMapper, ArrayFindValueType, ArrayFindValuesResult, ArrayFindValuesType, ArrayParameters } from "../../models/array/array.find.model.mjs";
|
|
1
2
|
//#region src/internal/array/find.d.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
type FindValueType = "index" | "item";
|
|
7
|
-
type FindValuesResult = {
|
|
8
|
-
matched: unknown[];
|
|
9
|
-
notMatched: unknown[];
|
|
10
|
-
};
|
|
11
|
-
type FindValuesType = "all" | "unique";
|
|
12
|
-
type Parameters = {
|
|
13
|
-
bool?: unknown;
|
|
14
|
-
key?: unknown;
|
|
15
|
-
value?: unknown;
|
|
16
|
-
};
|
|
17
|
-
export declare function createFindParameters(original: unknown[]): Parameters;
|
|
18
|
-
export declare function findValue(type: Exclude<FindValueType, "item">, array: unknown[], parameters: unknown[], reversed: boolean): number;
|
|
19
|
-
export declare function findValue(type: Exclude<FindValueType, "index">, array: unknown[], parameters: unknown[], reversed: boolean): unknown;
|
|
3
|
+
export declare function createFindParameters(original: unknown[]): ArrayParameters;
|
|
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;
|
|
20
6
|
export declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
|
|
21
|
-
export declare function findValues(type:
|
|
22
|
-
export declare const FIND_VALUE_INDEX = "index";
|
|
23
|
-
export declare const FIND_VALUE_ITEM = "item";
|
|
24
|
-
export declare const FIND_VALUES_ALL: FindValuesType;
|
|
25
|
-
export declare const FIND_VALUES_UNIQUE: FindValuesType;
|
|
7
|
+
export declare function findValues(type: ArrayFindValuesType, array: unknown[], parameters: unknown[], mapper?: ArrayFindMapper): ArrayFindValuesResult;
|
|
26
8
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ARRAY_FIND_VALUE_INDEX } from "../../models/array/array.find.model.mjs";
|
|
1
2
|
import { getArrayCallback, getArrayCallbacks } from "./callbacks.mjs";
|
|
2
3
|
//#region src/internal/array/find.ts
|
|
3
4
|
function createFindParameters(original) {
|
|
@@ -9,7 +10,7 @@ function createFindParameters(original) {
|
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
function findValue(type, array, parameters, reversed) {
|
|
12
|
-
const findIndex = type ===
|
|
13
|
+
const findIndex = type === ARRAY_FIND_VALUE_INDEX;
|
|
13
14
|
if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
|
|
14
15
|
const { bool, key, value } = createFindParameters(parameters);
|
|
15
16
|
const callbacks = getArrayCallbacks(bool, key);
|
|
@@ -36,7 +37,7 @@ function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultV
|
|
|
36
37
|
if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
|
|
37
38
|
return useDefaultValue ? defaultValue : void 0;
|
|
38
39
|
}
|
|
39
|
-
const index = findValue(
|
|
40
|
+
const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
|
|
40
41
|
return index > -1 ? array[index] : useDefaultValue ? defaultValue : void 0;
|
|
41
42
|
}
|
|
42
43
|
function findValues(type, array, parameters, mapper) {
|
|
@@ -48,7 +49,7 @@ function findValues(type, array, parameters, mapper) {
|
|
|
48
49
|
const { length } = array;
|
|
49
50
|
const { bool, key, value } = createFindParameters(parameters);
|
|
50
51
|
const callbacks = getArrayCallbacks(bool, key);
|
|
51
|
-
if (type === "unique" && callbacks?.keyed == null && length >=
|
|
52
|
+
if (type === "unique" && callbacks?.keyed == null && length >= 100) {
|
|
52
53
|
result.matched = [...new Set(array)];
|
|
53
54
|
return result;
|
|
54
55
|
}
|
|
@@ -85,10 +86,5 @@ function findValues(type, array, parameters, mapper) {
|
|
|
85
86
|
}
|
|
86
87
|
return result;
|
|
87
88
|
}
|
|
88
|
-
const FIND_VALUE_INDEX = "index";
|
|
89
|
-
const FIND_VALUE_ITEM = "item";
|
|
90
|
-
const FIND_VALUES_ALL = "all";
|
|
91
|
-
const FIND_VALUES_UNIQUE = "unique";
|
|
92
|
-
const FIND_UNIQUE_THRESHOLD = 100;
|
|
93
89
|
//#endregion
|
|
94
|
-
export {
|
|
90
|
+
export { createFindParameters, findAbsoluteValueOrDefault, findValue, findValues };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ARRAY_FIND_VALUE_INDEX } from "../../models/array/array.find.model.mjs";
|
|
2
|
+
import { findValue } from "./find.mjs";
|
|
2
3
|
//#region src/internal/array/index-of.ts
|
|
3
4
|
function indexOf(array, ...parameters) {
|
|
4
|
-
return findValue(
|
|
5
|
+
return findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, false);
|
|
5
6
|
}
|
|
6
7
|
function lastIndexOf(array, ...parameters) {
|
|
7
|
-
return findValue(
|
|
8
|
+
return findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, true);
|
|
8
9
|
}
|
|
9
10
|
indexOf.last = lastIndexOf;
|
|
10
11
|
//#endregion
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
+
import { ArrayInsertType } from "../../models/array/array.misc.model.mjs";
|
|
1
2
|
//#region src/internal/array/insert.d.ts
|
|
2
|
-
type
|
|
3
|
-
export declare function insertValues(type: InsertType, array: unknown, items: unknown, start: unknown, deleteCount: number): unknown;
|
|
4
|
-
export declare const INSERT_TYPE_INSERT: InsertType;
|
|
5
|
-
export declare const INSERT_TYPE_PUSH: InsertType;
|
|
6
|
-
export declare const INSERT_TYPE_SPLICE: InsertType;
|
|
3
|
+
export declare function insertValues(type: ArrayInsertType, array: unknown, items: unknown, start: unknown, deleteCount: number): unknown;
|
|
7
4
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "../../models/array/array.misc.model.mjs";
|
|
1
2
|
import { chunk } from "./chunk.mjs";
|
|
2
3
|
import { max, min } from "../math/aggregate.mjs";
|
|
3
4
|
//#region src/internal/array/insert.ts
|
|
@@ -22,8 +23,5 @@ function insertValues(type, array, items, start, deleteCount) {
|
|
|
22
23
|
if (!Array.isArray(array) || typeof start !== "number" || !Array.isArray(items) || items.length === 0) return spliceArray ? [] : 0;
|
|
23
24
|
return insertChunkedValues(type, array, items, start, spliceArray ? deleteCount : 0);
|
|
24
25
|
}
|
|
25
|
-
const INSERT_TYPE_INSERT = "insert";
|
|
26
|
-
const INSERT_TYPE_PUSH = "push";
|
|
27
|
-
const INSERT_TYPE_SPLICE = "splice";
|
|
28
26
|
//#endregion
|
|
29
|
-
export {
|
|
27
|
+
export { insertValues };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { PlainObject } from "../../models.mjs";
|
|
1
|
+
import { PlainObject } from "../../models/index.mjs";
|
|
2
|
+
import { ArrayComparison } from "../../models/array/array.misc.model.mjs";
|
|
2
3
|
//#region src/internal/array/match.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Comparison of an array within another array
|
|
5
|
-
*/
|
|
6
|
-
export type ArrayComparison = "end" | "inside" | "invalid" | "outside" | "same" | "start";
|
|
7
4
|
/**
|
|
8
5
|
* Is the needle array at the end of the haystack array?
|
|
9
6
|
*
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { getArrayCallback } from "./callbacks.mjs";
|
|
2
|
+
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
3
|
//#region src/internal/array/match.ts
|
|
3
4
|
function endsWithArray(haystack, needle, key) {
|
|
4
|
-
return
|
|
5
|
+
return arrayMatchEndings.has(getPosition(haystack, needle, key)[1]);
|
|
5
6
|
}
|
|
6
7
|
function getArrayComparison(haystack, needle, key) {
|
|
7
8
|
return getPosition(haystack, needle, key)[1];
|
|
8
9
|
}
|
|
9
10
|
function getName(start, haystack, needle) {
|
|
10
|
-
if (start === 0) return haystack === needle ?
|
|
11
|
-
return start + needle === haystack ?
|
|
11
|
+
if (start === 0) return haystack === needle ? ARRAY_MATCH_COMPARISON_SAME : ARRAY_MATCH_COMPARISON_START;
|
|
12
|
+
return start + needle === haystack ? "end" : ARRAY_MATCH_COMPARISON_INSIDE;
|
|
12
13
|
}
|
|
13
14
|
function getPosition(haystack, needle, key) {
|
|
14
|
-
if (!Array.isArray(haystack) || !Array.isArray(needle)) return
|
|
15
|
+
if (!Array.isArray(haystack) || !Array.isArray(needle)) return arrayMatchInvalid;
|
|
15
16
|
const haystackLength = haystack.length;
|
|
16
17
|
const needleLength = needle.length;
|
|
17
|
-
if (haystackLength === 0 || needleLength === 0) return
|
|
18
|
-
if (needleLength > haystackLength) return
|
|
18
|
+
if (haystackLength === 0 || needleLength === 0) return arrayMatchOutside;
|
|
19
|
+
if (needleLength > haystackLength) return arrayMatchOutside;
|
|
19
20
|
const callback = getArrayCallback(key);
|
|
20
21
|
const limit = haystackLength - needleLength + 1;
|
|
21
22
|
let needleValues = callback == null ? needle : needle.slice();
|
|
@@ -32,27 +33,16 @@ function getPosition(haystack, needle, key) {
|
|
|
32
33
|
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return arrayMatchOutside;
|
|
36
37
|
}
|
|
37
38
|
function includesArray(haystack, needle, key) {
|
|
38
|
-
return !
|
|
39
|
+
return !arrayMatchOutsides.has(getPosition(haystack, needle, key)[1]);
|
|
39
40
|
}
|
|
40
41
|
function indexOfArray(haystack, needle, key) {
|
|
41
42
|
return getPosition(haystack, needle, key)[0];
|
|
42
43
|
}
|
|
43
44
|
function startsWithArray(haystack, needle, key) {
|
|
44
|
-
return
|
|
45
|
+
return arrayMatchStarts.has(getPosition(haystack, needle, key)[1]);
|
|
45
46
|
}
|
|
46
|
-
const MATCH_COMPARISON_END = "end";
|
|
47
|
-
const MATCH_COMPARISON_INSIDE = "inside";
|
|
48
|
-
const MATCH_COMPARISON_INVALID = "invalid";
|
|
49
|
-
const MATCH_COMPARISON_OUTSIDE = "outside";
|
|
50
|
-
const MATCH_COMPARISON_SAME = "same";
|
|
51
|
-
const MATCH_COMPARISON_START = "start";
|
|
52
|
-
const endings = /* @__PURE__ */ new Set([MATCH_COMPARISON_END, MATCH_COMPARISON_SAME]);
|
|
53
|
-
const invalid = [-1, MATCH_COMPARISON_INVALID];
|
|
54
|
-
const outside = [-1, MATCH_COMPARISON_OUTSIDE];
|
|
55
|
-
const outsides = /* @__PURE__ */ new Set([MATCH_COMPARISON_INVALID, MATCH_COMPARISON_OUTSIDE]);
|
|
56
|
-
const starts = /* @__PURE__ */ new Set([MATCH_COMPARISON_START, MATCH_COMPARISON_SAME]);
|
|
57
47
|
//#endregion
|
|
58
48
|
export { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
+
import { ArrayOverlapItem, ArrayOverlapResult } from "../../models/array/array.misc.model.mjs";
|
|
1
2
|
//#region src/internal/array/overlap.d.ts
|
|
2
|
-
|
|
3
|
-
array: unknown[];
|
|
4
|
-
index: number;
|
|
5
|
-
};
|
|
6
|
-
type OverlapResult = {
|
|
7
|
-
first: OverlapItem;
|
|
8
|
-
second: OverlapItem;
|
|
9
|
-
overlap: boolean;
|
|
10
|
-
};
|
|
11
|
-
export declare function arraysOverlap(first: OverlapItem, second: OverlapItem): OverlapResult;
|
|
3
|
+
export declare function arraysOverlap(first: ArrayOverlapItem, second: ArrayOverlapItem): ArrayOverlapResult;
|
|
12
4
|
//#endregion
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
+
import { ArrayCompareSetsType } from "../../models/array/array.misc.model.mjs";
|
|
1
2
|
//#region src/internal/array/sets.d.ts
|
|
2
|
-
type
|
|
3
|
-
export declare function compareSets(type: CompareSetsType, first: unknown[], second: unknown[], key?: unknown): unknown[];
|
|
4
|
-
export declare const SETS_COMPARE_DIFFERENCE: CompareSetsType;
|
|
5
|
-
export declare const SETS_COMPARE_INTERSECTION: CompareSetsType;
|
|
6
|
-
export declare const SETS_COMPARE_UNION: CompareSetsType;
|
|
3
|
+
export declare function compareSets(type: ArrayCompareSetsType, first: unknown[], second: unknown[], key?: unknown): unknown[];
|
|
7
4
|
//#endregion
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getArrayCallback } from "./callbacks.mjs";
|
|
2
|
+
import { ARRAY_SETS_COMPARE_DIFFERENCE, ARRAY_SETS_COMPARE_INTERSECTION, ARRAY_SETS_COMPARE_UNION } from "../../models/array/array.misc.model.mjs";
|
|
2
3
|
//#region src/internal/array/sets.ts
|
|
3
4
|
function compareSets(type, first, second, key) {
|
|
4
5
|
if (!Array.isArray(first)) return [];
|
|
5
|
-
const isDifference = type ===
|
|
6
|
-
const isIntersection = type ===
|
|
7
|
-
const isUnion = type ===
|
|
6
|
+
const isDifference = type === ARRAY_SETS_COMPARE_DIFFERENCE;
|
|
7
|
+
const isIntersection = type === ARRAY_SETS_COMPARE_INTERSECTION;
|
|
8
|
+
const isUnion = type === ARRAY_SETS_COMPARE_UNION;
|
|
8
9
|
if (first.length === 0) return isDifference ? first.slice() : isIntersection ? [] : second.slice();
|
|
9
10
|
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : first.slice();
|
|
10
11
|
const callback = getArrayCallback(key);
|
|
@@ -25,8 +26,5 @@ function compareSets(type, first, second, key) {
|
|
|
25
26
|
}
|
|
26
27
|
return result;
|
|
27
28
|
}
|
|
28
|
-
const SETS_COMPARE_DIFFERENCE = "difference";
|
|
29
|
-
const SETS_COMPARE_INTERSECTION = "intersection";
|
|
30
|
-
const SETS_COMPARE_UNION = "union";
|
|
31
29
|
//#endregion
|
|
32
|
-
export {
|
|
30
|
+
export { compareSets };
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { Constructor, NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
|
|
1
|
+
import { Constructor, NestedKeys, NestedValue, PlainObject } from "../../models/index.mjs";
|
|
2
|
+
import { AssertNestedPick, Asserter } from "../../models/function/assert.model.mjs";
|
|
2
3
|
//#region src/internal/function/assert.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Asserter for a property of a value
|
|
5
|
-
*/
|
|
6
|
-
export type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted extends NestedPick<Value, Path> = NestedPick<Value, Path>> = Asserter<Asserted>;
|
|
7
|
-
/**
|
|
8
|
-
* A function that asserts a value is of a specific type, throwing an error if it is not
|
|
9
|
-
*/
|
|
10
|
-
export type Asserter<Value> = (value: unknown) => asserts value is Value;
|
|
11
|
-
type NestedPick<Value, Path extends string> = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: NestedPick<Value[Key], Rest>; } : never : Path extends keyof Value ? { [Key in Path]: Value[Key]; } : never : never;
|
|
12
4
|
/**
|
|
13
5
|
* Asserts that a condition is true, throwing an error if it is not
|
|
14
6
|
*
|
|
@@ -71,7 +63,7 @@ export declare function assertIs<Value>(condition: (value: unknown) => value is
|
|
|
71
63
|
* @param error Error constructor _(defaults to `Error`)_
|
|
72
64
|
* @returns _Asserter_
|
|
73
65
|
*/
|
|
74
|
-
export declare function assertProperty<Value extends PlainObject, Path extends NestedKeys<Value>>(path: Path, condition: (value: NestedValue<Value, Path>) => boolean, message: string, error?: ErrorConstructor): Asserter<
|
|
66
|
+
export declare function assertProperty<Value extends PlainObject, Path extends NestedKeys<Value>>(path: Path, condition: (value: NestedValue<Value, Path>) => boolean, message: string, error?: ErrorConstructor): Asserter<AssertNestedPick<Value, Path>>;
|
|
75
67
|
export declare namespace assert {
|
|
76
68
|
export var condition: typeof assertCondition;
|
|
77
69
|
export var defined: typeof assertDefined;
|
|
@@ -79,4 +71,5 @@ export declare namespace assert {
|
|
|
79
71
|
export var is: typeof assertIs;
|
|
80
72
|
export var property: typeof assertProperty;
|
|
81
73
|
}
|
|
82
|
-
//#endregion
|
|
74
|
+
//#endregion
|
|
75
|
+
export type { Asserter };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "../../models/function/assert.model.mjs";
|
|
1
2
|
import { hasValueResult } from "../value/has.mjs";
|
|
2
3
|
//#region src/internal/function/assert.ts
|
|
3
4
|
/**
|
|
@@ -35,7 +36,7 @@ function assertCondition(condition, message, error) {
|
|
|
35
36
|
* @param error Error constructor _(defaults to `Error`)_
|
|
36
37
|
*/
|
|
37
38
|
function assertDefined(value, message, error) {
|
|
38
|
-
assert(() => value != null, message ??
|
|
39
|
+
assert(() => value != null, message ?? "Expected value to be defined", error);
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
@@ -86,7 +87,6 @@ function assertProperty(path, condition, message, error) {
|
|
|
86
87
|
}, message, error);
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
|
-
const ASSERT_MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
90
90
|
assert.condition = assertCondition;
|
|
91
91
|
assert.defined = assertDefined;
|
|
92
92
|
assert.instanceOf = assertInstanceOf;
|
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
import { GenericAsyncCallback, GenericCallback } from "../../models.mjs";
|
|
1
|
+
import { GenericAsyncCallback, GenericCallback } from "../../models/index.mjs";
|
|
2
|
+
import { AsyncLimiter, Limiter, LimiterType } from "../../models/function/limiter.model.mjs";
|
|
2
3
|
//#region src/internal/function/limit.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* An asynchronous function that can be cancelled
|
|
5
|
-
*/
|
|
6
|
-
export type AsyncLimiter<Callback extends GenericAsyncCallback> = {
|
|
7
|
-
/**
|
|
8
|
-
* Cancel the function
|
|
9
|
-
*/
|
|
10
|
-
cancel(): void;
|
|
11
|
-
/**
|
|
12
|
-
* Call the function
|
|
13
|
-
*
|
|
14
|
-
* @param parameters Function parameters
|
|
15
|
-
* @returns Function result
|
|
16
|
-
*/
|
|
17
|
-
run(...parameters: Parameters<Callback>): Promise<ReturnType<Callback>>;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* A function that can be cancelled
|
|
21
|
-
*/
|
|
22
|
-
export type Limiter<Callback extends GenericCallback> = {
|
|
23
|
-
/**
|
|
24
|
-
* Cancel the function
|
|
25
|
-
*/
|
|
26
|
-
cancel(): void;
|
|
27
|
-
/**
|
|
28
|
-
* Call the function
|
|
29
|
-
*
|
|
30
|
-
* @param parameters Function parameters
|
|
31
|
-
* @returns Function result
|
|
32
|
-
*/
|
|
33
|
-
run(...parameters: Parameters<Callback>): ReturnType<Callback>;
|
|
34
|
-
};
|
|
35
|
-
type LimiterType = "debounce" | "throttle" | "wait";
|
|
36
4
|
export declare function getAsyncLimiter<Callback extends GenericAsyncCallback | GenericCallback>(type: LimiterType, callback: Callback, time?: number): AsyncLimiter<Callback>;
|
|
37
5
|
export declare function getLimiter<Callback extends GenericCallback>(type: LimiterType, callback: Callback, time?: number): Limiter<Callback>;
|
|
38
|
-
export declare const LIMITER_DEBOUNCE: LimiterType;
|
|
39
|
-
export declare const LIMITER_THROTTLE: LimiterType;
|
|
40
|
-
export declare const LIMITER_WAIT: LimiterType;
|
|
41
6
|
//#endregion
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { asyncAttempt } from "../result/attempt.mjs";
|
|
2
|
+
import { LIMITER_NAME_ASYNC, LIMITER_NAME_SYNC, LIMITER_PROPERTY, LIMITER_SYMBOL, LIMITER_THROTTLE, clearTimer, startTimer } from "../../models/function/limiter.model.mjs";
|
|
2
3
|
import { getNumberOrDefault } from "../defaults.mjs";
|
|
3
4
|
//#region src/internal/function/limit.ts
|
|
4
|
-
const LIMITER_NAME_ASYNC = "asyncLimiter";
|
|
5
|
-
const LIMITER_NAME_SYNC = "limiter";
|
|
6
|
-
const LIMITER_PROPERTY = "$limiter";
|
|
7
5
|
function AsyncLimiter(type, callback, time) {
|
|
8
6
|
this[LIMITER_SYMBOL] = {
|
|
9
7
|
callback,
|
|
@@ -49,7 +47,7 @@ function getLimiter(type, callback, time) {
|
|
|
49
47
|
async function handleAsyncLimiter(state, item) {
|
|
50
48
|
const now = performance.now();
|
|
51
49
|
state.start ??= now;
|
|
52
|
-
if (state.interval === 0 || now - state.start >= state.interval -
|
|
50
|
+
if (state.interval === 0 || now - state.start >= state.interval - 5) {
|
|
53
51
|
state.start = state.throttle ? now : void 0;
|
|
54
52
|
item.running = true;
|
|
55
53
|
const result = await asyncAttempt(async () => {
|
|
@@ -65,7 +63,7 @@ async function handleAsyncLimiter(state, item) {
|
|
|
65
63
|
function handleLimiter(state) {
|
|
66
64
|
const now = performance.now();
|
|
67
65
|
state.start ??= now;
|
|
68
|
-
if (state.interval === 0 || now - state.start >= state.interval -
|
|
66
|
+
if (state.interval === 0 || now - state.start >= state.interval - 5) {
|
|
69
67
|
state.start = state.throttle ? now : void 0;
|
|
70
68
|
state.callback(...state.parameters);
|
|
71
69
|
} else state.timer = startTimer(() => handleLimiter(state));
|
|
@@ -93,14 +91,5 @@ function runLimiter(...parameters) {
|
|
|
93
91
|
if (state.throttle) handleLimiter(state);
|
|
94
92
|
else state.timer = startTimer(() => handleLimiter(state));
|
|
95
93
|
}
|
|
96
|
-
const LIMITER_DEBOUNCE = "debounce";
|
|
97
|
-
const LIMITER_OFFSET = 5;
|
|
98
|
-
const LIMITER_SYMBOL = Symbol("limiter");
|
|
99
|
-
const LIMITER_THROTTLE = "throttle";
|
|
100
|
-
const LIMITER_WAIT = "wait";
|
|
101
|
-
// istanbul ignore next
|
|
102
|
-
const clearTimer = typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : clearTimeout;
|
|
103
|
-
// istanbul ignore next
|
|
104
|
-
const startTimer = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout;
|
|
105
94
|
//#endregion
|
|
106
|
-
export {
|
|
95
|
+
export { getAsyncLimiter, getLimiter };
|
|
@@ -1,73 +1,7 @@
|
|
|
1
|
-
import { GenericCallback } from "../../models.mjs";
|
|
1
|
+
import { GenericCallback } from "../../models/index.mjs";
|
|
2
|
+
import { Memoized, MemoizedOptions, MemoizedStateOptions } from "../../models/function/memoize.model.mjs";
|
|
2
3
|
//#region src/internal/function/memoize.d.ts
|
|
3
|
-
|
|
4
|
-
* A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
5
|
-
*/
|
|
6
|
-
export type Memoized<Callback extends GenericCallback> = {
|
|
7
|
-
/**
|
|
8
|
-
* Maximum cache size
|
|
9
|
-
*
|
|
10
|
-
* @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
11
|
-
*/
|
|
12
|
-
get maximum(): number;
|
|
13
|
-
/**
|
|
14
|
-
* Current cache size
|
|
15
|
-
*
|
|
16
|
-
* @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
17
|
-
*/
|
|
18
|
-
get size(): number;
|
|
19
|
-
/**
|
|
20
|
-
* Clear the cache
|
|
21
|
-
*/
|
|
22
|
-
clear(): void;
|
|
23
|
-
/**
|
|
24
|
-
* Delete a result from the cache
|
|
25
|
-
*
|
|
26
|
-
* @param key Key to delete
|
|
27
|
-
* @returns `true` if the key existed and was removed, otherwise `false`
|
|
28
|
-
*/
|
|
29
|
-
delete(key: unknown): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Destroy the instance
|
|
32
|
-
*
|
|
33
|
-
* _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
|
|
34
|
-
*/
|
|
35
|
-
destroy(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Get a result from the cache
|
|
38
|
-
*
|
|
39
|
-
* @param key Key to get
|
|
40
|
-
* @returns Cached result or `undefined` if it does not exist
|
|
41
|
-
*/
|
|
42
|
-
get(key: unknown): ReturnType<Callback> | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Does the result exist?
|
|
45
|
-
*
|
|
46
|
-
* @param key Key to check
|
|
47
|
-
* @returns `true` if the result exists, otherwise `false`
|
|
48
|
-
*/
|
|
49
|
-
has(key: unknown): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Run the callback with the provided parameters
|
|
52
|
-
*
|
|
53
|
-
* @param parameters Parameters to pass to the callback
|
|
54
|
-
* @returns Cached or computed _(then cached)_ result
|
|
55
|
-
*/
|
|
56
|
-
run(...parameters: Parameters<Callback>): ReturnType<Callback>;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Options for a _Memoized_ function
|
|
60
|
-
*/
|
|
61
|
-
export type MemoizedOptions<Callback extends GenericCallback> = {
|
|
62
|
-
/**
|
|
63
|
-
* Callback for getting a cache key for the provided parameters
|
|
64
|
-
*/
|
|
65
|
-
cacheKey?: (...parameters: Parameters<Callback>) => unknown;
|
|
66
|
-
/**
|
|
67
|
-
* Size of the cache
|
|
68
|
-
*/
|
|
69
|
-
cacheSize?: number;
|
|
70
|
-
};
|
|
4
|
+
declare function Memoized(this: any, callback: GenericCallback, options: MemoizedStateOptions): void;
|
|
71
5
|
/**
|
|
72
6
|
* Memoize a function, caching and retrieving results based on the first parameter
|
|
73
7
|
*
|
|
@@ -76,4 +10,5 @@ export type MemoizedOptions<Callback extends GenericCallback> = {
|
|
|
76
10
|
* @returns _Memoized_ instance
|
|
77
11
|
*/
|
|
78
12
|
export declare function memoize<Callback extends GenericCallback>(callback: Callback, options?: MemoizedOptions<Callback>): Memoized<Callback>;
|
|
79
|
-
//#endregion
|
|
13
|
+
//#endregion
|
|
14
|
+
export type { Memoized, MemoizedOptions };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "../is.mjs";
|
|
2
2
|
import { getString, join } from "../string/misc.mjs";
|
|
3
3
|
import { getNumberOrDefault } from "../defaults.mjs";
|
|
4
|
+
import { MEMOIZED_CACHE_SIZE_DEFAULT, MEMOIZED_CALLBACK, MEMOIZED_SYMBOL } from "../../models/function/memoize.model.mjs";
|
|
4
5
|
import { SizedMap } from "../sized/map.mjs";
|
|
5
6
|
//#region src/internal/function/memoize.ts
|
|
6
7
|
function Memoized(callback, options) {
|
|
@@ -34,7 +35,7 @@ function deleteMemoizedValue(key) {
|
|
|
34
35
|
}
|
|
35
36
|
function createGetter(state, callback) {
|
|
36
37
|
return (...parameters) => {
|
|
37
|
-
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString),
|
|
38
|
+
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), "_"));
|
|
38
39
|
if (state.cache.has(key)) return state.cache.get(key);
|
|
39
40
|
const value = callback(...parameters);
|
|
40
41
|
state.cache.set(key, value);
|
|
@@ -74,9 +75,5 @@ function memoize(callback, options) {
|
|
|
74
75
|
function runMemoized(...parameters) {
|
|
75
76
|
return this[MEMOIZED_SYMBOL].getter(...parameters);
|
|
76
77
|
}
|
|
77
|
-
const MEMOIZED_CACHE_SIZE_DEFAULT = 1024;
|
|
78
|
-
const MEMOIZED_CALLBACK = "Memoized requires a callback function";
|
|
79
|
-
const MEMOIZED_KEY_SEPARATOR = "_";
|
|
80
|
-
const MEMOIZED_SYMBOL = Symbol("memoized");
|
|
81
78
|
//#endregion
|
|
82
79
|
export { memoize };
|