@dereekb/util 13.0.7 → 13.2.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/fetch/package.json +2 -2
- package/index.cjs.js +4107 -1516
- package/index.esm.js +4107 -1516
- package/package.json +1 -2
- package/src/lib/array/array.d.ts +92 -47
- package/src/lib/array/array.find.d.ts +14 -18
- package/src/lib/array/array.index.d.ts +43 -14
- package/src/lib/array/array.indexed.d.ts +66 -17
- package/src/lib/array/array.limit.d.ts +11 -0
- package/src/lib/array/array.make.d.ts +9 -3
- package/src/lib/array/array.map.d.ts +20 -8
- package/src/lib/array/array.number.d.ts +63 -5
- package/src/lib/array/array.random.d.ts +12 -9
- package/src/lib/array/array.set.d.ts +24 -1
- package/src/lib/array/array.string.d.ts +104 -0
- package/src/lib/array/array.unique.d.ts +60 -8
- package/src/lib/array/array.value.d.ts +20 -11
- package/src/lib/assertion/assertion.d.ts +30 -2
- package/src/lib/assertion/assertion.generic.d.ts +8 -0
- package/src/lib/assertion/assertion.number.d.ts +16 -0
- package/src/lib/auth/auth.role.claims.d.ts +14 -8
- package/src/lib/boolean.d.ts +54 -1
- package/src/lib/contact/domain.d.ts +22 -4
- package/src/lib/contact/random.d.ts +24 -0
- package/src/lib/date/date.d.ts +8 -13
- package/src/lib/date/hour.d.ts +51 -32
- package/src/lib/date/minute.d.ts +4 -4
- package/src/lib/date/time.d.ts +12 -3
- package/src/lib/date/week.d.ts +77 -10
- package/src/lib/error/error.d.ts +54 -3
- package/src/lib/error/error.server.d.ts +25 -2
- package/src/lib/filter/filter.d.ts +12 -7
- package/src/lib/function/function.boolean.d.ts +4 -4
- package/src/lib/function/function.d.ts +2 -5
- package/src/lib/function/function.forward.d.ts +19 -3
- package/src/lib/getter/getter.cache.d.ts +9 -5
- package/src/lib/getter/getter.d.ts +39 -22
- package/src/lib/getter/getter.map.d.ts +10 -4
- package/src/lib/getter/getter.util.d.ts +3 -3
- package/src/lib/grouping.d.ts +98 -31
- package/src/lib/hash.d.ts +15 -8
- package/src/lib/iterable/iterable.d.ts +62 -50
- package/src/lib/iterable/iterable.map.d.ts +4 -4
- package/src/lib/iterate.d.ts +17 -1
- package/src/lib/key.d.ts +32 -10
- package/src/lib/lifecycle.d.ts +10 -1
- package/src/lib/map/map.d.ts +17 -16
- package/src/lib/map/map.intersection.d.ts +5 -4
- package/src/lib/map/map.key.d.ts +16 -15
- package/src/lib/misc/host.d.ts +6 -3
- package/src/lib/model/id.batch.d.ts +7 -3
- package/src/lib/model/id.factory.d.ts +16 -1
- package/src/lib/model/model.conversion.d.ts +49 -6
- package/src/lib/model/model.conversion.field.d.ts +13 -3
- package/src/lib/model/model.copy.d.ts +11 -0
- package/src/lib/model/model.d.ts +174 -1
- package/src/lib/model/model.modify.d.ts +24 -5
- package/src/lib/nodejs/stream.d.ts +8 -6
- package/src/lib/number/bitwise.dencoder.d.ts +43 -3
- package/src/lib/number/bound.d.ts +34 -5
- package/src/lib/number/dollar.d.ts +13 -6
- package/src/lib/number/factory.d.ts +11 -3
- package/src/lib/number/number.d.ts +55 -32
- package/src/lib/number/random.d.ts +13 -3
- package/src/lib/number/round.d.ts +47 -26
- package/src/lib/number/sort.d.ts +7 -1
- package/src/lib/number/transform.d.ts +16 -0
- package/src/lib/object/object.array.d.ts +16 -2
- package/src/lib/object/object.array.delta.d.ts +6 -2
- package/src/lib/object/object.d.ts +33 -5
- package/src/lib/object/object.empty.d.ts +4 -2
- package/src/lib/object/object.equal.d.ts +21 -4
- package/src/lib/object/object.filter.tuple.d.ts +105 -3
- package/src/lib/object/object.key.d.ts +13 -6
- package/src/lib/object/object.map.d.ts +30 -19
- package/src/lib/page/page.d.ts +21 -0
- package/src/lib/page/page.filter.d.ts +16 -9
- package/src/lib/path/path.d.ts +101 -14
- package/src/lib/path/path.tree.d.ts +16 -0
- package/src/lib/promise/callback.d.ts +18 -0
- package/src/lib/promise/is.d.ts +10 -3
- package/src/lib/promise/map.d.ts +5 -3
- package/src/lib/promise/poll.d.ts +14 -4
- package/src/lib/promise/promise.d.ts +84 -18
- package/src/lib/promise/promise.factory.d.ts +18 -2
- package/src/lib/promise/promise.limit.d.ts +22 -2
- package/src/lib/promise/promise.loop.d.ts +69 -1
- package/src/lib/promise/promise.ref.d.ts +14 -2
- package/src/lib/promise/promise.task.d.ts +8 -4
- package/src/lib/promise/promise.type.d.ts +4 -4
- package/src/lib/promise/use.d.ts +6 -4
- package/src/lib/promise/wait.d.ts +5 -2
- package/src/lib/relation/relation.d.ts +98 -0
- package/src/lib/service/handler.config.d.ts +47 -9
- package/src/lib/service/handler.d.ts +43 -1
- package/src/lib/service/typed.service.d.ts +21 -2
- package/src/lib/set/set.allowed.d.ts +6 -4
- package/src/lib/set/set.d.ts +174 -46
- package/src/lib/set/set.decision.d.ts +4 -2
- package/src/lib/set/set.delta.d.ts +16 -3
- package/src/lib/set/set.hashset.d.ts +43 -0
- package/src/lib/set/set.selection.d.ts +7 -3
- package/src/lib/sort.d.ts +36 -16
- package/src/lib/string/char.d.ts +48 -34
- package/src/lib/string/dencoder.d.ts +84 -13
- package/src/lib/string/factory.d.ts +13 -4
- package/src/lib/string/html.d.ts +7 -6
- package/src/lib/string/mimetype.d.ts +65 -1
- package/src/lib/string/prefix.d.ts +21 -7
- package/src/lib/string/record.d.ts +7 -4
- package/src/lib/string/replace.d.ts +77 -33
- package/src/lib/string/search.d.ts +19 -9
- package/src/lib/string/sort.d.ts +10 -1
- package/src/lib/string/string.d.ts +74 -21
- package/src/lib/string/transform.d.ts +7 -0
- package/src/lib/string/tree.d.ts +91 -29
- package/src/lib/string/url.d.ts +148 -63
- package/src/lib/tree/tree.explore.d.ts +84 -17
- package/src/lib/tree/tree.flatten.d.ts +44 -7
- package/src/lib/type.d.ts +15 -12
- package/src/lib/value/address.d.ts +66 -17
- package/src/lib/value/bound.d.ts +253 -17
- package/src/lib/value/build.d.ts +30 -5
- package/src/lib/value/comparator.d.ts +53 -25
- package/src/lib/value/cron.d.ts +14 -6
- package/src/lib/value/decision.d.ts +57 -13
- package/src/lib/value/equal.d.ts +44 -13
- package/src/lib/value/indexed.d.ts +253 -82
- package/src/lib/value/label.d.ts +16 -5
- package/src/lib/value/map.d.ts +77 -20
- package/src/lib/value/maybe.d.ts +47 -49
- package/src/lib/value/modifier.d.ts +82 -27
- package/src/lib/value/point.d.ts +248 -54
- package/src/lib/value/url.d.ts +10 -3
- package/src/lib/value/use.d.ts +99 -8
- package/src/lib/value/vector.d.ts +71 -9
- package/test/index.cjs.js +86 -23
- package/test/index.esm.js +86 -23
- package/test/package.json +2 -2
- package/test/src/lib/shared/shared.d.ts +31 -5
- package/test/src/lib/shared/shared.fail.d.ts +72 -9
- package/test/src/lib/shared/shared.function.d.ts +40 -2
- package/test/src/lib/shared/shared.wrap.d.ts +20 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/util",
|
|
3
|
-
"version": "13.0
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"exports": {
|
|
5
5
|
"./test": {
|
|
6
6
|
"module": "./test/index.esm.js",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"ts-essentials": "^10.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"class-validator": "^0.15.1",
|
|
33
32
|
"date-fns": "4.0.0"
|
|
34
33
|
},
|
|
35
34
|
"module": "./index.esm.js",
|
package/src/lib/array/array.d.ts
CHANGED
|
@@ -1,106 +1,149 @@
|
|
|
1
1
|
import { type IterableOrValue } from '../iterable/iterable';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
|
+
/**
|
|
4
|
+
* An array type that cannot contain any elements.
|
|
5
|
+
*/
|
|
3
6
|
export type EmptyArray = never[];
|
|
7
|
+
/**
|
|
8
|
+
* A value that is either a single item of type T or an array of T items.
|
|
9
|
+
*/
|
|
4
10
|
export type ArrayOrValue<T> = T | T[];
|
|
5
11
|
/**
|
|
6
|
-
* Converts the input value to an array containing itself, or returns itself if it is a non-empty array.
|
|
12
|
+
* Converts the input value to an array containing itself, or returns itself if it is a non-empty array. Returns undefined if the input is nullish or results in an empty array.
|
|
7
13
|
*
|
|
8
|
-
* @param arrayOrValue
|
|
9
|
-
* @returns
|
|
14
|
+
* @param arrayOrValue - single value or array to convert
|
|
15
|
+
* @returns an array with at least one element, or undefined if the result would be empty
|
|
10
16
|
*/
|
|
11
17
|
export declare function convertMaybeToNonEmptyArray<T>(arrayOrValue: Maybe<ArrayOrValue<T>>): Maybe<T[]>;
|
|
12
18
|
/**
|
|
13
|
-
* Converts the input value to an array containing itself, or returns itself if it is an array.
|
|
19
|
+
* Converts the input value to an array containing itself, or returns itself if it is an array. Returns an empty array if the input is nullish.
|
|
14
20
|
*
|
|
15
|
-
* @param arrayOrValue
|
|
16
|
-
* @returns
|
|
21
|
+
* @param arrayOrValue - single value, array, or nullish value to convert
|
|
22
|
+
* @returns the input wrapped in an array, the input array itself, or an empty array if nullish
|
|
17
23
|
*/
|
|
18
24
|
export declare function convertMaybeToArray<T>(arrayOrValue: Maybe<ArrayOrValue<T>>): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Alias for {@link convertMaybeToArray}. Converts a maybe value or array into an array, returning an empty array for nullish input.
|
|
27
|
+
*/
|
|
19
28
|
export declare const asArray: typeof convertMaybeToArray;
|
|
29
|
+
/**
|
|
30
|
+
* Alias for {@link convertMaybeToNonEmptyArray}. Converts a maybe value or array into a non-empty array, returning undefined for nullish or empty input.
|
|
31
|
+
*/
|
|
20
32
|
export declare const asNonEmptyArray: typeof convertMaybeToNonEmptyArray;
|
|
21
33
|
/**
|
|
22
|
-
* Converts the input value to an array containing itself, or returns itself if it is an array.
|
|
34
|
+
* Converts the input value to an array containing itself, or returns itself if it is already an array.
|
|
23
35
|
*
|
|
24
|
-
* @param arrayOrValue
|
|
25
|
-
* @returns
|
|
36
|
+
* @param arrayOrValue - single value or array to convert
|
|
37
|
+
* @returns the input array unchanged, or a new single-element array wrapping the input value
|
|
26
38
|
*/
|
|
27
39
|
export declare function convertToArray<T>(arrayOrValue: ArrayOrValue<T>): T[];
|
|
28
40
|
/**
|
|
29
|
-
* Returns the first value from the array.
|
|
41
|
+
* Returns the first value from the array, or the value itself if not an array.
|
|
42
|
+
*
|
|
43
|
+
* @param input - single value or array to retrieve from
|
|
44
|
+
* @returns the first element of the array, or the input value itself
|
|
30
45
|
*/
|
|
31
46
|
export declare function firstValue<T>(input: ArrayOrValue<T>): T;
|
|
32
47
|
/**
|
|
33
|
-
* Returns the last value from the array.
|
|
48
|
+
* Returns the last value from the array, or the value itself if not an array.
|
|
49
|
+
*
|
|
50
|
+
* @param input - single value or array to retrieve from
|
|
51
|
+
* @returns the last element of the array, or the input value itself
|
|
34
52
|
*/
|
|
35
53
|
export declare function lastValue<T>(input: ArrayOrValue<T>): T;
|
|
36
54
|
/**
|
|
37
55
|
* Returns a tuple with the first and last value of the input.
|
|
38
56
|
*
|
|
39
|
-
* If the input is not an array, returns that value as the first and last value.
|
|
57
|
+
* If the input is not an array, returns that value as both the first and last value.
|
|
40
58
|
*
|
|
41
|
-
* @param input
|
|
42
|
-
* @returns
|
|
59
|
+
* @param input - single value or array to retrieve from
|
|
60
|
+
* @returns a two-element tuple of the first and last values
|
|
43
61
|
*/
|
|
44
62
|
export declare function firstAndLastValue<T>(input: ArrayOrValue<T>): [T, T];
|
|
63
|
+
/**
|
|
64
|
+
* Returns the value at the given index from an array, or the value itself if not an array.
|
|
65
|
+
*
|
|
66
|
+
* @param input - single value or array to retrieve from
|
|
67
|
+
* @param index - zero-based index of the element to retrieve
|
|
68
|
+
* @returns the element at the specified index, or the input value itself if not an array
|
|
69
|
+
*/
|
|
45
70
|
export declare function valueAtIndex<T>(input: ArrayOrValue<T>, index: number): T;
|
|
46
71
|
/**
|
|
47
|
-
*
|
|
72
|
+
* Concatenates the input arrays into a single array, filtering out nullish entries.
|
|
73
|
+
*
|
|
74
|
+
* @param arrays - arrays to concatenate; nullish entries are ignored
|
|
75
|
+
* @returns a single flattened array containing all elements from the non-nullish input arrays
|
|
48
76
|
*/
|
|
49
77
|
export declare function concatArrays<T>(...arrays: Maybe<T[]>[]): T[];
|
|
50
78
|
/**
|
|
51
|
-
* Flattens a two
|
|
79
|
+
* Flattens a two-dimensional array into a single-dimensional array. Any null/undefined entries in the outer dimension are filtered out.
|
|
52
80
|
*
|
|
53
|
-
* @param array
|
|
54
|
-
* @returns
|
|
81
|
+
* @param array - two-dimensional array to flatten, may contain nullish entries
|
|
82
|
+
* @returns a single-dimensional array with all elements from the non-nullish inner arrays
|
|
55
83
|
*/
|
|
56
84
|
export declare function flattenArray<T>(array: Maybe<T[]>[]): T[];
|
|
57
85
|
/**
|
|
58
|
-
* Flattens an array of ArrayOrValue
|
|
86
|
+
* Flattens an array of {@link ArrayOrValue} entries into a single array. Nullish entries are filtered out.
|
|
59
87
|
*
|
|
60
|
-
* @param array
|
|
61
|
-
* @returns
|
|
88
|
+
* @param array - array of single values or arrays to flatten
|
|
89
|
+
* @returns a single flat array containing all non-nullish elements
|
|
62
90
|
*/
|
|
63
91
|
export declare function flattenArrayOrValueArray<T>(array: ArrayOrValue<Maybe<T>>[]): T[];
|
|
92
|
+
/**
|
|
93
|
+
* Creates a shallow copy of the input array. Returns an empty array if the input is nullish.
|
|
94
|
+
*
|
|
95
|
+
* @param input - array to copy, or nullish
|
|
96
|
+
* @returns a new array with the same elements, or an empty array if input is nullish
|
|
97
|
+
*/
|
|
64
98
|
export declare function copyArray<T>(input: Maybe<T[]>): T[];
|
|
99
|
+
/**
|
|
100
|
+
* Pushes the same element onto the target array a specified number of times.
|
|
101
|
+
*
|
|
102
|
+
* @param target - array to push elements into
|
|
103
|
+
* @param element - element to push
|
|
104
|
+
* @param times - number of times to push the element
|
|
105
|
+
* @returns the mutated target array
|
|
106
|
+
*/
|
|
65
107
|
export declare function pushElementOntoArray<T>(target: T[], element: T, times: number): T[];
|
|
66
108
|
/**
|
|
67
|
-
* Merges all input arrays into a single array.
|
|
109
|
+
* Merges all input arrays into a single new array. Nullish entries are ignored.
|
|
68
110
|
*
|
|
69
|
-
* @param arrays
|
|
70
|
-
* @returns
|
|
111
|
+
* @param arrays - arrays to merge; nullish entries are skipped
|
|
112
|
+
* @returns a new array containing all elements from the provided arrays
|
|
71
113
|
*/
|
|
72
114
|
export declare function mergeArrays<T>(arrays: Maybe<T[]>[]): T[];
|
|
73
115
|
/**
|
|
74
|
-
* Merges the input arrays into the target array by pushing each item from each array. Creates an empty array if the target is
|
|
116
|
+
* Merges the input arrays into the target array by pushing each item from each array. Creates an empty array if the target is nullish.
|
|
75
117
|
*
|
|
76
|
-
* @param target
|
|
77
|
-
* @param arrays
|
|
78
|
-
* @returns
|
|
118
|
+
* @param target - array to merge into; a new array is created if nullish
|
|
119
|
+
* @param arrays - arrays whose elements are pushed into the target; nullish entries are skipped
|
|
120
|
+
* @returns the mutated target array, or a new array if the target was nullish
|
|
79
121
|
*/
|
|
80
122
|
export declare function mergeArraysIntoArray<T>(target: Maybe<T[]>, ...arrays: Maybe<T[]>[]): T[];
|
|
81
123
|
/**
|
|
82
|
-
* Pushes the input value into the target array if it is not an array. If it is an array,
|
|
124
|
+
* Pushes the input value into the target array if it is not an array. If it is an array, pushes all of its elements into the target array.
|
|
83
125
|
*
|
|
84
|
-
* @param target
|
|
85
|
-
* @param value
|
|
86
|
-
* @returns
|
|
126
|
+
* @param target - array to push into
|
|
127
|
+
* @param value - single value or array of values to add
|
|
128
|
+
* @returns the mutated target array
|
|
87
129
|
*/
|
|
88
130
|
export declare function pushItemOrArrayItemsIntoArray<T>(target: T[], value: ArrayOrValue<T>): T[];
|
|
89
131
|
/**
|
|
90
|
-
* Merges all
|
|
132
|
+
* Merges all elements from the source array into the target array using push.
|
|
91
133
|
*
|
|
92
134
|
* This is preferable in cases where immutability is not required.
|
|
93
135
|
*
|
|
94
|
-
* @param target
|
|
95
|
-
* @param array
|
|
136
|
+
* @param target - array to push elements into
|
|
137
|
+
* @param array - source array whose elements are pushed into the target
|
|
138
|
+
* @returns the mutated target array
|
|
96
139
|
*/
|
|
97
140
|
export declare function pushArrayItemsIntoArray<T>(target: T[], array: T[]): T[];
|
|
98
141
|
/**
|
|
99
|
-
* Copies/takes the elements from the front of the array up to the
|
|
142
|
+
* Copies/takes the elements from the front of the array up to the specified maximum.
|
|
100
143
|
*
|
|
101
|
-
* @param values
|
|
102
|
-
* @param maxToTake
|
|
103
|
-
* @returns
|
|
144
|
+
* @param values - source array to take from
|
|
145
|
+
* @param maxToTake - maximum number of elements to take from the front
|
|
146
|
+
* @returns a new array containing at most maxToTake elements from the front
|
|
104
147
|
*/
|
|
105
148
|
export declare function takeFront<T>(values: T[], maxToTake: number): T[];
|
|
106
149
|
/**
|
|
@@ -138,23 +181,25 @@ export declare function splitFront<T>(values: T[], maxToTake: number): SplitFron
|
|
|
138
181
|
*/
|
|
139
182
|
export declare function takeLast<T>(values: T[], maxToTake: number, keepFromFront?: number): T[];
|
|
140
183
|
/**
|
|
141
|
-
* Performs forEach
|
|
184
|
+
* Performs a forEach iteration over the input and returns the resulting array. If the input is nullish, returns an empty array.
|
|
142
185
|
*
|
|
143
|
-
* @param array
|
|
144
|
-
* @param forEach
|
|
145
|
-
* @returns
|
|
186
|
+
* @param array - single value, array, or nullish value to iterate over
|
|
187
|
+
* @param forEach - callback invoked for each element
|
|
188
|
+
* @returns the array that was iterated over, or an empty array if the input was nullish
|
|
146
189
|
*/
|
|
147
190
|
export declare function forEachWithArray<T>(array: Maybe<ArrayOrValue<T>>, forEach: (value: T) => void): T[];
|
|
148
191
|
/**
|
|
149
|
-
* Counts all
|
|
192
|
+
* Counts the total number of elements across all inner arrays of a nested array.
|
|
150
193
|
*
|
|
151
|
-
* @param array
|
|
152
|
-
* @returns
|
|
194
|
+
* @param array - two-dimensional array whose elements are counted
|
|
195
|
+
* @returns the total number of elements across all inner arrays
|
|
153
196
|
*/
|
|
154
197
|
export declare function countAllInNestedArray<T>(array: T[][]): number;
|
|
155
198
|
/**
|
|
156
199
|
* Creates a copy of the array with the items at the specified indexes removed.
|
|
157
200
|
*
|
|
158
|
-
* @param array
|
|
201
|
+
* @param array - source array to copy from
|
|
202
|
+
* @param removeIndexes - indexes of elements to exclude from the copy
|
|
203
|
+
* @returns a new array without the elements at the specified indexes
|
|
159
204
|
*/
|
|
160
205
|
export declare function removeValuesAtIndexesFromArrayCopy<T>(array: T[], removeIndexes: IterableOrValue<number>): T[];
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { type SetIncludesMode } from '../set/set.mode';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Similar to the predicate function in Array.prototype.find() or Array.prototype.filter().
|
|
5
|
-
* @template T - The type of elements in the array
|
|
3
|
+
* Predicate function that tests an individual array element, similar to the callback used by {@link Array.prototype.find} or {@link Array.prototype.filter}.
|
|
6
4
|
*/
|
|
7
5
|
export type ArrayFindDecisionFunction<T> = (value: T, index: number, obj: T[]) => boolean;
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of elements in the array
|
|
7
|
+
* Preconfigured function that evaluates an array and returns whether its elements satisfy a decision criterion based on a {@link SetIncludesMode}.
|
|
12
8
|
*/
|
|
13
9
|
export type ArrayDecisionFunction<T> = (values: T[]) => boolean;
|
|
14
10
|
/**
|
|
15
|
-
* Creates an ArrayDecisionFunction
|
|
11
|
+
* Creates an {@link ArrayDecisionFunction} from a per-element predicate and a {@link SetIncludesMode}.
|
|
12
|
+
*
|
|
13
|
+
* When mode is `'any'`, the resulting function returns `true` if at least one element satisfies the predicate.
|
|
14
|
+
* When mode is `'all'`, it returns `true` only if every element satisfies the predicate.
|
|
16
15
|
*
|
|
17
|
-
* @
|
|
18
|
-
* @param
|
|
19
|
-
* @
|
|
20
|
-
* @returns A function that takes an array and returns a boolean decision based on the array elements
|
|
16
|
+
* @param decision - Predicate used to test individual elements.
|
|
17
|
+
* @param mode - Whether all or any elements must satisfy the predicate.
|
|
18
|
+
* @returns A function that evaluates an array against the configured decision criteria.
|
|
21
19
|
*/
|
|
22
20
|
export declare function arrayDecisionFunction<T>(decision: ArrayFindDecisionFunction<T>, mode: SetIncludesMode): ArrayDecisionFunction<T>;
|
|
23
21
|
/**
|
|
24
|
-
*
|
|
25
|
-
* A convenience function that creates and immediately applies an array decision function.
|
|
22
|
+
* Convenience wrapper that creates and immediately invokes an {@link ArrayDecisionFunction}.
|
|
26
23
|
*
|
|
27
|
-
* @
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
31
|
-
* @returns A boolean indicating whether the array meets the decision criteria
|
|
24
|
+
* @param values - Array to evaluate.
|
|
25
|
+
* @param decision - Predicate used to test individual elements.
|
|
26
|
+
* @param mode - Whether all or any elements must satisfy the predicate.
|
|
27
|
+
* @returns `true` if the array satisfies the decision criteria for the given mode.
|
|
32
28
|
*/
|
|
33
29
|
export declare function arrayDecision<T>(values: T[], decision: ArrayFindDecisionFunction<T>, mode: SetIncludesMode): boolean;
|
|
@@ -2,41 +2,70 @@ import { type AscendingSortCompareFunction } from '../sort';
|
|
|
2
2
|
import { type IndexNumber, type IndexRef, type IndexRangeInput } from '../value/indexed';
|
|
3
3
|
import { type Maybe } from '../value/maybe.type';
|
|
4
4
|
/**
|
|
5
|
-
* A set of
|
|
5
|
+
* A set of index numbers corresponding to items in an array.
|
|
6
6
|
*
|
|
7
|
-
* This is useful for cases where you need
|
|
7
|
+
* This is useful for cases where you need to reference items by their position in the array.
|
|
8
8
|
*/
|
|
9
9
|
export type IndexSet = IndexNumber[];
|
|
10
|
+
/**
|
|
11
|
+
* An array of {@link IndexSetPair} values, associating array items with their indices.
|
|
12
|
+
*/
|
|
10
13
|
export type IndexSetPairSet<T> = IndexSetPair<T>[];
|
|
14
|
+
/**
|
|
15
|
+
* Pairs an array item with its index position.
|
|
16
|
+
*/
|
|
11
17
|
export interface IndexSetPair<T> extends IndexRef {
|
|
18
|
+
/** The item at the index, or undefined if no item exists at that position. */
|
|
12
19
|
item: Maybe<T>;
|
|
13
20
|
}
|
|
14
21
|
/**
|
|
15
|
-
* Runs a filter on an array and returns an IndexSet
|
|
22
|
+
* Runs a filter on an array and returns an {@link IndexSet} containing the indices of values that match.
|
|
16
23
|
*
|
|
17
|
-
* @param input
|
|
18
|
-
* @param filter
|
|
19
|
-
* @returns
|
|
24
|
+
* @param input - array to search through
|
|
25
|
+
* @param filter - predicate function to test each value
|
|
26
|
+
* @returns an {@link IndexSet} of indices for matching values
|
|
20
27
|
*/
|
|
21
28
|
export declare function findToIndexSet<T>(input: T[], filter: (value: T) => boolean): IndexSet;
|
|
29
|
+
/**
|
|
30
|
+
* Expands an {@link IndexSet} into an {@link IndexSetPairSet} by pairing each index with the corresponding item from the input array.
|
|
31
|
+
*
|
|
32
|
+
* @param input - source array to retrieve items from
|
|
33
|
+
* @param indexSet - set of indices to expand
|
|
34
|
+
* @returns an {@link IndexSetPairSet} pairing each index with its corresponding item
|
|
35
|
+
*/
|
|
22
36
|
export declare function expandIndexSet<T>(input: T[], indexSet: IndexSet): IndexSetPairSet<T>;
|
|
23
37
|
/**
|
|
24
|
-
* Finds the best item in the input array using the compare function, and returns an IndexSetPair value.
|
|
38
|
+
* Finds the best item in the input array using the compare function, and returns an {@link IndexSetPair} value.
|
|
25
39
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
40
|
+
* The comparison follows ascending sort conventions: a negative return value from the compare function
|
|
41
|
+
* indicates the second argument is "better" than the first.
|
|
42
|
+
*
|
|
43
|
+
* @param input - array of items to search through
|
|
44
|
+
* @param compare - comparison function used to determine the best item
|
|
45
|
+
* @returns an {@link IndexSetPair} containing the best item and its index
|
|
28
46
|
*/
|
|
29
47
|
export declare function findBest<T>(input: T[], compare: (a: T, b: T) => number): IndexSetPair<T>;
|
|
30
48
|
/**
|
|
31
|
-
* Finds the best item in the input IndexSetPairSet, and returns it.
|
|
49
|
+
* Finds the best item in the input {@link IndexSetPairSet} using the compare function, and returns it.
|
|
50
|
+
*
|
|
51
|
+
* Pairs with null/undefined items are skipped in favor of pairs with defined items.
|
|
32
52
|
*
|
|
33
|
-
* @param input
|
|
34
|
-
* @param compare
|
|
35
|
-
* @returns
|
|
53
|
+
* @param input - set of index-item pairs to search through
|
|
54
|
+
* @param compare - ascending sort comparison function used to determine the best item
|
|
55
|
+
* @returns the {@link IndexSetPair} containing the best item
|
|
36
56
|
*/
|
|
37
57
|
export declare function findBestIndexSetPair<T>(input: IndexSetPairSet<T>, compare: AscendingSortCompareFunction<T>): IndexSetPair<T>;
|
|
38
58
|
/**
|
|
39
|
-
*
|
|
59
|
+
* A function that slices a pre-configured index range from an input array.
|
|
60
|
+
*
|
|
61
|
+
* @param input - array to slice
|
|
62
|
+
* @returns the sliced portion of the array
|
|
40
63
|
*/
|
|
41
64
|
export type SliceIndexRangeFunction<T> = (input: T[]) => T[];
|
|
65
|
+
/**
|
|
66
|
+
* Creates a {@link SliceIndexRangeFunction} that slices the specified index range from any input array.
|
|
67
|
+
*
|
|
68
|
+
* @param inputRange - the index range configuration to use for slicing
|
|
69
|
+
* @returns a function that slices the configured range from an input array
|
|
70
|
+
*/
|
|
42
71
|
export declare function sliceIndexRangeFunction<T>(inputRange: IndexRangeInput): SliceIndexRangeFunction<T>;
|
|
@@ -2,59 +2,108 @@ import { type IndexNumber, type IndexRange, type ReadIndexRangeFunction } from '
|
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
3
|
import { type ArrayFindDecisionFunction } from './array.find';
|
|
4
4
|
/**
|
|
5
|
-
* Creates an IndexRange for the input array.
|
|
5
|
+
* Creates an IndexRange for the input array, spanning from index 0 to the array's length.
|
|
6
6
|
*
|
|
7
|
-
* @param array
|
|
8
|
-
* @returns
|
|
7
|
+
* @param array - The array to create an index range for.
|
|
8
|
+
* @returns An IndexRange covering the full extent of the array.
|
|
9
9
|
*/
|
|
10
10
|
export declare function indexRangeForArray<T>(array: T[]): IndexRange;
|
|
11
11
|
/**
|
|
12
|
-
* Finds a value, then returns the
|
|
12
|
+
* Finds a value in the array using the provided decision function, then returns the value at the next index.
|
|
13
13
|
*
|
|
14
|
-
* @param array array to
|
|
15
|
-
* @param find
|
|
16
|
-
* @param wrapAround Whether
|
|
17
|
-
* @param steps
|
|
14
|
+
* @param array - The array to search through, or undefined/null.
|
|
15
|
+
* @param find - Decision function used to locate the target element.
|
|
16
|
+
* @param wrapAround - Whether to wrap around to the beginning of the array if the found value is at or near the last index.
|
|
17
|
+
* @param steps - Number of steps forward from the found index. Defaults to 1.
|
|
18
|
+
* @returns The value at the next index, or undefined if no match is found or no next value exists.
|
|
18
19
|
*/
|
|
19
20
|
export declare function findNext<T>(array: Maybe<T[]>, find: ArrayFindDecisionFunction<T>, wrapAround?: boolean, steps?: number): Maybe<T>;
|
|
20
21
|
/**
|
|
21
|
-
* Returns the next index of an element in the input array based
|
|
22
|
+
* Returns the next index of an element in the input array based on the input index.
|
|
22
23
|
*
|
|
23
24
|
* Indexes less than 0 are considered to not exist.
|
|
24
25
|
*
|
|
25
26
|
* When wrapAround is true, indexes that are larger than the entire array will be used to find an index that is that many steps into the array.
|
|
26
|
-
*
|
|
27
27
|
* For instance, an index of 5 on an array of length 3 will return the index 1.
|
|
28
28
|
*
|
|
29
|
-
* @param array
|
|
30
|
-
* @param index
|
|
31
|
-
* @param wrapAround
|
|
32
|
-
* @param steps
|
|
29
|
+
* @param array - The array to compute the next index within.
|
|
30
|
+
* @param index - The current index to step from.
|
|
31
|
+
* @param wrapAround - Whether to wrap around when stepping past the end of the array.
|
|
32
|
+
* @param steps - Number of steps forward from the current index.
|
|
33
|
+
* @returns The computed next index, or undefined if the input index is out of bounds.
|
|
33
34
|
*/
|
|
34
35
|
export declare function getArrayNextIndex<T>(array: T[], index: number, wrapAround?: boolean, steps?: number): Maybe<number>;
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
+
* Accessor function that returns a value for the given index if any value's range contains that index.
|
|
37
38
|
*/
|
|
38
39
|
export type RangedIndexedValuesArrayAccessor<T> = (index: IndexNumber) => Maybe<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Factory function that creates a {@link RangedIndexedValuesArrayAccessor} from an array of values.
|
|
42
|
+
*/
|
|
39
43
|
export type RangedIndexedValuesArrayAccessorFactory<T> = (values: T[]) => RangedIndexedValuesArrayAccessor<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a factory that produces {@link RangedIndexedValuesArrayAccessor} instances.
|
|
46
|
+
*
|
|
47
|
+
* Each accessor maps an index to the value whose range contains that index, or undefined if no range matches.
|
|
48
|
+
*
|
|
49
|
+
* @param readIndexRange - Function that reads the index range from each value.
|
|
50
|
+
* @returns A factory that creates ranged accessors from arrays of values.
|
|
51
|
+
*/
|
|
40
52
|
export declare function rangedIndexedValuesArrayAccessorFactory<T>(readIndexRange: ReadIndexRangeFunction<T>): RangedIndexedValuesArrayAccessorFactory<T>;
|
|
41
53
|
/**
|
|
42
|
-
*
|
|
54
|
+
* Accessor function that returns a value for the given index. Always returns a value by falling back to the nearest neighbor.
|
|
43
55
|
*/
|
|
44
56
|
export type IndexedValuesArrayAccessor<T> = (index: IndexNumber) => T;
|
|
57
|
+
/**
|
|
58
|
+
* Factory function that creates an {@link IndexedValuesArrayAccessor} from an array of values.
|
|
59
|
+
*/
|
|
45
60
|
export type IndexedValuesArrayAccessorFactory<T> = (values: T[]) => IndexedValuesArrayAccessor<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a factory that produces {@link IndexedValuesArrayAccessor} instances.
|
|
63
|
+
*
|
|
64
|
+
* Each accessor maps an index to the matching value, falling back to the previous value, then the next value.
|
|
65
|
+
* This guarantees a value is always returned.
|
|
66
|
+
*
|
|
67
|
+
* @param readIndexRange - Function that reads the index range from each value.
|
|
68
|
+
* @returns A factory that creates indexed accessors from arrays of values.
|
|
69
|
+
* @throws Error if the provided values array is empty.
|
|
70
|
+
*/
|
|
46
71
|
export declare function indexedValuesArrayAccessorFactory<T>(readIndexRange: ReadIndexRangeFunction<T>): IndexedValuesArrayAccessorFactory<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Contains the match result for a ranged index lookup, including the matched value and its neighbors.
|
|
74
|
+
*/
|
|
47
75
|
export interface RangedIndexValuesArrayAccessorInfo<T> {
|
|
76
|
+
/** The value from the range immediately before the matched or queried range. */
|
|
48
77
|
readonly prev?: Maybe<T>;
|
|
78
|
+
/** The value whose range contains the queried index, or undefined if no range matched. */
|
|
49
79
|
readonly match?: Maybe<T>;
|
|
80
|
+
/** The value from the range immediately after the matched or queried range. */
|
|
50
81
|
readonly next?: Maybe<T>;
|
|
51
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Accessor function that returns detailed match info (match, previous, and next values) for the given index.
|
|
85
|
+
*/
|
|
52
86
|
export type RangedIndexedValuesArrayInfoAccessor<T> = (index: IndexNumber) => RangedIndexValuesArrayAccessorInfo<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Factory function that creates a {@link RangedIndexedValuesArrayInfoAccessor} from an array of values.
|
|
89
|
+
*/
|
|
53
90
|
export type RangedIndexedValuesArrayInfoAccessorFactory<T> = (values: T[]) => RangedIndexedValuesArrayInfoAccessor<T>;
|
|
91
|
+
/**
|
|
92
|
+
* Configuration for {@link rangedIndexedValuesArrayAccessorInfoFactory}.
|
|
93
|
+
*/
|
|
54
94
|
export interface RangedIndexedValuesArrayInfoAccessorFactoryConfig<T> {
|
|
55
95
|
/**
|
|
56
|
-
* Reads the index range. The IndexRange is treated as exclusive.
|
|
96
|
+
* Reads the index range from a value. The IndexRange is treated as exclusive.
|
|
57
97
|
*/
|
|
58
98
|
readonly readIndexRange: ReadIndexRangeFunction<T>;
|
|
59
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a factory that produces {@link RangedIndexedValuesArrayInfoAccessor} instances.
|
|
102
|
+
*
|
|
103
|
+
* Each accessor sorts the values by their index ranges in ascending order, then for a given index
|
|
104
|
+
* returns the matching value along with its previous and next neighbors.
|
|
105
|
+
*
|
|
106
|
+
* @param config - Configuration containing the index range reader function.
|
|
107
|
+
* @returns A factory that creates ranged info accessors from arrays of values.
|
|
108
|
+
*/
|
|
60
109
|
export declare function rangedIndexedValuesArrayAccessorInfoFactory<T>(config: RangedIndexedValuesArrayInfoAccessorFactoryConfig<T>): RangedIndexedValuesArrayInfoAccessorFactory<T>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type Maybe } from '../value/maybe.type';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for limiting the number of items returned from an array.
|
|
4
|
+
*/
|
|
2
5
|
export interface LimitArrayConfig {
|
|
3
6
|
/**
|
|
4
7
|
* Number of items in the list to limit in the result.
|
|
@@ -9,6 +12,14 @@ export interface LimitArrayConfig {
|
|
|
9
12
|
*/
|
|
10
13
|
readonly limitFromEnd?: boolean;
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Limits the number of items in an array based on the provided configuration.
|
|
17
|
+
* Items are taken from the front of the array by default, or from the end if configured.
|
|
18
|
+
*
|
|
19
|
+
* @param array - source array to limit
|
|
20
|
+
* @param inputConfig - configuration controlling the limit count and direction
|
|
21
|
+
* @returns a new array with at most the configured number of items, or the original array if no limit is specified
|
|
22
|
+
*/
|
|
12
23
|
export declare function limitArray<T>(array: T[], { limit, limitFromEnd }: Partial<LimitArrayConfig>): T[];
|
|
13
24
|
export declare function limitArray<T>(array: Maybe<T[]>, { limit, limitFromEnd }: Partial<LimitArrayConfig>): Maybe<T[]>;
|
|
14
25
|
export declare function limitArray<T>(array: Maybe<T[]>, config: Maybe<Partial<LimitArrayConfig>>): Maybe<T[]>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type FactoryWithInput } from '../getter';
|
|
2
2
|
import { type RandomNumberFactoryInput, type RandomNumberFactory } from '../number/random';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for creating an array of items using a factory function.
|
|
5
|
+
*/
|
|
3
6
|
export interface MakeArray<T> {
|
|
4
7
|
readonly count: number;
|
|
5
8
|
/**
|
|
@@ -7,6 +10,9 @@ export interface MakeArray<T> {
|
|
|
7
10
|
*/
|
|
8
11
|
readonly make: FactoryWithInput<T, number>;
|
|
9
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for creating a {@link RandomArrayFactory}. Combines a make function with a random number source to produce arrays of varying length.
|
|
15
|
+
*/
|
|
10
16
|
export interface RandomArrayFactoryConfig<T> extends Omit<MakeArray<T>, 'count'> {
|
|
11
17
|
readonly random: RandomNumberFactory | RandomNumberFactoryInput;
|
|
12
18
|
}
|
|
@@ -15,9 +21,9 @@ export interface RandomArrayFactoryConfig<T> extends Omit<MakeArray<T>, 'count'>
|
|
|
15
21
|
*/
|
|
16
22
|
export type RandomArrayFactory<T> = FactoryWithInput<T[], number>;
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
24
|
+
* Creates a factory function that generates arrays of a random length populated with items from a make function.
|
|
19
25
|
*
|
|
20
|
-
* @param config
|
|
21
|
-
* @returns
|
|
26
|
+
* @param config - configuration containing the make function and random number source
|
|
27
|
+
* @returns a factory that produces arrays of random length, optionally accepting a specific count override
|
|
22
28
|
*/
|
|
23
29
|
export declare function randomArrayFactory<T>(config: RandomArrayFactoryConfig<T>): RandomArrayFactory<T>;
|
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
import { type PrimativeKey, type ReadKeyFunction } from '../key';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
3
|
/**
|
|
4
|
-
* Maps the values of the input array to a Map
|
|
4
|
+
* Maps the values of the input array to a Map, keyed by the result of a key function.
|
|
5
|
+
* Optionally transforms each value using a value function.
|
|
6
|
+
*
|
|
7
|
+
* @param values - source array of items to map
|
|
8
|
+
* @param keyFn - function to extract a key from each item
|
|
9
|
+
* @param valueFn - optional function to transform each item into the desired map value
|
|
10
|
+
* @returns a Map of keys to values derived from the input array
|
|
5
11
|
*/
|
|
6
12
|
export declare function arrayToMap<T, V, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => V): Map<Maybe<K>, V>;
|
|
7
13
|
export declare function arrayToMap<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => T): Map<Maybe<K>, T>;
|
|
8
14
|
export declare function arrayToMap<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>): Map<Maybe<K>, T>;
|
|
9
15
|
/**
|
|
10
|
-
* Maps the values of the input array to a Record object
|
|
16
|
+
* Maps the values of the input array to a Record object, keyed by the result of a key function.
|
|
17
|
+
* Items with undefined keys are omitted. Optionally transforms each value using a value function.
|
|
18
|
+
*
|
|
19
|
+
* @param values - source array of items to map
|
|
20
|
+
* @param keyFn - function to extract a key from each item
|
|
21
|
+
* @param valueFn - optional function to transform each item into the desired record value
|
|
22
|
+
* @returns a Record of keys to values derived from the input array
|
|
11
23
|
*/
|
|
12
24
|
export declare function arrayToObject<T, V, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => V): Record<K, V>;
|
|
13
25
|
export declare function arrayToObject<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>, valueFn: (t: T) => T): Record<K, T>;
|
|
14
26
|
export declare function arrayToObject<T, K extends PrimativeKey = PrimativeKey>(values: T[], keyFn: ReadKeyFunction<T, K>): Record<K, T>;
|
|
15
27
|
/**
|
|
16
|
-
*
|
|
28
|
+
* Returns values for each key, reusing existing items when available and generating new ones for missing keys.
|
|
17
29
|
*
|
|
18
|
-
* @param keys
|
|
19
|
-
* @param existing
|
|
20
|
-
* @param readKey
|
|
21
|
-
* @param generateFn
|
|
22
|
-
* @returns
|
|
30
|
+
* @param keys - the keys to resolve values for
|
|
31
|
+
* @param existing - array of pre-existing items to check against
|
|
32
|
+
* @param readKey - function to extract a key from an existing item
|
|
33
|
+
* @param generateFn - function to create a new item for a key not found in existing items
|
|
34
|
+
* @returns an array of items corresponding to each input key, in the same order
|
|
23
35
|
*/
|
|
24
36
|
export declare function generateIfDoesNotExist<T, K extends PrimativeKey = PrimativeKey>(keys: K[], existing: T[], readKey: ReadKeyFunction<T, K>, generateFn: (key: K) => T): T[];
|