@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/src/lib/set/set.d.ts
CHANGED
|
@@ -4,57 +4,161 @@ import { type PrimativeKey, type ReadKeyFunction } from '../key';
|
|
|
4
4
|
import { type SetIncludesMode } from './set.mode';
|
|
5
5
|
import { type DecisionFunction } from '../value/decision';
|
|
6
6
|
import { type MapFunction } from '../value/map';
|
|
7
|
+
/**
|
|
8
|
+
* Represents a selection that is either everything or nothing.
|
|
9
|
+
*/
|
|
7
10
|
export type AllOrNoneSelection = 'all' | 'none';
|
|
11
|
+
/**
|
|
12
|
+
* Converts an {@link IterableOrValue} into a Set. Strings are treated as single values rather than character iterables.
|
|
13
|
+
*
|
|
14
|
+
* @param values - The value or iterable to convert.
|
|
15
|
+
* @returns A new Set containing all values.
|
|
16
|
+
*/
|
|
8
17
|
export declare function asSet<T>(values: IterableOrValue<T>): Set<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a copy of the set, applies the given function to the copy, and returns it.
|
|
20
|
+
*
|
|
21
|
+
* @param set - The set to copy, or null/undefined for an empty set.
|
|
22
|
+
* @param fn - A function to mutate the copied set.
|
|
23
|
+
* @returns The modified copy of the set.
|
|
24
|
+
*/
|
|
9
25
|
export declare function copySetAndDo<T>(set: Maybe<Set<T>>, fn: (set: Set<T>) => void): Set<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a copy of the set with the given values added.
|
|
28
|
+
*
|
|
29
|
+
* @param set - The set to copy, or null/undefined for an empty set.
|
|
30
|
+
* @param values - The values to add to the copy.
|
|
31
|
+
* @returns A new Set with the values added.
|
|
32
|
+
*/
|
|
10
33
|
export declare function addToSetCopy<T>(set: Maybe<Set<T>>, values: Maybe<IterableOrValue<T>>): Set<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Adds one or more values to the given set in place.
|
|
36
|
+
*
|
|
37
|
+
* @param set - The set to add values to.
|
|
38
|
+
* @param values - The value or iterable of values to add.
|
|
39
|
+
*/
|
|
11
40
|
export declare function addToSet<T>(set: Set<T>, values: Maybe<IterableOrValue<T>>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a copy of the set with the given values toggled (added if absent, removed if present).
|
|
43
|
+
*
|
|
44
|
+
* @param set - The set to copy.
|
|
45
|
+
* @param values - The values to toggle.
|
|
46
|
+
* @returns A new Set with the toggles applied.
|
|
47
|
+
*/
|
|
12
48
|
export declare function toggleInSetCopy<T>(set: Set<T>, values: Maybe<IterableOrValue<T>>): Set<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Toggles values in the set in place: adds if absent, removes if present.
|
|
51
|
+
*
|
|
52
|
+
* @param set - The set to modify.
|
|
53
|
+
* @param values - The values to toggle.
|
|
54
|
+
*/
|
|
13
55
|
export declare function toggleInSet<T>(set: Set<T>, values: Maybe<IterableOrValue<T>>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a copy of the set with the given values removed.
|
|
58
|
+
*
|
|
59
|
+
* @param set - The set to copy, or null/undefined for an empty set.
|
|
60
|
+
* @param values - The values to remove from the copy.
|
|
61
|
+
* @returns A new Set with the values removed.
|
|
62
|
+
*/
|
|
14
63
|
export declare function removeFromSetCopy<T>(set: Maybe<Set<T>>, values: Maybe<IterableOrValue<T>>): Set<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Removes one or more values from the given set in place.
|
|
66
|
+
*
|
|
67
|
+
* @param set - The set to remove values from.
|
|
68
|
+
* @param values - The value or iterable of values to remove.
|
|
69
|
+
*/
|
|
15
70
|
export declare function removeFromSet<T>(set: Set<T>, values: Maybe<IterableOrValue<T>>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns true if both iterables contain the same set of values.
|
|
73
|
+
*
|
|
74
|
+
* @param a - First iterable.
|
|
75
|
+
* @param b - Second iterable.
|
|
76
|
+
* @returns `true` if the values are identical as sets.
|
|
77
|
+
*/
|
|
16
78
|
export declare function hasSameValues<T>(a: Maybe<Iterable<T>>, b: Maybe<Iterable<T>>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if the two iterables contain different sets of values, or if either is null/undefined.
|
|
81
|
+
*
|
|
82
|
+
* @param a - First iterable.
|
|
83
|
+
* @param b - Second iterable.
|
|
84
|
+
* @returns `true` if the values differ.
|
|
85
|
+
*/
|
|
17
86
|
export declare function hasDifferentValues<T>(a: Maybe<Iterable<T>>, b: Maybe<Iterable<T>>): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Returns an array of values that exist in exactly one of the two iterables (symmetric difference).
|
|
89
|
+
*
|
|
90
|
+
* @param a - First iterable.
|
|
91
|
+
* @param b - Second iterable.
|
|
92
|
+
* @returns An array of values present in only one of the inputs.
|
|
93
|
+
*/
|
|
18
94
|
export declare function symmetricDifferenceArray<T>(a: Maybe<Iterable<T>>, b: Maybe<Iterable<T>>): Maybe<T>[];
|
|
95
|
+
/**
|
|
96
|
+
* Returns an array of the symmetric difference between two sets.
|
|
97
|
+
*
|
|
98
|
+
* @param a - First set.
|
|
99
|
+
* @param b - Second set.
|
|
100
|
+
* @returns An array of values present in only one of the sets.
|
|
101
|
+
*/
|
|
19
102
|
export declare function symmetricDifferenceArrayBetweenSets<T>(a: Set<Maybe<T>>, b: Set<Maybe<T>>): Maybe<T>[];
|
|
103
|
+
/**
|
|
104
|
+
* Flattens a two-dimensional array into a Set of unique values.
|
|
105
|
+
*
|
|
106
|
+
* @param array - The nested array to flatten.
|
|
107
|
+
* @returns A Set containing all values from the nested arrays.
|
|
108
|
+
*/
|
|
20
109
|
export declare function flattenArrayToSet<T>(array: T[][]): Set<T>;
|
|
21
110
|
/**
|
|
22
|
-
*
|
|
111
|
+
* Returns a new Set containing only the values from the input that also exist in the given set.
|
|
112
|
+
* If the input values are null or undefined, returns an empty set.
|
|
23
113
|
*
|
|
24
|
-
* @param set
|
|
25
|
-
* @param values
|
|
26
|
-
* @returns
|
|
114
|
+
* @param set - The reference set to check membership against.
|
|
115
|
+
* @param values - The values to filter.
|
|
116
|
+
* @returns A Set of values that exist in both inputs.
|
|
27
117
|
*/
|
|
28
118
|
export declare function keepFromSetCopy<T>(set: Set<T>, values: Maybe<IterableOrValue<T>>): Set<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Filters the array to only include values that exist in the given set.
|
|
121
|
+
*
|
|
122
|
+
* @param values - The array to filter.
|
|
123
|
+
* @param set - The set to check membership against.
|
|
124
|
+
* @returns An array of values present in the set.
|
|
125
|
+
*/
|
|
29
126
|
export declare function keepValuesFromSet<T>(values: T[], set: Set<T>): T[];
|
|
127
|
+
/**
|
|
128
|
+
* Returns values from the first array that are not present in the iterable.
|
|
129
|
+
*
|
|
130
|
+
* @param valuesToExclude - The array of values to filter.
|
|
131
|
+
* @param iterable - The iterable of values to exclude.
|
|
132
|
+
* @returns An array of values not found in the iterable.
|
|
133
|
+
*/
|
|
30
134
|
export declare function excludeValues<T>(valuesToExclude: T[], iterable: Maybe<Iterable<T>>): T[];
|
|
31
135
|
/**
|
|
32
|
-
*
|
|
136
|
+
* Filters the array to exclude any values present in the given set.
|
|
33
137
|
*
|
|
34
|
-
* @param values
|
|
35
|
-
* @param set
|
|
36
|
-
* @returns
|
|
138
|
+
* @param values - The array to filter.
|
|
139
|
+
* @param set - The set of values to exclude.
|
|
140
|
+
* @returns An array of values not in the set.
|
|
37
141
|
*/
|
|
38
142
|
export declare function excludeValuesFromSet<T>(values: T[], set: Set<T>): T[];
|
|
39
143
|
/**
|
|
40
|
-
* Filters the
|
|
144
|
+
* Filters the array using set membership, either including or excluding matched values.
|
|
41
145
|
*
|
|
42
|
-
* @param values
|
|
43
|
-
* @param set
|
|
44
|
-
* @param exclude
|
|
45
|
-
* @returns
|
|
146
|
+
* @param values - The array to filter.
|
|
147
|
+
* @param set - The set to check against.
|
|
148
|
+
* @param exclude - If true, excludes values in the set; if false, keeps only values in the set.
|
|
149
|
+
* @returns The filtered array.
|
|
46
150
|
*/
|
|
47
151
|
export declare function filterValuesUsingSet<T>(values: T[], set: Set<T>, exclude?: boolean): T[];
|
|
48
152
|
/**
|
|
49
|
-
* Filters the input iterable using a DecisionFunction and returns a Set.
|
|
153
|
+
* Filters the input iterable using a {@link DecisionFunction} and returns a Set of values for which the function returns true.
|
|
50
154
|
*
|
|
51
|
-
* @param values
|
|
52
|
-
* @param fn
|
|
53
|
-
* @returns
|
|
155
|
+
* @param values - The iterable to filter.
|
|
156
|
+
* @param fn - The decision function that determines inclusion.
|
|
157
|
+
* @returns A Set of values that passed the filter.
|
|
54
158
|
*/
|
|
55
159
|
export declare function filterValuesToSet<T>(values: Iterable<T>, fn: DecisionFunction<T>): Set<T>;
|
|
56
160
|
/**
|
|
57
|
-
*
|
|
161
|
+
* Result of {@link separateValuesToSets} containing included and excluded value sets.
|
|
58
162
|
*/
|
|
59
163
|
export interface SeparateValuesToSetsResult<T> {
|
|
60
164
|
readonly included: Set<T>;
|
|
@@ -65,27 +169,29 @@ export interface SeparateValuesToSetsResult<T> {
|
|
|
65
169
|
*/
|
|
66
170
|
export type SeparateValuesToSetsInput<T> = Partial<SeparateValuesToSetsResult<T>>;
|
|
67
171
|
/**
|
|
68
|
-
*
|
|
172
|
+
* Separates values from an iterable into two sets based on a {@link DecisionFunction}.
|
|
173
|
+
* Values for which the function returns true go into `included`, others into `excluded`.
|
|
69
174
|
*
|
|
70
|
-
* @param values
|
|
71
|
-
* @param fn
|
|
72
|
-
* @
|
|
175
|
+
* @param values - The iterable to partition.
|
|
176
|
+
* @param fn - The decision function that determines inclusion.
|
|
177
|
+
* @param input - Optional pre-existing sets to add results to.
|
|
178
|
+
* @returns An object with `included` and `excluded` sets.
|
|
73
179
|
*/
|
|
74
180
|
export declare function separateValuesToSets<T>(values: Iterable<T>, fn: DecisionFunction<T>, input?: SeparateValuesToSetsInput<T>): SeparateValuesToSetsResult<T>;
|
|
75
181
|
/**
|
|
76
|
-
* Maps the
|
|
182
|
+
* Maps each value in the iterable through a function and collects the results into a Set.
|
|
77
183
|
*
|
|
78
|
-
* @param values
|
|
79
|
-
* @param
|
|
80
|
-
* @returns
|
|
184
|
+
* @param values - The iterable to map.
|
|
185
|
+
* @param mapFn - The mapping function.
|
|
186
|
+
* @returns A Set of mapped values.
|
|
81
187
|
*/
|
|
82
188
|
export declare function mapValuesToSet<I, O>(values: Iterable<I>, mapFn: MapFunction<I, O>): Set<O>;
|
|
83
189
|
/**
|
|
84
|
-
*
|
|
190
|
+
* Creates a {@link SetHasValueFunction} from an {@link IterableOrValue} by first converting it to a Set.
|
|
85
191
|
*
|
|
86
|
-
* @param iterable
|
|
87
|
-
* @param exclude
|
|
88
|
-
* @returns
|
|
192
|
+
* @param iterable - The values to create a set from.
|
|
193
|
+
* @param exclude - If true, the returned function returns true for values NOT in the set.
|
|
194
|
+
* @returns A function that tests membership.
|
|
89
195
|
*/
|
|
90
196
|
export declare function hasValueFunction<T>(iterable: IterableOrValue<T>, exclude?: boolean): SetHasValueFunction<T>;
|
|
91
197
|
/**
|
|
@@ -93,13 +199,16 @@ export declare function hasValueFunction<T>(iterable: IterableOrValue<T>, exclud
|
|
|
93
199
|
*/
|
|
94
200
|
export type SetHasValueFunction<T> = (value: T) => boolean;
|
|
95
201
|
/**
|
|
96
|
-
* Creates a SetHasValueFunction.
|
|
202
|
+
* Creates a {@link SetHasValueFunction} for the given set. When `exclude` is true, returns the inverse (true for values not in the set).
|
|
97
203
|
*
|
|
98
|
-
* @param set
|
|
99
|
-
* @param exclude
|
|
100
|
-
* @returns
|
|
204
|
+
* @param set - The set to check against.
|
|
205
|
+
* @param exclude - If true, returns true for values NOT in the set.
|
|
206
|
+
* @returns A function that tests membership.
|
|
101
207
|
*/
|
|
102
208
|
export declare function setHasValueFunction<T>(set: Set<T>, exclude: boolean): SetHasValueFunction<T>;
|
|
209
|
+
/**
|
|
210
|
+
* Configuration for {@link findValuesFrom} that filters an array by key membership.
|
|
211
|
+
*/
|
|
103
212
|
export interface FindValuesFromInput<T, K extends PrimativeKey = PrimativeKey> {
|
|
104
213
|
/**
|
|
105
214
|
* Values to filter on.
|
|
@@ -125,10 +234,11 @@ export interface FindValuesFromInput<T, K extends PrimativeKey = PrimativeKey> {
|
|
|
125
234
|
readonly exclude?: boolean;
|
|
126
235
|
}
|
|
127
236
|
/**
|
|
128
|
-
*
|
|
237
|
+
* Filters an array of values based on whether their keys are found in a specified set of keys or values.
|
|
238
|
+
* Supports both inclusion and exclusion modes.
|
|
129
239
|
*
|
|
130
|
-
* @param config
|
|
131
|
-
* @returns
|
|
240
|
+
* @param config - Configuration specifying the values, keys to find, and filtering behavior.
|
|
241
|
+
* @returns The filtered array of matching values.
|
|
132
242
|
*/
|
|
133
243
|
export declare function findValuesFrom<T, K extends PrimativeKey = PrimativeKey>(config: FindValuesFromInput<T, K>): T[];
|
|
134
244
|
/**
|
|
@@ -136,27 +246,45 @@ export declare function findValuesFrom<T, K extends PrimativeKey = PrimativeKey>
|
|
|
136
246
|
*/
|
|
137
247
|
export type SetIncludesFunction<T> = (valuesToFind: IterableOrValue<T>) => boolean;
|
|
138
248
|
/**
|
|
139
|
-
* Creates a SetIncludesFunction
|
|
249
|
+
* Creates a {@link SetIncludesFunction} that checks whether the set includes given values using the specified mode.
|
|
140
250
|
*
|
|
141
|
-
* @param valuesSet
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
251
|
+
* @param valuesSet - The reference set.
|
|
252
|
+
* @param mode - Whether to require 'all' values or 'any' value to be present. Defaults to 'all'.
|
|
253
|
+
* @param emptyValuesToFindArrayResult - The result when the values to find are empty.
|
|
254
|
+
* @returns A function that tests inclusion against the set.
|
|
144
255
|
*/
|
|
145
256
|
export declare function setIncludesFunction<T>(valuesSet: Set<T>, mode?: SetIncludesMode, emptyValuesToFindArrayResult?: boolean): SetIncludesFunction<T>;
|
|
146
257
|
/**
|
|
147
|
-
*
|
|
258
|
+
* Checks whether the set includes the given values using the specified mode.
|
|
259
|
+
* Convenience wrapper around {@link setIncludesFunction}.
|
|
148
260
|
*
|
|
149
|
-
* @param valuesSet
|
|
150
|
-
* @param valuesToFind
|
|
151
|
-
* @param mode
|
|
152
|
-
* @returns
|
|
261
|
+
* @param valuesSet - The reference set.
|
|
262
|
+
* @param valuesToFind - The values to check for.
|
|
263
|
+
* @param mode - Whether to require 'all' or 'any'. Defaults to 'all'.
|
|
264
|
+
* @returns `true` if the inclusion check passes.
|
|
153
265
|
*/
|
|
154
266
|
export declare function setIncludes<T>(valuesSet: Set<T>, valuesToFind: IterableOrValue<T>, mode?: SetIncludesMode): boolean;
|
|
155
267
|
/**
|
|
156
268
|
* Returns false if the input array contains any value from the second array.
|
|
157
269
|
*/
|
|
158
270
|
export declare function containsNoneOfValue<T>(values: IterableOrValue<T>, valuesToFind: IterableOrValue<T>, emptyValuesToFindArrayResult?: boolean): boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Returns true if none of the values are present in the given set.
|
|
273
|
+
*
|
|
274
|
+
* @param values - The values to check.
|
|
275
|
+
* @param valuesToFind - The set to check against.
|
|
276
|
+
* @param emptyValuesArrayResult - Result when values is empty.
|
|
277
|
+
* @returns `true` if no values are in the set.
|
|
278
|
+
*/
|
|
159
279
|
export declare function containsNoValueFromSet<T>(values: IterableOrValue<T>, valuesToFind: Set<T>, emptyValuesArrayResult?: boolean): boolean;
|
|
280
|
+
/**
|
|
281
|
+
* Returns true if the set contains none of the given values.
|
|
282
|
+
*
|
|
283
|
+
* @param valuesSet - The set to check against.
|
|
284
|
+
* @param valuesToFind - The values to look for.
|
|
285
|
+
* @param emptyValuesToFindArrayResult - Result when valuesToFind is empty. Defaults to true.
|
|
286
|
+
* @returns `true` if none of the values are in the set.
|
|
287
|
+
*/
|
|
160
288
|
export declare function setContainsNoneOfValue<T>(valuesSet: Set<T>, valuesToFind: IterableOrValue<T>, emptyValuesToFindArrayResult?: boolean): boolean;
|
|
161
289
|
/**
|
|
162
290
|
* Returns true if the input array contains any value from the second array.
|
|
@@ -7,9 +7,11 @@ export type IsInSetDecisionFunction<T, V> = DecisionFunction<T> & {
|
|
|
7
7
|
readonly _set: Set<V>;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
* Creates an IsInSetDecisionFunction.
|
|
10
|
+
* Creates an {@link IsInSetDecisionFunction} that checks whether a value (or a derived value) is in the given set.
|
|
11
11
|
*
|
|
12
|
-
* @param set
|
|
12
|
+
* @param set - The set to check membership against.
|
|
13
|
+
* @param readValue - Optional function to extract the lookup value from the input. Defaults to identity.
|
|
14
|
+
* @returns A decision function that returns true for values found in the set.
|
|
13
15
|
*/
|
|
14
16
|
export declare function isInSetDecisionFunction<T>(set: Set<T>): IsInSetDecisionFunction<T, T>;
|
|
15
17
|
export declare function isInSetDecisionFunction<T, V>(set: Set<V>, readValue: (value: T) => V): IsInSetDecisionFunction<T, V>;
|
|
@@ -11,6 +11,9 @@ export declare enum SetDeltaChange {
|
|
|
11
11
|
* Returns true if the next value has been modified compared to the past value.
|
|
12
12
|
*/
|
|
13
13
|
export type SetValueIsModifiedFunction<T> = (past: T, next: T) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Represents the change status of a single value between two sets, including its past and next values.
|
|
16
|
+
*/
|
|
14
17
|
export interface SetDeltaChangePair<T, K extends PrimativeKey = PrimativeKey> {
|
|
15
18
|
/**
|
|
16
19
|
* Key for this pair
|
|
@@ -41,6 +44,9 @@ export interface SetDeltaChangePair<T, K extends PrimativeKey = PrimativeKey> {
|
|
|
41
44
|
* Function that builds an array of changes based on the values in the past array to the next array.
|
|
42
45
|
*/
|
|
43
46
|
export type SetDeltaFunction<T, K extends PrimativeKey = PrimativeKey> = (past: Iterable<T>, next: Iterable<T>) => SetDeltaChangePair<T, K>[];
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for creating a {@link SetDeltaFunction}.
|
|
49
|
+
*/
|
|
44
50
|
export interface SetDeltaFunctionConfig<T, K extends PrimativeKey = PrimativeKey> {
|
|
45
51
|
/**
|
|
46
52
|
* Reads the identifying key from each input value.
|
|
@@ -51,6 +57,13 @@ export interface SetDeltaFunctionConfig<T, K extends PrimativeKey = PrimativeKey
|
|
|
51
57
|
*/
|
|
52
58
|
isModifiedFunction?: SetValueIsModifiedFunction<T>;
|
|
53
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a {@link SetDeltaFunction} that computes the differences between two iterables,
|
|
62
|
+
* identifying which items were added, removed, or unchanged.
|
|
63
|
+
*
|
|
64
|
+
* @param config - Configuration with the key reader and optional modification detector.
|
|
65
|
+
* @returns A function that compares two iterables and returns an array of change pairs.
|
|
66
|
+
*/
|
|
54
67
|
export declare function setDeltaFunction<T>(config: SetDeltaFunctionConfig<T>): SetDeltaFunction<T>;
|
|
55
68
|
/**
|
|
56
69
|
* Keys mapped by their change type.
|
|
@@ -61,10 +74,10 @@ export interface SetDeltaChangeKeys<K extends PrimativeKey = PrimativeKey> {
|
|
|
61
74
|
readonly added: K[];
|
|
62
75
|
}
|
|
63
76
|
/**
|
|
64
|
-
*
|
|
77
|
+
* Groups the keys from an array of {@link SetDeltaChangePair} values by their change type.
|
|
65
78
|
*
|
|
66
|
-
* @param pairs
|
|
67
|
-
* @returns
|
|
79
|
+
* @param pairs - The delta change pairs to categorize.
|
|
80
|
+
* @returns An object with `added`, `removed`, and `none` key arrays.
|
|
68
81
|
*/
|
|
69
82
|
export declare function setDeltaChangeKeys<T, K extends PrimativeKey = PrimativeKey>(pairs: SetDeltaChangePair<T, K>[]): SetDeltaChangeKeys<K>;
|
|
70
83
|
/**
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type PrimativeKey, type ReadKeyFunction } from '../key';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for a {@link HashSet}, providing the key extraction function.
|
|
5
|
+
*/
|
|
3
6
|
export interface HashSetConfig<K extends PrimativeKey, T> {
|
|
7
|
+
/** Extracts the unique key used for equality comparison from each value. */
|
|
4
8
|
readKey: ReadKeyFunction<T, K>;
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
@@ -11,23 +15,62 @@ export interface HashSetConfig<K extends PrimativeKey, T> {
|
|
|
11
15
|
export declare class HashSet<K extends PrimativeKey, T> implements Set<T> {
|
|
12
16
|
private readonly _map;
|
|
13
17
|
private readonly _config;
|
|
18
|
+
/**
|
|
19
|
+
* @param config - Configuration with the key extraction function.
|
|
20
|
+
* @param values - Optional initial values to add.
|
|
21
|
+
*/
|
|
14
22
|
constructor(config: HashSetConfig<K, T>, values?: T[]);
|
|
15
23
|
get config(): HashSetConfig<K, T>;
|
|
16
24
|
get size(): number;
|
|
17
25
|
[Symbol.iterator](): MapIterator<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Adds all values from the array to the set.
|
|
28
|
+
*
|
|
29
|
+
* @param values - The values to add, or null/undefined to skip.
|
|
30
|
+
* @returns This set for chaining.
|
|
31
|
+
*/
|
|
18
32
|
addAll(values: Maybe<T[]>): this;
|
|
19
33
|
add(value: T): this;
|
|
20
34
|
clear(): void;
|
|
21
35
|
delete(value: T): boolean;
|
|
22
36
|
has(value: T): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Checks whether a value with the given key exists in the set.
|
|
39
|
+
*
|
|
40
|
+
* @param key - The key to check for.
|
|
41
|
+
* @returns `true` if a value with this key exists.
|
|
42
|
+
*/
|
|
23
43
|
hasKeyValue(key: Maybe<K>): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the value associated with the given key, or undefined if not found.
|
|
46
|
+
*
|
|
47
|
+
* @param key - The key to look up.
|
|
48
|
+
* @returns The value, or undefined.
|
|
49
|
+
*/
|
|
24
50
|
valueForKey(key: Maybe<K>): T | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Returns key-value entry pairs for each of the given keys. Missing values appear as undefined.
|
|
53
|
+
*
|
|
54
|
+
* @param keys - The keys to look up.
|
|
55
|
+
* @returns An array of [key, value] tuples.
|
|
56
|
+
*/
|
|
25
57
|
valueKeyEntriesForKeys(keys: Maybe<K>[]): [Maybe<K>, Maybe<T>][];
|
|
58
|
+
/**
|
|
59
|
+
* Returns the values associated with the given keys, omitting keys that have no value.
|
|
60
|
+
*
|
|
61
|
+
* @param keys - The keys to look up.
|
|
62
|
+
* @returns An array of found values.
|
|
63
|
+
*/
|
|
26
64
|
valuesForKeys(keys: Maybe<K>[]): T[];
|
|
27
65
|
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: unknown): void;
|
|
28
66
|
entries(): SetIterator<[T, T]>;
|
|
29
67
|
keys(): SetIterator<T>;
|
|
30
68
|
values(): SetIterator<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns all values in the set as an array.
|
|
71
|
+
*
|
|
72
|
+
* @returns An array of all stored values.
|
|
73
|
+
*/
|
|
31
74
|
valuesArray(): T[];
|
|
32
75
|
get [Symbol.toStringTag](): string;
|
|
33
76
|
}
|
|
@@ -4,6 +4,9 @@ import { type DecisionFunction } from '../value';
|
|
|
4
4
|
* Factory that creates a DecisionFunction using the input "selected" values. That function returns true if the value's key is considered to be included in the selected values.
|
|
5
5
|
*/
|
|
6
6
|
export type IsSelectedDecisionFunctionFactory<T, K extends PrimativeKey = PrimativeKey> = (selectedValues: Iterable<K>) => DecisionFunction<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for {@link isSelectedDecisionFunctionFactory}.
|
|
9
|
+
*/
|
|
7
10
|
export interface IsSelectedDecisionFunctionConfig<T, K extends PrimativeKey = PrimativeKey> {
|
|
8
11
|
/**
|
|
9
12
|
* Reads the key from the input value.
|
|
@@ -17,9 +20,10 @@ export interface IsSelectedDecisionFunctionConfig<T, K extends PrimativeKey = Pr
|
|
|
17
20
|
defaultIfKeyNull?: boolean;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
|
-
* Creates
|
|
23
|
+
* Creates an {@link IsSelectedDecisionFunctionFactory} that produces decision functions
|
|
24
|
+
* checking whether a value's key is included in a set of selected values.
|
|
21
25
|
*
|
|
22
|
-
* @param config
|
|
23
|
-
* @returns
|
|
26
|
+
* @param config - Configuration with the key reader and default behavior.
|
|
27
|
+
* @returns A factory that creates decision functions from a set of selected keys.
|
|
24
28
|
*/
|
|
25
29
|
export declare function isSelectedDecisionFunctionFactory<T, K extends PrimativeKey = PrimativeKey>(config: IsSelectedDecisionFunctionConfig<T, K>): IsSelectedDecisionFunctionFactory<T, K>;
|
package/src/lib/sort.d.ts
CHANGED
|
@@ -50,11 +50,22 @@ export declare function reverseCompareFn<T>(compareFn: SortDescendingCompareFunc
|
|
|
50
50
|
*/
|
|
51
51
|
export declare function compareFnOrder<T>(ascendingCompareFn: AscendingSortCompareFunction<T>, order?: SortingOrder): SortCompareFunction<T>;
|
|
52
52
|
/**
|
|
53
|
-
* Creates a
|
|
53
|
+
* Creates a {@link SortCompareFunction} that maps values to a different type before comparing.
|
|
54
|
+
* Useful for sorting objects by a derived property.
|
|
54
55
|
*
|
|
55
|
-
* @param mapValue
|
|
56
|
-
* @param
|
|
57
|
-
* @returns
|
|
56
|
+
* @param mapValue - Maps each value to the type used for comparison.
|
|
57
|
+
* @param comparesFunction - Compares the mapped values.
|
|
58
|
+
* @returns A sort comparison function for the original type.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const byName = compareWithMappedValuesFunction(
|
|
63
|
+
* (user: { name: string }) => user.name,
|
|
64
|
+
* (a, b) => a.localeCompare(b)
|
|
65
|
+
* );
|
|
66
|
+
* [{ name: 'Bob' }, { name: 'Alice' }].sort(byName);
|
|
67
|
+
* // [{ name: 'Alice' }, { name: 'Bob' }]
|
|
68
|
+
* ```
|
|
58
69
|
*/
|
|
59
70
|
export declare function compareWithMappedValuesFunction<T, V>(mapValue: MapFunction<T, V>, comparesFunction: SortCompareFunction<V>): SortCompareFunction<T>;
|
|
60
71
|
/**
|
|
@@ -83,17 +94,18 @@ export type SortValuesInput<T> = MaybeMap<Partial<SortCompareFunctionRef<T>>> &
|
|
|
83
94
|
readonly alwaysReturnCopy?: Maybe<boolean>;
|
|
84
95
|
};
|
|
85
96
|
/**
|
|
86
|
-
* Sorts the
|
|
97
|
+
* Sorts values using the configuration in {@link SortValuesInput}. Optionally sorts on a copy to avoid mutating the original array.
|
|
87
98
|
*
|
|
88
|
-
* @param input
|
|
89
|
-
* @returns
|
|
99
|
+
* @param input - Configuration including values, sort function, and copy behavior.
|
|
100
|
+
* @returns The sorted array (may be the original or a copy depending on configuration).
|
|
90
101
|
*/
|
|
91
102
|
export declare function sortValues<T>(input: SortValuesInput<T>): T[];
|
|
92
103
|
/**
|
|
93
|
-
* Creates a SortValuesFunction
|
|
104
|
+
* Creates a {@link SortValuesFunction} from a {@link SortCompareFunctionRef}.
|
|
94
105
|
*
|
|
95
|
-
* @param sortRef
|
|
96
|
-
* @
|
|
106
|
+
* @param sortRef - Reference containing the sort comparison function.
|
|
107
|
+
* @param sortOnCopyDefault - Whether to sort on a copy by default (default: true).
|
|
108
|
+
* @returns A function that sorts arrays using the configured comparison.
|
|
97
109
|
*/
|
|
98
110
|
export declare function sortValuesFunctionWithSortRef<T>(sortRef: Maybe<Partial<SortCompareFunctionRef<T>>>, sortOnCopyDefault?: boolean): SortValuesFunction<T>;
|
|
99
111
|
/**
|
|
@@ -101,11 +113,11 @@ export declare function sortValuesFunctionWithSortRef<T>(sortRef: Maybe<Partial<
|
|
|
101
113
|
*/
|
|
102
114
|
export declare function sortValuesFunctionOrMapIdentityWithSortRef<T>(sortRef: Maybe<Partial<SortCompareFunctionRef<T>>>, sortOnCopyDefault?: boolean): SortValuesFunction<T>;
|
|
103
115
|
/**
|
|
104
|
-
* Equivalent to sortValuesFunctionOrMapIdentityWithSortRef
|
|
116
|
+
* Equivalent to {@link sortValuesFunctionOrMapIdentityWithSortRef}, but returns a {@link SimpleSortValuesFunction} instead.
|
|
105
117
|
*
|
|
106
|
-
* @param sortRef
|
|
107
|
-
* @param sortOnCopyDefault
|
|
108
|
-
* @returns
|
|
118
|
+
* @param sortRef - Reference containing the sort comparison function.
|
|
119
|
+
* @param sortOnCopyDefault - Whether to sort on a copy by default.
|
|
120
|
+
* @returns A simple sort function or identity function.
|
|
109
121
|
*/
|
|
110
122
|
export declare const simpleSortValuesFunctionWithSortRef: <T>(sortRef: Maybe<Partial<SortCompareFunctionRef<T>>>, sortOnCopyDefault?: boolean) => SimpleSortValuesFunction<T>;
|
|
111
123
|
export interface MinAndMax<T> {
|
|
@@ -120,8 +132,16 @@ export type MinAndMaxFunctionResult<T> = MinAndMax<T> | null;
|
|
|
120
132
|
*/
|
|
121
133
|
export type MinAndMaxFunction<T> = (values: Iterable<T>) => MinAndMaxFunctionResult<T>;
|
|
122
134
|
/**
|
|
123
|
-
* Creates a MinAndMaxFunction using the
|
|
135
|
+
* Creates a {@link MinAndMaxFunction} that finds the minimum and maximum values from an iterable using the provided comparison function.
|
|
136
|
+
*
|
|
137
|
+
* @param compareFn - Ascending sort comparison function used to determine min/max.
|
|
138
|
+
* @returns A function that returns `{ min, max }` or `null` for empty iterables.
|
|
124
139
|
*
|
|
125
|
-
* @
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const fn = minAndMaxFunction<number>((a, b) => a - b);
|
|
143
|
+
* fn([3, 1, 4, 1, 5]); // { min: 1, max: 5 }
|
|
144
|
+
* fn([]); // null
|
|
145
|
+
* ```
|
|
126
146
|
*/
|
|
127
147
|
export declare function minAndMaxFunction<T>(compareFn: SortCompareFunction<T>): MinAndMaxFunction<T>;
|