@oscarpalmer/atoms 0.202.0 → 0.203.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 +4 -5
- package/dist/array/exists.d.mts +5 -6
- package/dist/array/filter.d.mts +10 -11
- package/dist/array/find.d.mts +10 -11
- package/dist/array/first.d.mts +10 -11
- package/dist/array/flatten.d.mts +2 -3
- package/dist/array/from.d.mts +7 -8
- package/dist/array/group-by.d.mts +7 -8
- package/dist/array/insert.d.mts +3 -4
- package/dist/array/intersection.d.mts +4 -5
- package/dist/array/last.d.mts +10 -11
- package/dist/array/move.d.mts +9 -10
- package/dist/array/partition.d.mts +5 -6
- package/dist/array/push.d.mts +2 -3
- package/dist/array/reverse.d.mts +2 -3
- package/dist/array/select.d.mts +11 -12
- package/dist/array/single.d.mts +4 -5
- package/dist/array/slice.d.mts +12 -13
- package/dist/array/sort.d.mts +31 -32
- package/dist/array/sort.mjs +41 -33
- package/dist/array/splice.d.mts +5 -6
- package/dist/array/swap.d.mts +8 -9
- package/dist/array/to-map.d.mts +7 -8
- package/dist/array/to-record.d.mts +7 -8
- package/dist/array/to-set.d.mts +4 -5
- package/dist/array/toggle.d.mts +4 -5
- package/dist/array/union.d.mts +4 -5
- package/dist/array/unique.d.mts +4 -5
- package/dist/array/update.d.mts +4 -5
- package/dist/beacon.d.mts +8 -9
- package/dist/beacon.mjs +90 -65
- package/dist/color/constants.d.mts +14 -13
- package/dist/color/constants.mjs +9 -2
- package/dist/color/index.d.mts +2 -2
- package/dist/color/instance.d.mts +3 -3
- package/dist/color/instance.mjs +125 -61
- package/dist/color/misc/alpha.d.mts +4 -5
- package/dist/color/misc/format.d.mts +6 -7
- package/dist/color/misc/format.mjs +15 -12
- package/dist/color/misc/get.d.mts +14 -15
- package/dist/color/misc/is.d.mts +16 -17
- package/dist/color/misc/is.mjs +3 -4
- package/dist/color/misc/state.d.mts +8 -10
- package/dist/color/misc/state.mjs +22 -20
- package/dist/color/models.d.mts +25 -19
- package/dist/color/space/hex.d.mts +9 -10
- package/dist/color/space/hsl.d.mts +8 -9
- package/dist/color/space/hwb.d.mts +9 -10
- package/dist/color/space/rgb.d.mts +11 -12
- package/dist/function/limit.d.mts +9 -8
- package/dist/function/limit.mjs +5 -5
- package/dist/function/once.d.mts +26 -6
- package/dist/function/once.mjs +135 -76
- package/dist/function/retry.d.mts +5 -6
- package/dist/function/retry.mjs +3 -3
- package/dist/index.d.mts +182 -58
- package/dist/index.mjs +1191 -810
- package/dist/internal/abort.d.mts +3 -4
- package/dist/internal/array/callbacks.d.mts +4 -5
- package/dist/internal/array/chunk.d.mts +2 -3
- package/dist/internal/array/compact.d.mts +3 -4
- package/dist/internal/array/find.d.mts +10 -11
- package/dist/internal/array/get.d.mts +7 -8
- package/dist/internal/array/group.d.mts +2 -3
- package/dist/internal/array/index-of.d.mts +10 -11
- package/dist/internal/array/insert.d.mts +5 -6
- package/dist/internal/array/match.d.mts +17 -18
- package/dist/internal/array/overlap.d.mts +2 -3
- package/dist/internal/array/sets.d.mts +5 -6
- package/dist/internal/array/shuffle.d.mts +2 -3
- package/dist/internal/array/update.d.mts +2 -3
- package/dist/internal/defaults.d.mts +3 -4
- package/dist/internal/function/assert.d.mts +10 -11
- package/dist/internal/function/limit.d.mts +41 -0
- package/dist/internal/function/limit.mjs +110 -0
- package/dist/internal/function/memoize.d.mts +4 -5
- package/dist/internal/function/memoize.mjs +53 -31
- package/dist/internal/function/misc.d.mts +2 -3
- package/dist/internal/function/work.d.mts +53 -54
- package/dist/internal/herald.d.mts +8 -9
- package/dist/internal/herald.mjs +38 -26
- package/dist/internal/is.d.mts +19 -20
- package/dist/internal/math/aggregate.d.mts +14 -15
- package/dist/internal/math/misc.d.mts +3 -4
- package/dist/internal/number.d.mts +4 -5
- package/dist/internal/random.d.mts +3 -4
- package/dist/internal/result/misc.d.mts +29 -14
- package/dist/internal/result/misc.mjs +4 -0
- package/dist/internal/result/models.d.mts +9 -10
- package/dist/internal/sized/map.d.mts +2 -3
- package/dist/internal/sized/misc.d.mts +2 -3
- package/dist/internal/string/case.d.mts +9 -10
- package/dist/internal/string/misc.d.mts +8 -9
- package/dist/internal/subscription.d.mts +10 -11
- package/dist/internal/subscription.mjs +69 -57
- package/dist/internal/value/compare.d.mts +17 -9
- package/dist/internal/value/compare.mjs +7 -7
- package/dist/internal/value/equal.d.mts +34 -15
- package/dist/internal/value/equal.mjs +28 -13
- package/dist/internal/value/get.d.mts +3 -4
- package/dist/internal/value/handlers.d.mts +19 -9
- package/dist/internal/value/handlers.mjs +50 -50
- package/dist/internal/value/has.d.mts +6 -7
- package/dist/internal/value/misc.d.mts +6 -7
- package/dist/internal/value/partial.d.mts +3 -4
- package/dist/internal/value/set.d.mts +4 -5
- package/dist/is.d.mts +13 -13
- package/dist/logger.d.mts +5 -4
- package/dist/logger.mjs +61 -54
- package/dist/math.d.mts +20 -20
- package/dist/models.d.mts +45 -49
- package/dist/promise/constants.d.mts +14 -15
- package/dist/promise/delay.d.mts +3 -4
- package/dist/promise/delay.mjs +4 -4
- package/dist/promise/helpers.d.mts +7 -8
- package/dist/promise/index.d.mts +13 -14
- package/dist/promise/misc.d.mts +6 -6
- package/dist/promise/models.d.mts +16 -17
- package/dist/promise/timed.d.mts +4 -5
- package/dist/promise/timed.mjs +5 -5
- package/dist/query.d.mts +3 -4
- package/dist/queue.d.mts +14 -15
- package/dist/queue.mjs +185 -129
- package/dist/random.d.mts +8 -8
- package/dist/result/index.d.mts +8 -9
- package/dist/result/match.d.mts +6 -7
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +28 -29
- package/dist/result/work/pipe.d.mts +24 -25
- package/dist/sized/set.d.mts +2 -3
- package/dist/string/fuzzy.d.mts +21 -12
- package/dist/string/fuzzy.mjs +77 -49
- package/dist/string/index.d.mts +8 -8
- package/dist/string/match.d.mts +4 -5
- package/dist/string/normalize.d.mts +8 -9
- package/dist/string/normalize.mjs +9 -4
- package/dist/string/template.d.mts +9 -9
- package/dist/string/template.mjs +11 -4
- package/dist/value/clone.d.mts +21 -13
- package/dist/value/clone.mjs +22 -20
- package/dist/value/collection.d.mts +4 -5
- package/dist/value/diff.d.mts +5 -6
- package/dist/value/freeze.d.mts +18 -19
- package/dist/value/freeze.mjs +1 -1
- package/dist/value/merge.d.mts +13 -14
- package/dist/value/merge.mjs +21 -5
- package/dist/value/omit.d.mts +2 -3
- package/dist/value/pick.d.mts +2 -3
- package/dist/value/shake.d.mts +3 -4
- package/dist/value/smush.d.mts +3 -4
- package/dist/value/transform.d.mts +15 -10
- package/dist/value/transform.mjs +12 -7
- package/dist/value/unsmush.d.mts +3 -4
- package/package.json +1 -1
- package/dist/internal/function/timer.d.mts +0 -10
- package/dist/internal/function/timer.mjs +0 -87
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { GenericCallback } from "../models.mjs";
|
|
2
2
|
//#region src/internal/abort.d.ts
|
|
3
|
-
type Aborter = {
|
|
3
|
+
export type Aborter = {
|
|
4
4
|
callback: GenericCallback;
|
|
5
5
|
signal: AbortSignal;
|
|
6
6
|
cancel: () => void;
|
|
7
7
|
};
|
|
8
|
-
declare function createAborter(value: unknown, onAbort: () => void): Aborter | undefined;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { Aborter, createAborter };
|
|
8
|
+
export declare function createAborter(value: unknown, onAbort: () => void): Aborter | undefined;
|
|
9
|
+
//#endregion
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { GenericCallback } from "../../models.mjs";
|
|
2
2
|
//#region src/internal/array/callbacks.d.ts
|
|
3
|
-
type Callbacks = {
|
|
3
|
+
export type Callbacks = {
|
|
4
4
|
bool?: GenericCallback;
|
|
5
5
|
keyed?: GenericCallback;
|
|
6
6
|
value?: GenericCallback;
|
|
7
7
|
};
|
|
8
|
-
declare function getArrayCallback(value: unknown): GenericCallback | undefined;
|
|
9
|
-
declare function getArrayCallbacks(bool?: unknown, key?: unknown, value?: unknown): Callbacks | undefined;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { Callbacks, getArrayCallback, getArrayCallbacks };
|
|
8
|
+
export declare function getArrayCallback(value: unknown): GenericCallback | undefined;
|
|
9
|
+
export declare function getArrayCallbacks(bool?: unknown, key?: unknown, value?: unknown): Callbacks | undefined;
|
|
10
|
+
//#endregion
|
|
@@ -11,6 +11,5 @@
|
|
|
11
11
|
* chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
declare function chunk<Item>(array: Item[], size?: number): Item[][];
|
|
15
|
-
//#endregion
|
|
16
|
-
export { chunk };
|
|
14
|
+
export declare function chunk<Item>(array: Item[], size?: number): Item[][];
|
|
15
|
+
//#endregion
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* compact([0, 1, '', 'hello', false, true, null, undefined]); // => [1, 'hello', true]
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
declare function compact<Item>(array: Item[], strict: true): Array<Exclude<Item, 0 | '' | false | null | undefined>>;
|
|
14
|
+
export declare function compact<Item>(array: Item[], strict: true): Array<Exclude<Item, 0 | '' | false | null | undefined>>;
|
|
15
15
|
/**
|
|
16
16
|
* Compact an array _(removing all `null` and `undefined` values)_
|
|
17
17
|
*
|
|
@@ -23,6 +23,5 @@ declare function compact<Item>(array: Item[], strict: true): Array<Exclude<Item,
|
|
|
23
23
|
* compact([0, 1, '', 'hello', false, true, null, undefined]); // => [0, 1, '', 'hello', false, true]
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
declare function compact<Item>(array: Item[]): Array<Exclude<Item, null | undefined>>;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { compact };
|
|
26
|
+
export declare function compact<Item>(array: Item[]): Array<Exclude<Item, null | undefined>>;
|
|
27
|
+
//#endregion
|
|
@@ -14,14 +14,13 @@ type Parameters = {
|
|
|
14
14
|
key?: unknown;
|
|
15
15
|
value?: unknown;
|
|
16
16
|
};
|
|
17
|
-
declare function createFindParameters(original: unknown[]): Parameters;
|
|
18
|
-
declare function findValue(type: Exclude<FindValueType, 'item'>, array: unknown[], parameters: unknown[], reversed: boolean): number;
|
|
19
|
-
declare function findValue(type: Exclude<FindValueType, 'index'>, array: unknown[], parameters: unknown[], reversed: boolean): unknown;
|
|
20
|
-
declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
|
|
21
|
-
declare function findValues(type: FindValuesType, array: unknown[], parameters: unknown[], mapper?: FindMapper): FindValuesResult;
|
|
22
|
-
declare const FIND_VALUE_INDEX = "index";
|
|
23
|
-
declare const FIND_VALUE_ITEM = "item";
|
|
24
|
-
declare const FIND_VALUES_ALL: FindValuesType;
|
|
25
|
-
declare const FIND_VALUES_UNIQUE: FindValuesType;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { FIND_VALUES_ALL, FIND_VALUES_UNIQUE, FIND_VALUE_INDEX, FIND_VALUE_ITEM, createFindParameters, findAbsoluteValueOrDefault, findValue, findValues };
|
|
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;
|
|
20
|
+
export declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
|
|
21
|
+
export declare function findValues(type: FindValuesType, array: unknown[], parameters: unknown[], mapper?: FindMapper): FindValuesResult;
|
|
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;
|
|
26
|
+
//#endregion
|
|
@@ -12,7 +12,7 @@ import { NumericalKeys, PlainObject } from "../../models.mjs";
|
|
|
12
12
|
* getArray({a: 'a', b: 'b', c: 'c', d: 'd'}, true); // => []
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Value[NumericalKeys<Value>][];
|
|
15
|
+
export declare function getArray<Value extends PlainObject>(value: Value, indiced: true): Value[NumericalKeys<Value>][];
|
|
16
16
|
/**
|
|
17
17
|
* Get an array from a map
|
|
18
18
|
*
|
|
@@ -26,7 +26,7 @@ declare function getArray<Value extends PlainObject>(value: Value, indiced: true
|
|
|
26
26
|
* ); // => [['a', 1], ['b', 2], ['c', 3]]
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
declare function getArray<Key, Value>(map: Map<Key, Value>): [Key, Value][];
|
|
29
|
+
export declare function getArray<Key, Value>(map: Map<Key, Value>): [Key, Value][];
|
|
30
30
|
/**
|
|
31
31
|
* Get an array from an object
|
|
32
32
|
*
|
|
@@ -39,7 +39,7 @@ declare function getArray<Key, Value>(map: Map<Key, Value>): [Key, Value][];
|
|
|
39
39
|
* getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd']
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
declare function getArray<Value extends PlainObject>(value: Value): [keyof Value, Value[keyof Value]][];
|
|
42
|
+
export declare function getArray<Value extends PlainObject>(value: Value): [keyof Value, Value[keyof Value]][];
|
|
43
43
|
/**
|
|
44
44
|
* Get an array from a set
|
|
45
45
|
*
|
|
@@ -51,7 +51,7 @@ declare function getArray<Value extends PlainObject>(value: Value): [keyof Value
|
|
|
51
51
|
* getArray(new Set([123, 456, 789])); // => [123, 456, 789]
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
declare function getArray<Value>(set: Set<Value>): Value[];
|
|
54
|
+
export declare function getArray<Value>(set: Set<Value>): Value[];
|
|
55
55
|
/**
|
|
56
56
|
* Get an array from a value
|
|
57
57
|
*
|
|
@@ -63,7 +63,7 @@ declare function getArray<Value>(set: Set<Value>): Value[];
|
|
|
63
63
|
* getArray([123]); // => [123]
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
declare function getArray<Item>(value: Item[]): Item[];
|
|
66
|
+
export declare function getArray<Item>(value: Item[]): Item[];
|
|
67
67
|
/**
|
|
68
68
|
* Get an array from an unknown value
|
|
69
69
|
*
|
|
@@ -75,6 +75,5 @@ declare function getArray<Item>(value: Item[]): Item[];
|
|
|
75
75
|
* getArray(123); // => [123]
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
declare function getArray<Value>(value: Value): Value[];
|
|
79
|
-
//#endregion
|
|
80
|
-
export { getArray };
|
|
78
|
+
export declare function getArray<Value>(value: Value): Value[];
|
|
79
|
+
//#endregion
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Key } from "../../models.mjs";
|
|
2
2
|
//#region src/internal/array/group.d.ts
|
|
3
|
-
declare function groupValues(array: unknown[], key: unknown, value: unknown, arrays: boolean): Record<Key, unknown>;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { groupValues };
|
|
3
|
+
export declare function groupValues(array: unknown[], key: unknown, value: unknown, arrays: boolean): Record<Key, unknown>;
|
|
4
|
+
//#endregion
|
|
@@ -17,7 +17,7 @@ import { PlainObject } from "../../models.mjs";
|
|
|
17
17
|
* ); // => 1
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
declare function indexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
20
|
+
export declare function indexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
21
21
|
/**
|
|
22
22
|
* Get the index of the first matching item by key
|
|
23
23
|
*
|
|
@@ -35,7 +35,7 @@ declare function indexOf<Item, Callback extends (item: Item, index: number, arra
|
|
|
35
35
|
* ); // => 1
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
38
|
+
export declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
39
39
|
/**
|
|
40
40
|
* Get the index of the first item matching the filter
|
|
41
41
|
*
|
|
@@ -51,7 +51,7 @@ declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(a
|
|
|
51
51
|
* ); // => 1
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
declare function indexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
54
|
+
export declare function indexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
55
55
|
/**
|
|
56
56
|
* Get the index of the first item matching the given item
|
|
57
57
|
*
|
|
@@ -64,8 +64,8 @@ declare function indexOf<Item>(array: Item[], filter: (item: Item, index: number
|
|
|
64
64
|
* indexOf([1, 2, 3, 4, 5], 3); // => 2
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
|
-
declare function indexOf<Item>(array: Item[], item: Item): number;
|
|
68
|
-
declare namespace indexOf {
|
|
67
|
+
export declare function indexOf<Item>(array: Item[], item: Item): number;
|
|
68
|
+
export declare namespace indexOf {
|
|
69
69
|
var last: typeof lastIndexOf;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -87,7 +87,7 @@ declare namespace indexOf {
|
|
|
87
87
|
* ); // => 3
|
|
88
88
|
* ```
|
|
89
89
|
*/
|
|
90
|
-
declare function lastIndexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
90
|
+
export declare function lastIndexOf<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): number;
|
|
91
91
|
/**
|
|
92
92
|
* Get the index of the last matching item by key
|
|
93
93
|
*
|
|
@@ -107,7 +107,7 @@ declare function lastIndexOf<Item, Callback extends (item: Item, index: number,
|
|
|
107
107
|
* ); // => 3
|
|
108
108
|
* ```
|
|
109
109
|
*/
|
|
110
|
-
declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
110
|
+
export declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
111
111
|
/**
|
|
112
112
|
* Get the index of the last item matching the filter
|
|
113
113
|
*
|
|
@@ -125,7 +125,7 @@ declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
125
125
|
* ); // => 3
|
|
126
126
|
* ```
|
|
127
127
|
*/
|
|
128
|
-
declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
128
|
+
export declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number;
|
|
129
129
|
/**
|
|
130
130
|
* Get the index of the last item matching the given item
|
|
131
131
|
*
|
|
@@ -140,6 +140,5 @@ declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: nu
|
|
|
140
140
|
* lastIndexOf([1, 2, 3, 2, 1], 2); // => 3
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
|
-
declare function lastIndexOf<Item>(array: Item[], item: Item): number;
|
|
144
|
-
//#endregion
|
|
145
|
-
export { indexOf, lastIndexOf };
|
|
143
|
+
export declare function lastIndexOf<Item>(array: Item[], item: Item): number;
|
|
144
|
+
//#endregion
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//#region src/internal/array/insert.d.ts
|
|
2
2
|
type InsertType = 'insert' | 'push' | 'splice';
|
|
3
|
-
declare function insertValues(type: InsertType, array: unknown, items: unknown, start: unknown, deleteCount: number): unknown;
|
|
4
|
-
declare const INSERT_TYPE_INSERT: InsertType;
|
|
5
|
-
declare const INSERT_TYPE_PUSH: InsertType;
|
|
6
|
-
declare const INSERT_TYPE_SPLICE: InsertType;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { INSERT_TYPE_INSERT, INSERT_TYPE_PUSH, INSERT_TYPE_SPLICE, insertValues };
|
|
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;
|
|
7
|
+
//#endregion
|
|
@@ -3,7 +3,7 @@ import { PlainObject } from "../../models.mjs";
|
|
|
3
3
|
/**
|
|
4
4
|
* Comparison of an array within another array
|
|
5
5
|
*/
|
|
6
|
-
type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
|
|
6
|
+
export type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
|
|
7
7
|
/**
|
|
8
8
|
* Is the needle array at the end of the haystack array?
|
|
9
9
|
*
|
|
@@ -21,7 +21,7 @@ type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'star
|
|
|
21
21
|
* ); // => true
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
24
|
+
export declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
25
25
|
/**
|
|
26
26
|
* Is the needle array at the end of the haystack array?
|
|
27
27
|
*
|
|
@@ -39,7 +39,7 @@ declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback:
|
|
|
39
39
|
* ); // => true
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
42
|
+
export declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
43
43
|
/**
|
|
44
44
|
* Is the needle array at the end of the haystack array?
|
|
45
45
|
*
|
|
@@ -52,7 +52,7 @@ declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needl
|
|
|
52
52
|
* endsWithArray([1, 2, 3], [2, 3]); // => true
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
55
|
+
export declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
56
56
|
/**
|
|
57
57
|
* Get the position of an array within another array
|
|
58
58
|
*
|
|
@@ -70,7 +70,7 @@ declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
|
70
70
|
* ); // => 'end'
|
|
71
71
|
* ```
|
|
72
72
|
*/
|
|
73
|
-
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
|
|
73
|
+
export declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
|
|
74
74
|
/**
|
|
75
75
|
* Get the position of an array within another array
|
|
76
76
|
*
|
|
@@ -88,7 +88,7 @@ declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], call
|
|
|
88
88
|
* ); // => 'end'
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
|
|
91
|
+
export declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
|
|
92
92
|
/**
|
|
93
93
|
* Get the position of an array within another array
|
|
94
94
|
*
|
|
@@ -101,7 +101,7 @@ declare function getArrayComparison<Item extends PlainObject>(haystack: Item[],
|
|
|
101
101
|
* getArrayComparison([1, 2, 3], [2, 3]); // => 'end'
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
|
|
104
|
+
export declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
|
|
105
105
|
/**
|
|
106
106
|
* Does the needle array exist within the haystack array?
|
|
107
107
|
*
|
|
@@ -119,7 +119,7 @@ declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): Arr
|
|
|
119
119
|
* ); // => true
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
|
-
declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
122
|
+
export declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
123
123
|
/**
|
|
124
124
|
* Does the needle array exist within the haystack array?
|
|
125
125
|
*
|
|
@@ -137,7 +137,7 @@ declare function includesArray<Item>(haystack: Item[], needle: Item[], callback:
|
|
|
137
137
|
* ); // => true
|
|
138
138
|
* ```
|
|
139
139
|
*/
|
|
140
|
-
declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
140
|
+
export declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
141
141
|
/**
|
|
142
142
|
* Does the needle array exist within the haystack array?
|
|
143
143
|
*
|
|
@@ -150,7 +150,7 @@ declare function includesArray<Item extends PlainObject>(haystack: Item[], needl
|
|
|
150
150
|
* includesArray([1, 2, 3], [2, 3]); // => true
|
|
151
151
|
* ```
|
|
152
152
|
*/
|
|
153
|
-
declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
153
|
+
export declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
154
154
|
/**
|
|
155
155
|
* Get the index of an array within another array
|
|
156
156
|
*
|
|
@@ -168,7 +168,7 @@ declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
|
168
168
|
* ); // => 1
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
171
|
-
declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
|
|
171
|
+
export declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
|
|
172
172
|
/**
|
|
173
173
|
* Get the index of an array within another array
|
|
174
174
|
*
|
|
@@ -186,7 +186,7 @@ declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback:
|
|
|
186
186
|
* ); // => 1
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
|
-
declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
|
|
189
|
+
export declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
|
|
190
190
|
/**
|
|
191
191
|
* Get the index of an array within another array
|
|
192
192
|
*
|
|
@@ -199,7 +199,7 @@ declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle
|
|
|
199
199
|
* indexOfArray([1, 2, 3], [2, 3]); // => 1
|
|
200
200
|
* ```
|
|
201
201
|
*/
|
|
202
|
-
declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
|
|
202
|
+
export declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
|
|
203
203
|
/**
|
|
204
204
|
* Is the needle array at the start of the haystack array?
|
|
205
205
|
*
|
|
@@ -217,7 +217,7 @@ declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
|
|
|
217
217
|
* ); // => true
|
|
218
218
|
* ```
|
|
219
219
|
*/
|
|
220
|
-
declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
220
|
+
export declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
221
221
|
/**
|
|
222
222
|
* Is the needle array at the start of the haystack array?
|
|
223
223
|
*
|
|
@@ -235,7 +235,7 @@ declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callbac
|
|
|
235
235
|
* ); // => true
|
|
236
236
|
* ```
|
|
237
237
|
*/
|
|
238
|
-
declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
238
|
+
export declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
239
239
|
/**
|
|
240
240
|
* Is the needle array at the start of the haystack array?
|
|
241
241
|
*
|
|
@@ -248,6 +248,5 @@ declare function startsWithArray<Item extends PlainObject>(haystack: Item[], nee
|
|
|
248
248
|
* startsWithArray([1, 2, 3], [1, 2]); // => true
|
|
249
249
|
* ```
|
|
250
250
|
*/
|
|
251
|
-
declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
252
|
-
//#endregion
|
|
253
|
-
export { ArrayComparison, endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
|
|
251
|
+
export declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
252
|
+
//#endregion
|
|
@@ -8,6 +8,5 @@ type OverlapResult = {
|
|
|
8
8
|
second: OverlapItem;
|
|
9
9
|
overlap: boolean;
|
|
10
10
|
};
|
|
11
|
-
declare function arraysOverlap(first: OverlapItem, second: OverlapItem): OverlapResult;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { arraysOverlap };
|
|
11
|
+
export declare function arraysOverlap(first: OverlapItem, second: OverlapItem): OverlapResult;
|
|
12
|
+
//#endregion
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//#region src/internal/array/sets.d.ts
|
|
2
2
|
type CompareSetsType = 'difference' | 'intersection' | 'union';
|
|
3
|
-
declare function compareSets(type: CompareSetsType, first: unknown[], second: unknown[], key?: unknown): unknown[];
|
|
4
|
-
declare const SETS_COMPARE_DIFFERENCE: CompareSetsType;
|
|
5
|
-
declare const SETS_COMPARE_INTERSECTION: CompareSetsType;
|
|
6
|
-
declare const SETS_COMPARE_UNION: CompareSetsType;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { SETS_COMPARE_DIFFERENCE, SETS_COMPARE_INTERSECTION, SETS_COMPARE_UNION, compareSets };
|
|
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;
|
|
7
|
+
//#endregion
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
//#region src/internal/array/update.d.ts
|
|
2
|
-
declare function updateInArray(array: unknown[], items: unknown[], key: unknown, replace: boolean): unknown[];
|
|
3
|
-
//#endregion
|
|
4
|
-
export { updateInArray };
|
|
2
|
+
export declare function updateInArray(array: unknown[], items: unknown[], key: unknown, replace: boolean): unknown[];
|
|
3
|
+
//#endregion
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
//#region src/internal/defaults.d.ts
|
|
2
|
-
declare function getBooleanOrDefault(value: unknown, defaultValue: boolean): boolean;
|
|
3
|
-
declare function getNumberOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { getBooleanOrDefault, getNumberOrDefault };
|
|
2
|
+
export declare function getBooleanOrDefault(value: unknown, defaultValue: boolean): boolean;
|
|
3
|
+
export declare function getNumberOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
|
|
4
|
+
//#endregion
|
|
@@ -3,11 +3,11 @@ import { Constructor, NestedKeys, NestedValue, PlainObject } from "../../models.
|
|
|
3
3
|
/**
|
|
4
4
|
* Asserter for a property of a value
|
|
5
5
|
*/
|
|
6
|
-
type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted extends NestedPick<Value, Path> = NestedPick<Value, Path>> = Asserter<Asserted>;
|
|
6
|
+
export type AssertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted extends NestedPick<Value, Path> = NestedPick<Value, Path>> = Asserter<Asserted>;
|
|
7
7
|
/**
|
|
8
8
|
* A function that asserts a value is of a specific type, throwing an error if it is not
|
|
9
9
|
*/
|
|
10
|
-
type Asserter<Value> = (value: unknown) => asserts value is Value;
|
|
10
|
+
export type Asserter<Value> = (value: unknown) => asserts value is Value;
|
|
11
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
12
|
/**
|
|
13
13
|
* Asserts that a condition is true, throwing an error if it is not
|
|
@@ -16,8 +16,8 @@ type NestedPick<Value, Path extends string> = Value extends PlainObject ? Path e
|
|
|
16
16
|
* @param message Error message
|
|
17
17
|
* @param error Error constructor _(defaults to `Error`)_
|
|
18
18
|
*/
|
|
19
|
-
declare function assert<Condition extends () => boolean>(condition: Condition, message: string, error?: ErrorConstructor): asserts condition;
|
|
20
|
-
declare namespace assert {
|
|
19
|
+
export declare function assert<Condition extends () => boolean>(condition: Condition, message: string, error?: ErrorConstructor): asserts condition;
|
|
20
|
+
export declare namespace assert {
|
|
21
21
|
var condition: typeof assertCondition;
|
|
22
22
|
var defined: typeof assertDefined;
|
|
23
23
|
var instanceOf: typeof assertInstanceOf;
|
|
@@ -34,7 +34,7 @@ declare namespace assert {
|
|
|
34
34
|
* @param error Error constructor _(defaults to `Error`)_
|
|
35
35
|
* @returns _Asserter_
|
|
36
36
|
*/
|
|
37
|
-
declare function assertCondition<Value>(condition: (value: unknown) => boolean, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
37
|
+
export declare function assertCondition<Value>(condition: (value: unknown) => boolean, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
38
38
|
/**
|
|
39
39
|
* Asserts that a value is defined, throwing an error if it is not
|
|
40
40
|
*
|
|
@@ -44,7 +44,7 @@ declare function assertCondition<Value>(condition: (value: unknown) => boolean,
|
|
|
44
44
|
* @param message Error message
|
|
45
45
|
* @param error Error constructor _(defaults to `Error`)_
|
|
46
46
|
*/
|
|
47
|
-
declare function assertDefined<Value>(value: unknown, message?: string, error?: ErrorConstructor): asserts value is Exclude<Value, null | undefined>;
|
|
47
|
+
export declare function assertDefined<Value>(value: unknown, message?: string, error?: ErrorConstructor): asserts value is Exclude<Value, null | undefined>;
|
|
48
48
|
/**
|
|
49
49
|
* Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
50
50
|
*
|
|
@@ -55,7 +55,7 @@ declare function assertDefined<Value>(value: unknown, message?: string, error?:
|
|
|
55
55
|
* @param error Error constructor _(defaults to `Error`)_
|
|
56
56
|
* @returns _Asserter_
|
|
57
57
|
*/
|
|
58
|
-
declare function assertInstanceOf<Value>(constructor: Constructor<Value>, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
58
|
+
export declare function assertInstanceOf<Value>(constructor: Constructor<Value>, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
59
59
|
/**
|
|
60
60
|
* Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not
|
|
61
61
|
*
|
|
@@ -66,7 +66,7 @@ declare function assertInstanceOf<Value>(constructor: Constructor<Value>, messag
|
|
|
66
66
|
* @param error Error constructor _(defaults to `Error`)_
|
|
67
67
|
* @returns _Asserter_
|
|
68
68
|
*/
|
|
69
|
-
declare function assertIs<Value>(condition: (value: unknown) => value is Value, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
69
|
+
export declare function assertIs<Value>(condition: (value: unknown) => value is Value, message: string, error?: ErrorConstructor): Asserter<Value>;
|
|
70
70
|
/**
|
|
71
71
|
* Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
72
72
|
*
|
|
@@ -78,6 +78,5 @@ declare function assertIs<Value>(condition: (value: unknown) => value is Value,
|
|
|
78
78
|
* @param error Error constructor _(defaults to `Error`)_
|
|
79
79
|
* @returns _Asserter_
|
|
80
80
|
*/
|
|
81
|
-
declare function assertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted = NestedPick<Value, Path>>(path: Path, condition: (value: NestedValue<Value, Path>) => boolean, message: string, error?: ErrorConstructor): Asserter<Asserted>;
|
|
82
|
-
//#endregion
|
|
83
|
-
export { AssertProperty, Asserter, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty };
|
|
81
|
+
export declare function assertProperty<Value extends PlainObject, Path extends NestedKeys<Value>, Asserted = NestedPick<Value, Path>>(path: Path, condition: (value: NestedValue<Value, Path>) => boolean, message: string, error?: ErrorConstructor): Asserter<Asserted>;
|
|
82
|
+
//#endregion
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GenericAsyncCallback, GenericCallback } from "../../models.mjs";
|
|
2
|
+
//#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
|
+
export declare function getAsyncLimiter<Callback extends GenericAsyncCallback | GenericCallback>(type: LimiterType, callback: Callback, time?: number): AsyncLimiter<Callback>;
|
|
37
|
+
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
|
+
//#endregion
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { getNumberOrDefault } from "../defaults.mjs";
|
|
2
|
+
//#region src/internal/function/limit.ts
|
|
3
|
+
const LIMITER_NAME_ASYNC = "asyncLimiter";
|
|
4
|
+
const LIMITER_NAME_SYNC = "limiter";
|
|
5
|
+
const LIMITER_PROPERTY = "$limiter";
|
|
6
|
+
function AsyncLimiter(type, callback, time) {
|
|
7
|
+
Object.defineProperty(this, LIMITER_SYMBOL, { value: {
|
|
8
|
+
callback,
|
|
9
|
+
type,
|
|
10
|
+
interval: getNumberOrDefault(time, 0),
|
|
11
|
+
parameters: [],
|
|
12
|
+
throttle: type === LIMITER_THROTTLE
|
|
13
|
+
} });
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperties(AsyncLimiter.prototype, {
|
|
16
|
+
[LIMITER_PROPERTY]: { value: LIMITER_NAME_ASYNC },
|
|
17
|
+
cancel: { value: cancelAsyncLimiter },
|
|
18
|
+
run: { value: runAsyncLimiter }
|
|
19
|
+
});
|
|
20
|
+
function Limiter(type, callback, time) {
|
|
21
|
+
Object.defineProperty(this, LIMITER_SYMBOL, { value: {
|
|
22
|
+
callback,
|
|
23
|
+
type,
|
|
24
|
+
interval: getNumberOrDefault(time, 0),
|
|
25
|
+
parameters: [],
|
|
26
|
+
throttle: type === LIMITER_THROTTLE
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperties(Limiter.prototype, {
|
|
30
|
+
[LIMITER_PROPERTY]: { value: LIMITER_NAME_SYNC },
|
|
31
|
+
cancel: { value: cancelLimiter },
|
|
32
|
+
run: { value: runLimiter }
|
|
33
|
+
});
|
|
34
|
+
function cancelAsyncLimiter() {
|
|
35
|
+
const state = this[LIMITER_SYMBOL];
|
|
36
|
+
if (state.timer != null) clearTimer(state.timer);
|
|
37
|
+
if (state.last != null && !state.last.running) {
|
|
38
|
+
state.last.reject();
|
|
39
|
+
state.last = void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function cancelLimiter() {
|
|
43
|
+
const { timer } = this[LIMITER_SYMBOL];
|
|
44
|
+
if (timer != null) clearTimer(timer);
|
|
45
|
+
}
|
|
46
|
+
function getAsyncLimiter(type, callback, time) {
|
|
47
|
+
return new AsyncLimiter(type, callback, time);
|
|
48
|
+
}
|
|
49
|
+
function getLimiter(type, callback, time) {
|
|
50
|
+
return new Limiter(type, callback, time);
|
|
51
|
+
}
|
|
52
|
+
async function handleAsyncLimiter(state, item) {
|
|
53
|
+
const now = performance.now();
|
|
54
|
+
state.start ??= now;
|
|
55
|
+
if (state.interval === 0 || now - state.start >= state.interval - LIMITER_OFFSET) {
|
|
56
|
+
state.start = state.throttle ? now : void 0;
|
|
57
|
+
item.running = true;
|
|
58
|
+
try {
|
|
59
|
+
let result = state.callback(...item.parameters);
|
|
60
|
+
if (result instanceof Promise) result = await result;
|
|
61
|
+
item.resolve(result);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
item.reject(error);
|
|
64
|
+
} finally {
|
|
65
|
+
item.running = false;
|
|
66
|
+
}
|
|
67
|
+
} else state.timer = startTimer(() => handleAsyncLimiter(state, item));
|
|
68
|
+
}
|
|
69
|
+
function handleLimiter(state) {
|
|
70
|
+
const now = performance.now();
|
|
71
|
+
state.start ??= now;
|
|
72
|
+
if (state.interval === 0 || now - state.start >= state.interval - LIMITER_OFFSET) {
|
|
73
|
+
state.start = state.throttle ? now : void 0;
|
|
74
|
+
state.callback(...state.parameters);
|
|
75
|
+
} else state.timer = startTimer(() => handleLimiter(state));
|
|
76
|
+
}
|
|
77
|
+
function runAsyncLimiter() {
|
|
78
|
+
const state = this[LIMITER_SYMBOL];
|
|
79
|
+
cancelAsyncLimiter.call(this);
|
|
80
|
+
const next = {
|
|
81
|
+
parameters: state.parameters,
|
|
82
|
+
running: false
|
|
83
|
+
};
|
|
84
|
+
next.promise = new Promise((resolve, reject) => {
|
|
85
|
+
next.reject = reject;
|
|
86
|
+
next.resolve = resolve;
|
|
87
|
+
});
|
|
88
|
+
state.last = next;
|
|
89
|
+
if (state.throttle) handleAsyncLimiter(state, next);
|
|
90
|
+
else state.timer = startTimer(() => handleAsyncLimiter(state, next));
|
|
91
|
+
return next.promise;
|
|
92
|
+
}
|
|
93
|
+
function runLimiter(...parameters) {
|
|
94
|
+
const state = this[LIMITER_SYMBOL];
|
|
95
|
+
cancelLimiter.call(this);
|
|
96
|
+
state.parameters = parameters;
|
|
97
|
+
if (state.throttle) handleLimiter(state);
|
|
98
|
+
else state.timer = startTimer(() => handleLimiter(state));
|
|
99
|
+
}
|
|
100
|
+
const LIMITER_DEBOUNCE = "debounce";
|
|
101
|
+
const LIMITER_OFFSET = 5;
|
|
102
|
+
const LIMITER_SYMBOL = Symbol("limiter");
|
|
103
|
+
const LIMITER_THROTTLE = "throttle";
|
|
104
|
+
const LIMITER_WAIT = "wait";
|
|
105
|
+
// istanbul ignore next
|
|
106
|
+
const clearTimer = typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : clearTimeout;
|
|
107
|
+
// istanbul ignore next
|
|
108
|
+
const startTimer = typeof requestAnimationFrame === "function" ? requestAnimationFrame : setTimeout;
|
|
109
|
+
//#endregion
|
|
110
|
+
export { LIMITER_DEBOUNCE, LIMITER_THROTTLE, LIMITER_WAIT, getAsyncLimiter, getLimiter };
|