@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.
Files changed (143) hide show
  1. package/fetch/package.json +2 -2
  2. package/index.cjs.js +4107 -1516
  3. package/index.esm.js +4107 -1516
  4. package/package.json +1 -2
  5. package/src/lib/array/array.d.ts +92 -47
  6. package/src/lib/array/array.find.d.ts +14 -18
  7. package/src/lib/array/array.index.d.ts +43 -14
  8. package/src/lib/array/array.indexed.d.ts +66 -17
  9. package/src/lib/array/array.limit.d.ts +11 -0
  10. package/src/lib/array/array.make.d.ts +9 -3
  11. package/src/lib/array/array.map.d.ts +20 -8
  12. package/src/lib/array/array.number.d.ts +63 -5
  13. package/src/lib/array/array.random.d.ts +12 -9
  14. package/src/lib/array/array.set.d.ts +24 -1
  15. package/src/lib/array/array.string.d.ts +104 -0
  16. package/src/lib/array/array.unique.d.ts +60 -8
  17. package/src/lib/array/array.value.d.ts +20 -11
  18. package/src/lib/assertion/assertion.d.ts +30 -2
  19. package/src/lib/assertion/assertion.generic.d.ts +8 -0
  20. package/src/lib/assertion/assertion.number.d.ts +16 -0
  21. package/src/lib/auth/auth.role.claims.d.ts +14 -8
  22. package/src/lib/boolean.d.ts +54 -1
  23. package/src/lib/contact/domain.d.ts +22 -4
  24. package/src/lib/contact/random.d.ts +24 -0
  25. package/src/lib/date/date.d.ts +8 -13
  26. package/src/lib/date/hour.d.ts +51 -32
  27. package/src/lib/date/minute.d.ts +4 -4
  28. package/src/lib/date/time.d.ts +12 -3
  29. package/src/lib/date/week.d.ts +77 -10
  30. package/src/lib/error/error.d.ts +54 -3
  31. package/src/lib/error/error.server.d.ts +25 -2
  32. package/src/lib/filter/filter.d.ts +12 -7
  33. package/src/lib/function/function.boolean.d.ts +4 -4
  34. package/src/lib/function/function.d.ts +2 -5
  35. package/src/lib/function/function.forward.d.ts +19 -3
  36. package/src/lib/getter/getter.cache.d.ts +9 -5
  37. package/src/lib/getter/getter.d.ts +39 -22
  38. package/src/lib/getter/getter.map.d.ts +10 -4
  39. package/src/lib/getter/getter.util.d.ts +3 -3
  40. package/src/lib/grouping.d.ts +98 -31
  41. package/src/lib/hash.d.ts +15 -8
  42. package/src/lib/iterable/iterable.d.ts +62 -50
  43. package/src/lib/iterable/iterable.map.d.ts +4 -4
  44. package/src/lib/iterate.d.ts +17 -1
  45. package/src/lib/key.d.ts +32 -10
  46. package/src/lib/lifecycle.d.ts +10 -1
  47. package/src/lib/map/map.d.ts +17 -16
  48. package/src/lib/map/map.intersection.d.ts +5 -4
  49. package/src/lib/map/map.key.d.ts +16 -15
  50. package/src/lib/misc/host.d.ts +6 -3
  51. package/src/lib/model/id.batch.d.ts +7 -3
  52. package/src/lib/model/id.factory.d.ts +16 -1
  53. package/src/lib/model/model.conversion.d.ts +49 -6
  54. package/src/lib/model/model.conversion.field.d.ts +13 -3
  55. package/src/lib/model/model.copy.d.ts +11 -0
  56. package/src/lib/model/model.d.ts +174 -1
  57. package/src/lib/model/model.modify.d.ts +24 -5
  58. package/src/lib/nodejs/stream.d.ts +8 -6
  59. package/src/lib/number/bitwise.dencoder.d.ts +43 -3
  60. package/src/lib/number/bound.d.ts +34 -5
  61. package/src/lib/number/dollar.d.ts +13 -6
  62. package/src/lib/number/factory.d.ts +11 -3
  63. package/src/lib/number/number.d.ts +55 -32
  64. package/src/lib/number/random.d.ts +13 -3
  65. package/src/lib/number/round.d.ts +47 -26
  66. package/src/lib/number/sort.d.ts +7 -1
  67. package/src/lib/number/transform.d.ts +16 -0
  68. package/src/lib/object/object.array.d.ts +16 -2
  69. package/src/lib/object/object.array.delta.d.ts +6 -2
  70. package/src/lib/object/object.d.ts +33 -5
  71. package/src/lib/object/object.empty.d.ts +4 -2
  72. package/src/lib/object/object.equal.d.ts +21 -4
  73. package/src/lib/object/object.filter.tuple.d.ts +105 -3
  74. package/src/lib/object/object.key.d.ts +13 -6
  75. package/src/lib/object/object.map.d.ts +30 -19
  76. package/src/lib/page/page.d.ts +21 -0
  77. package/src/lib/page/page.filter.d.ts +16 -9
  78. package/src/lib/path/path.d.ts +101 -14
  79. package/src/lib/path/path.tree.d.ts +16 -0
  80. package/src/lib/promise/callback.d.ts +18 -0
  81. package/src/lib/promise/is.d.ts +10 -3
  82. package/src/lib/promise/map.d.ts +5 -3
  83. package/src/lib/promise/poll.d.ts +14 -4
  84. package/src/lib/promise/promise.d.ts +84 -18
  85. package/src/lib/promise/promise.factory.d.ts +18 -2
  86. package/src/lib/promise/promise.limit.d.ts +22 -2
  87. package/src/lib/promise/promise.loop.d.ts +69 -1
  88. package/src/lib/promise/promise.ref.d.ts +14 -2
  89. package/src/lib/promise/promise.task.d.ts +8 -4
  90. package/src/lib/promise/promise.type.d.ts +4 -4
  91. package/src/lib/promise/use.d.ts +6 -4
  92. package/src/lib/promise/wait.d.ts +5 -2
  93. package/src/lib/relation/relation.d.ts +98 -0
  94. package/src/lib/service/handler.config.d.ts +47 -9
  95. package/src/lib/service/handler.d.ts +43 -1
  96. package/src/lib/service/typed.service.d.ts +21 -2
  97. package/src/lib/set/set.allowed.d.ts +6 -4
  98. package/src/lib/set/set.d.ts +174 -46
  99. package/src/lib/set/set.decision.d.ts +4 -2
  100. package/src/lib/set/set.delta.d.ts +16 -3
  101. package/src/lib/set/set.hashset.d.ts +43 -0
  102. package/src/lib/set/set.selection.d.ts +7 -3
  103. package/src/lib/sort.d.ts +36 -16
  104. package/src/lib/string/char.d.ts +48 -34
  105. package/src/lib/string/dencoder.d.ts +84 -13
  106. package/src/lib/string/factory.d.ts +13 -4
  107. package/src/lib/string/html.d.ts +7 -6
  108. package/src/lib/string/mimetype.d.ts +65 -1
  109. package/src/lib/string/prefix.d.ts +21 -7
  110. package/src/lib/string/record.d.ts +7 -4
  111. package/src/lib/string/replace.d.ts +77 -33
  112. package/src/lib/string/search.d.ts +19 -9
  113. package/src/lib/string/sort.d.ts +10 -1
  114. package/src/lib/string/string.d.ts +74 -21
  115. package/src/lib/string/transform.d.ts +7 -0
  116. package/src/lib/string/tree.d.ts +91 -29
  117. package/src/lib/string/url.d.ts +148 -63
  118. package/src/lib/tree/tree.explore.d.ts +84 -17
  119. package/src/lib/tree/tree.flatten.d.ts +44 -7
  120. package/src/lib/type.d.ts +15 -12
  121. package/src/lib/value/address.d.ts +66 -17
  122. package/src/lib/value/bound.d.ts +253 -17
  123. package/src/lib/value/build.d.ts +30 -5
  124. package/src/lib/value/comparator.d.ts +53 -25
  125. package/src/lib/value/cron.d.ts +14 -6
  126. package/src/lib/value/decision.d.ts +57 -13
  127. package/src/lib/value/equal.d.ts +44 -13
  128. package/src/lib/value/indexed.d.ts +253 -82
  129. package/src/lib/value/label.d.ts +16 -5
  130. package/src/lib/value/map.d.ts +77 -20
  131. package/src/lib/value/maybe.d.ts +47 -49
  132. package/src/lib/value/modifier.d.ts +82 -27
  133. package/src/lib/value/point.d.ts +248 -54
  134. package/src/lib/value/url.d.ts +10 -3
  135. package/src/lib/value/use.d.ts +99 -8
  136. package/src/lib/value/vector.d.ts +71 -9
  137. package/test/index.cjs.js +86 -23
  138. package/test/index.esm.js +86 -23
  139. package/test/package.json +2 -2
  140. package/test/src/lib/shared/shared.d.ts +31 -5
  141. package/test/src/lib/shared/shared.fail.d.ts +72 -9
  142. package/test/src/lib/shared/shared.function.d.ts +40 -2
  143. package/test/src/lib/shared/shared.wrap.d.ts +20 -1
@@ -31,8 +31,8 @@ export interface IndexRef {
31
31
  /**
32
32
  * Convenience function for calling readKeysToMap() and keying the values by their index number.
33
33
  *
34
- * @param items
35
- * @returns
34
+ * @param items - array of IndexRef items to index
35
+ * @returns a Map keyed by each item's index number
36
36
  */
37
37
  export declare function indexRefMap<T extends IndexRef>(items: T[]): Map<IndexNumber, T>;
38
38
  /**
@@ -40,10 +40,16 @@ export declare function indexRefMap<T extends IndexRef>(items: T[]): Map<IndexNu
40
40
  */
41
41
  export type MaybeIndexRef<T extends IndexRef> = Omit<T, 'i'> & Partial<Pick<T, 'i'>>;
42
42
  /**
43
- * Creates a SortCompareFunction<T> that sorts by index on IndexRef values.
43
+ * Creates a SortCompareFunction that sorts IndexRef values in ascending order by their index number.
44
44
  *
45
- * @param input
46
- * @returns
45
+ * @returns a compare function suitable for Array.sort()
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const items = [{ i: 4 }, { i: 0 }, { i: 2 }];
50
+ * items.sort(sortAscendingIndexNumberRefFunction());
51
+ * // items[0].i === 0
52
+ * ```
47
53
  */
48
54
  export declare function sortAscendingIndexNumberRefFunction<T extends IndexRef>(): SortCompareFunction<T>;
49
55
  /**
@@ -57,8 +63,8 @@ export type ReadMaybeIndexFunction<T> = (value: T) => Maybe<IndexNumber>;
57
63
  /**
58
64
  * Reads an IndexNumber from an IndexRef.
59
65
  *
60
- * @param indexRef
61
- * @returns
66
+ * @param indexRef - the ref to read from
67
+ * @returns the index number value
62
68
  */
63
69
  export declare function readIndexNumber(indexRef: IndexRef): IndexNumber;
64
70
  export interface IndexDeltaGroup<T> {
@@ -77,14 +83,42 @@ export interface IndexDeltaGroup<T> {
77
83
  */
78
84
  readonly deletedItems?: T[];
79
85
  }
86
+ /**
87
+ * Function that separates items into new, current, and deleted groups based on their index assignment.
88
+ */
80
89
  export type IndexDeltaGroupFunction<T> = (inputItems: T[], previousItems?: Maybe<T[]>) => IndexDeltaGroup<T>;
90
+ /**
91
+ * Creates an {@link IndexDeltaGroupFunction} that separates items into new (no index), current (has index),
92
+ * and deleted (present in previous but missing from current) groups. Useful for computing deltas when
93
+ * items are added or removed from an indexed collection.
94
+ *
95
+ * @param readIndex - reads an item's index, returning null/undefined for unindexed items
96
+ * @returns a function that groups items by their index state
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const groupFn = indexDeltaGroupFunction<{ x: string; i?: number }>((x) => x.i);
101
+ * const result = groupFn([{ x: 'a' }, { x: 'b', i: 0 }, { x: 'c', i: 1 }]);
102
+ *
103
+ * // result.newItems.length === 1 (item without an index)
104
+ * // result.currentItems.length === 2 (items with indexes)
105
+ * ```
106
+ */
81
107
  export declare function indexDeltaGroupFunction<T>(readIndex: ReadMaybeIndexFunction<T>): IndexDeltaGroupFunction<T>;
108
+ /**
109
+ * Convenience function that creates and immediately invokes an {@link IndexDeltaGroupFunction}.
110
+ *
111
+ * @param readIndex - reads an item's index
112
+ * @param inputItems - the current set of items
113
+ * @param previousItems - the previous set of items for computing deletions
114
+ * @returns the grouped delta result
115
+ */
82
116
  export declare function indexDeltaGroup<T>(readIndex: ReadMaybeIndexFunction<T>, inputItems: T[], previousItems?: Maybe<T[]>): IndexDeltaGroup<T>;
83
117
  /**
84
- * Creates a SortCompareFunction<T> that sorts by the read index.
118
+ * Creates a SortCompareFunction that sorts items in ascending order using a custom index reader.
85
119
  *
86
- * @param input
87
- * @returns
120
+ * @param readIndex - extracts the index number from each item
121
+ * @returns a compare function suitable for Array.sort()
88
122
  */
89
123
  export declare function sortByIndexAscendingCompareFunction<T>(readIndex: ReadIndexFunction<T>): SortCompareFunction<T>;
90
124
  /**
@@ -94,11 +128,28 @@ export declare function sortByIndexAscendingCompareFunction<T>(readIndex: ReadIn
94
128
  */
95
129
  export type ComputeNextFreeIndexFunction<T> = (values: T[]) => IndexNumber;
96
130
  /**
97
- * Creates a new ComputeNextFreeIndexFunction.
131
+ * Creates a {@link ComputeNextFreeIndexFunction} that finds the maximum index in the input and returns the next available one.
132
+ * Returns 0 when the input is empty.
133
+ *
134
+ * @param readIndex - extracts the index number from each item
135
+ * @param nextIndex - optional custom function to compute the next index from the max item; defaults to max + 1
136
+ * @returns a function that computes the next free index for a given array
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * const fn = computeNextFreeIndexFunction<IndexRef>((x) => x.i);
141
+ * const nextIndex = fn([{ i: 0 }, { i: 1 }, { i: 5 }]);
142
+ * // nextIndex === 6
143
+ * ```
98
144
  */
99
145
  export declare function computeNextFreeIndexFunction<T>(readIndex: ReadIndexFunction<T>, nextIndex?: (value: T) => IndexNumber): ComputeNextFreeIndexFunction<T>;
100
146
  /**
101
- * Creates a new ComputeNextFreeIndexFunction that assumes that the input values are sorted in ascending order, with the latest index at the end.
147
+ * Creates a {@link ComputeNextFreeIndexFunction} optimized for pre-sorted input arrays.
148
+ * Instead of scanning all items for the maximum, it reads only the last element.
149
+ *
150
+ * @param readIndex - extracts the index number from each item
151
+ * @param nextIndex - optional custom function to compute the next index from the last item; defaults to last + 1
152
+ * @returns a function that computes the next free index from sorted arrays
102
153
  */
103
154
  export declare function computeNextFreeIndexOnSortedValuesFunction<T>(readIndex: ReadIndexFunction<T>, nextIndex?: (value: T) => IndexNumber): ComputeNextFreeIndexFunction<T>;
104
155
  /**
@@ -108,17 +159,25 @@ export type MinAndMaxIndexFunction<T> = ((values: Iterable<T>) => MinAndMaxFunct
108
159
  readonly _readIndex: ReadIndexFunction<T>;
109
160
  };
110
161
  /**
111
- * Returns a MinAndMaxIndexFunction.
162
+ * Creates a {@link MinAndMaxIndexFunction} that extracts the minimum and maximum index numbers from a collection.
112
163
  *
113
- * @param readIndex
114
- * @returns
164
+ * @param readIndex - extracts the index number from each item
165
+ * @returns a function returning the min/max indexes, or null for empty input
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * const fn = minAndMaxIndexFunction<IndexRef>((x) => x.i);
170
+ * const result = fn([{ i: 3 }, { i: 0 }, { i: 5 }]);
171
+ * // result?.min === 0, result?.max === 5
172
+ * ```
115
173
  */
116
174
  export declare function minAndMaxIndexFunction<T>(readIndex: ReadIndexFunction<T>): MinAndMaxIndexFunction<T>;
117
175
  /**
118
- * Returns the min and max index value from the input IndexRef values.
176
+ * Returns the min and max index numbers from an array of IndexRef values.
177
+ * Convenience wrapper around {@link minAndMaxIndexFunction} using {@link readIndexNumber}.
119
178
  *
120
- * @param values
121
- * @returns
179
+ * @param values - the IndexRef items to scan
180
+ * @returns the min/max indexes, or null for empty input
122
181
  */
123
182
  export declare function minAndMaxIndex<T extends IndexRef>(values: T[]): MinAndMaxFunctionResult<IndexNumber>;
124
183
  /**
@@ -128,17 +187,18 @@ export type MinAndMaxIndexItemsFunction<T> = MinAndMaxFunction<T> & {
128
187
  readonly _readIndex: ReadIndexFunction<T>;
129
188
  };
130
189
  /**
131
- * Returns a MinAndMaxIndexItemsFunction.
190
+ * Creates a {@link MinAndMaxIndexItemsFunction} that returns the actual items (not just index numbers)
191
+ * with the minimum and maximum index values.
132
192
  *
133
- * @param readIndex
134
- * @returns
193
+ * @param readIndex - extracts the index number from each item
194
+ * @returns a function returning the min/max items, or null for empty input
135
195
  */
136
196
  export declare function minAndMaxIndexItemsFunction<T>(readIndex: ReadIndexFunction<T>): MinAndMaxIndexItemsFunction<T>;
137
197
  /**
138
- * Creates a HashSet with items keyed by their IndexNumber for the input values.
198
+ * Creates a HashSet with items keyed by their IndexNumber, providing O(1) lookups by index.
139
199
  *
140
- * @param input
141
- * @returns
200
+ * @param input - optional initial values to populate the set
201
+ * @returns a HashSet keyed by index number
142
202
  */
143
203
  export declare function hashSetForIndexed<T extends IndexRef>(input?: ArrayOrValue<T>): HashSet<IndexNumber, T>;
144
204
  export interface FindItemsByIndexInput<T extends IndexRef> extends Pick<FindValuesFromInput<T, IndexNumber>, 'values' | 'exclude'> {
@@ -148,40 +208,63 @@ export interface FindItemsByIndexInput<T extends IndexRef> extends Pick<FindValu
148
208
  readonly indexes: ArrayOrValue<IndexNumber>;
149
209
  }
150
210
  /**
151
- * Convenience function to return all values that match one of the input indexes.
211
+ * Returns all values whose index matches one of the specified indexes.
212
+ *
213
+ * @param config - specifies the values to search, indexes to match, and optional exclusion flag
214
+ * @returns the matching items
152
215
  *
153
- * @param values
216
+ * @example
217
+ * ```ts
218
+ * const values = [{ i: 0, name: '0' }, { i: 1, name: '1' }, { i: 2, name: '2' }];
219
+ * const result = findItemsByIndex({ values, indexes: [1, 2] });
220
+ * // result contains items with i === 1 and i === 2
221
+ * ```
154
222
  */
155
223
  export declare function findItemsByIndex<T extends IndexRef>(config: FindItemsByIndexInput<T>): T[];
156
224
  /**
157
225
  * Finds the best index match given the configured objects and returns the best match.
158
226
  */
159
227
  export type FindBestIndexMatchFunction<T> = <I extends IndexRef>(value: I) => T;
160
- export declare function findBestIndexMatchFunction<T extends IndexRef>(items: Iterable<T>): FindBestIndexMatchFunction<T>;
161
228
  /**
162
- * Finds the best match given the input.
229
+ * Creates a {@link FindBestIndexMatchFunction} from a set of IndexRef items.
230
+ * Given an input index, returns the item with the highest index that is less than or equal to the input.
231
+ *
232
+ * @param items - the available match options; must not be empty
233
+ * @returns a function that finds the best match for any input index
234
+ * @throws {Error} When the input iterable is empty
163
235
  *
164
- * Throws an error if the input is an empty array.
236
+ * @example
237
+ * ```ts
238
+ * const options = [{ i: 0 }, { i: 5 }, { i: 10 }];
239
+ * const fn = findBestIndexMatchFunction(options);
165
240
  *
166
- * @param input
167
- * @param i
168
- * @returns
241
+ * fn({ i: 4 }); // returns { i: 0 }
242
+ * fn({ i: 6 }); // returns { i: 5 }
243
+ * fn({ i: 11 }); // returns { i: 10 }
244
+ * ```
169
245
  */
170
- export declare function findBestIndexMatch<T extends IndexRef>(input: T[], i: IndexNumber): T;
246
+ export declare function findBestIndexMatchFunction<T extends IndexRef>(items: Iterable<T>): FindBestIndexMatchFunction<T>;
171
247
  /**
172
- * Finds the best match given the input.
248
+ * Finds the best match for the given index from the input array.
249
+ * Returns the item with the highest index that is less than or equal to `i`.
173
250
  *
174
- * Returns undefined if the input is an empty array.
251
+ * @param input - the available match options
252
+ * @param i - the target index to match against
253
+ * @returns the best matching item
254
+ * @throws {Error} When the input array is empty
255
+ */
256
+ export declare function findBestIndexMatch<T extends IndexRef>(input: T[], i: IndexNumber): T;
257
+ /**
258
+ * Safe variant of {@link findBestIndexMatch} that returns undefined instead of throwing when input is empty or null.
175
259
  *
176
- * @param input
177
- * @param i
178
- * @returns
260
+ * @param input - the available match options, or null/undefined
261
+ * @param i - the target index to match against
262
+ * @returns the best matching item, or undefined if input is empty/null
179
263
  */
180
264
  export declare function safeFindBestIndexMatch<T extends IndexRef>(input: Maybe<T[]>, i: IndexNumber): Maybe<T>;
181
265
  /**
182
- * Creates a FilterUniqueFunction that filters by the input value's index.
183
- *
184
- * @param readIndex
266
+ * Pre-built filter function that removes duplicate items based on their index number,
267
+ * keeping the first occurrence of each index.
185
268
  */
186
269
  export declare const filterUniqueByIndex: <T>(input: T[], exclude?: FilterUniqueFunctionExcludeKeysInput<T, IndexNumber>) => T[];
187
270
  /**
@@ -202,10 +285,11 @@ export interface IndexRange {
202
285
  */
203
286
  export type ReadIndexRangeFunction<T> = FactoryWithRequiredInput<IndexRange, T>;
204
287
  /**
205
- * Creates a SortCompareFunction<T> that sorts by the read index.
288
+ * Creates a SortCompareFunction that sorts items by their IndexRange in ascending order.
289
+ * Sorts by minIndex first, then by maxIndex for items with equal minIndex values.
206
290
  *
207
- * @param input
208
- * @returns
291
+ * @param readIndexRange - extracts the IndexRange from each item
292
+ * @returns a compare function suitable for Array.sort()
209
293
  */
210
294
  export declare function sortByIndexRangeAscendingCompareFunction<T>(readIndexRange: ReadIndexRangeFunction<T>): SortCompareFunction<T>;
211
295
  /**
@@ -220,44 +304,71 @@ export interface IndexRangeReaderPair<T = unknown> {
220
304
  */
221
305
  export type IndexRangeReaderPairFactory<T> = FactoryWithRequiredInput<IndexRangeReaderPair<T>, T>;
222
306
  /**
223
- * Creates a new IndexRangeReaderPairFactory
307
+ * Creates a new {@link IndexRangeReaderPairFactory} that pairs each value with its computed IndexRange.
224
308
  *
225
- * @param reader
226
- * @returns
309
+ * @param reader - reads the IndexRange from the input value
310
+ * @returns a factory that creates IndexRangeReaderPair instances
227
311
  */
228
312
  export declare function indexRangeReaderPairFactory<T>(reader: ReadIndexRangeFunction<T>): IndexRangeReaderPairFactory<T>;
229
313
  /**
230
- * An IndexNumber that represenst a range of a single index, or an IndexRange.
314
+ * An IndexNumber representing a single index, or a full IndexRange. Used as flexible input for functions
315
+ * that can accept either form.
231
316
  */
232
317
  export type IndexRangeInput = IndexNumber | IndexRange;
233
318
  /**
234
- * Creates an IndexRange from the input.
319
+ * Normalizes an {@link IndexRangeInput} to a full {@link IndexRange}. When given a single number,
320
+ * creates a range spanning that single index (minIndex = input, maxIndex = input + 1).
235
321
  *
236
- * @param input
237
- * @returns
322
+ * @param input - a single index number or an IndexRange
323
+ * @returns the normalized IndexRange
238
324
  */
239
325
  export declare function indexRange(input: IndexRangeInput): IndexRange;
326
+ /**
327
+ * Clamps an IndexNumber to fit within a given IndexRange (inclusive min, exclusive max).
328
+ */
240
329
  export type FitToIndexRangeFunction = (input: IndexNumber) => IndexNumber;
330
+ /**
331
+ * Creates a {@link FitToIndexRangeFunction} that clamps index numbers to the given range boundaries.
332
+ *
333
+ * @param input - the range to clamp to
334
+ * @returns a function that clamps any index to the range
335
+ */
241
336
  export declare function fitToIndexRangeFunction(input: IndexRange): FitToIndexRangeFunction;
337
+ /**
338
+ * Wraps an IndexNumber around to the other side of a range when it goes out of bounds.
339
+ */
242
340
  export type WrapIndexNumberFunction = WrapNumberFunction;
243
341
  /**
244
- * Creates a WrapNumberFunction.
342
+ * Creates a {@link WrapIndexNumberFunction} that wraps index numbers around the range boundaries,
343
+ * similar to modular arithmetic. Values that exceed the max wrap to the min side and vice versa.
344
+ *
345
+ * @param input - the index range to wrap within
346
+ * @param fencePosts - whether to use fencepost semantics (maxIndex is exclusive); defaults to true
347
+ * @returns a function that wraps any index into the range
245
348
  *
246
- * @param input
247
- * @param fencePosts
248
- * @returns
349
+ * @example
350
+ * ```ts
351
+ * const wrap = wrapIndexRangeFunction({ minIndex: 0, maxIndex: 6 });
352
+ * wrap(6); // 0 (wraps from positive side)
353
+ * wrap(-1); // 5 (wraps from negative side)
354
+ * ```
249
355
  */
250
356
  export declare function wrapIndexRangeFunction(input: IndexRange, fencePosts?: boolean): WrapIndexNumberFunction;
251
357
  /**
252
- * Checks whether or not the input number is in the range.
358
+ * Checks whether an item's index falls within a configured range.
253
359
  */
254
360
  export type IndexRefRangeCheckFunction<T> = (value: T) => boolean;
255
361
  /**
256
- * Creates an IndexRefRangeCheckFunction
362
+ * Creates an {@link IndexRefRangeCheckFunction} that reads an item's index and checks whether it falls
363
+ * within the specified range. For IndexRef types, the index is read from `i` automatically.
257
364
  *
258
- * @param range
365
+ * @param input - the range or range config to check against
259
366
  */
260
367
  export declare function indexRangeCheckReaderFunction<T extends IndexRef>(input: IndexRangeFunctionInput): IndexRefRangeCheckFunction<T>;
368
+ /**
369
+ * @param input - the range or range config to check against
370
+ * @param read - custom function to extract the index from the item
371
+ */
261
372
  export declare function indexRangeCheckReaderFunction<T>(input: IndexRangeFunctionInput, read: ReadIndexFunction<T>): IndexRefRangeCheckFunction<T>;
262
373
  /**
263
374
  * Checks whether or not the input number is in the range.
@@ -273,87 +384,147 @@ export interface IndexRangeFunctionConfig {
273
384
  */
274
385
  readonly inclusiveMaxIndex: boolean;
275
386
  }
387
+ /**
388
+ * Flexible input for range-checking functions: either a plain {@link IndexRange} or a full {@link IndexRangeFunctionConfig}
389
+ * with inclusive/exclusive options.
390
+ */
276
391
  export type IndexRangeFunctionInput = IndexRange | IndexRangeFunctionConfig;
392
+ /**
393
+ * Normalizes an {@link IndexRangeFunctionInput} to a full {@link IndexRangeFunctionConfig},
394
+ * defaulting `inclusiveMaxIndex` to false when a plain IndexRange is provided.
395
+ *
396
+ * @param input - the range or config to normalize
397
+ * @returns the normalized config
398
+ */
277
399
  export declare function asIndexRangeCheckFunctionConfig(input: IndexRangeFunctionInput): IndexRangeFunctionConfig;
278
400
  /**
279
- * Creates an IndexRangeCheckFunction
401
+ * Creates an {@link IndexRangeCheckFunction} that tests whether an index number falls within the configured range.
402
+ * The min is inclusive and the max is exclusive by default unless `inclusiveMaxIndex` is set.
280
403
  *
281
- * @param range
404
+ * @param input - the range or range config to check against
405
+ * @returns a predicate function for index numbers
282
406
  */
283
407
  export declare function indexRangeCheckFunction(input: IndexRangeFunctionInput): IndexRangeCheckFunction;
284
408
  /**
285
409
  * Returns true if the input index is contained within the configured IndexRange.
286
410
  */
287
411
  export type IsIndexNumberInIndexRangeFunction = (index: IndexNumber) => boolean;
412
+ /**
413
+ * Checks whether a single index number falls within the given IndexRange.
414
+ *
415
+ * @param index - the index number to test
416
+ * @param indexRange - the range to test against
417
+ * @param inclusiveMaxIndex - whether the max boundary is inclusive; defaults to false
418
+ * @returns true if the index is within range
419
+ */
288
420
  export declare function isIndexNumberInIndexRange(index: IndexNumber, indexRange: IndexRange, inclusiveMaxIndex?: boolean): boolean;
289
421
  /**
290
- * Creates an IsIndexNumberInIndexRangeFunction
422
+ * Creates an {@link IsIndexNumberInIndexRangeFunction} bound to the given range configuration.
291
423
  *
292
- * @param indexRange
293
- * @returns
424
+ * @param input - the range or range config to bind
425
+ * @returns a predicate that tests index numbers against the bound range
294
426
  */
295
427
  export declare function isIndexNumberInIndexRangeFunction(input: IndexRangeFunctionInput): IsIndexNumberInIndexRangeFunction;
296
428
  /**
297
429
  * Returns true if the input IndexRange is contained within the configured IndexRange.
298
430
  */
299
431
  export type IsIndexRangeInIndexRangeFunction = (indexRange: IndexRange) => boolean;
432
+ /**
433
+ * Checks whether `compareIndexRange` is entirely contained within `indexRange`.
434
+ *
435
+ * @param compareIndexRange - the range to test
436
+ * @param indexRange - the bounding range
437
+ * @returns true if the compare range is fully contained
438
+ */
300
439
  export declare function isIndexRangeInIndexRange(compareIndexRange: IndexRange, indexRange: IndexRange): boolean;
301
440
  /**
302
- * Creates an IsIndexRangeInIndexRangeFunction
441
+ * Creates an {@link IsIndexRangeInIndexRangeFunction} bound to the given range configuration.
303
442
  *
304
- * @param indexRange
305
- * @returns
443
+ * @param input - the bounding range or range config to bind
444
+ * @returns a predicate that tests whether index ranges are fully contained
306
445
  */
307
446
  export declare function isIndexRangeInIndexRangeFunction(input: IndexRangeFunctionInput): IsIndexRangeInIndexRangeFunction;
308
447
  /**
309
448
  * Returns true if the input IndexRange overlaps the configured IndexRange in any way.
310
449
  */
311
450
  export type IndexRangeOverlapsIndexRangeFunction = (indexRange: IndexRange) => boolean;
451
+ /**
452
+ * Checks whether `compareIndexRange` overlaps `indexRange` in any way (partial or full).
453
+ *
454
+ * @param compareIndexRange - the range to test for overlap
455
+ * @param indexRange - the reference range
456
+ * @returns true if any portion of the ranges overlap
457
+ */
312
458
  export declare function indexRangeOverlapsIndexRange(compareIndexRange: IndexRange, indexRange: IndexRange): boolean;
313
459
  /**
314
- * Creates an IndexRangeOverlapsIndexRangeFunction
460
+ * Creates an {@link IndexRangeOverlapsIndexRangeFunction} bound to the given range configuration.
315
461
  *
316
- * @param indexRange
317
- * @returns
462
+ * @param input - the reference range or range config to bind
463
+ * @returns a predicate that tests for overlap with the bound range
318
464
  */
319
465
  export declare function indexRangeOverlapsIndexRangeFunction(input: IndexRangeFunctionInput): IndexRangeOverlapsIndexRangeFunction;
320
466
  /**
321
- * Returns an array of all IndexNumbers within the input IndexRange.
322
- *
323
- * maxIndex is exclusive.
467
+ * Returns an array of all IndexNumbers within the input IndexRange (minIndex inclusive, maxIndex exclusive).
324
468
  *
325
- * @param indexRange
326
- * @returns
469
+ * @param indexRange - the range to enumerate
470
+ * @returns an array of sequential index numbers
327
471
  */
328
472
  export declare function allIndexesInIndexRange(indexRange: IndexRange): IndexNumber[];
473
+ /**
474
+ * Configuration for {@link stepsFromIndexFunction}.
475
+ */
329
476
  export interface StepsFromIndexFunctionConfig {
477
+ /**
478
+ * The index range to step within.
479
+ */
330
480
  readonly range: IndexRange;
331
481
  /**
332
- * Whether or not to fit start indexes that are outside of the range. If false, then returns undefined.
482
+ * Whether to clamp out-of-range start indexes into the range. When false, out-of-range starts return undefined.
333
483
  */
334
484
  readonly fitToRange?: boolean;
335
485
  /**
336
- * Whether or not to wrap the index to the other side of the range when stepping outside the bounds of the range.
486
+ * Whether to wrap around to the other side of the range when stepping past the boundaries.
337
487
  */
338
488
  readonly wrapAround?: boolean;
339
489
  /**
340
- * Whether or not to use fencePosts. Defaults to true.
490
+ * Whether to use fencepost semantics for wrapping. Defaults to true.
341
491
  */
342
492
  readonly fencePosts?: boolean;
493
+ /**
494
+ * Default number of steps to take. Defaults to 1.
495
+ */
343
496
  readonly steps?: number;
344
497
  }
498
+ /**
499
+ * Steps forward or backward from a start index within a range, with optional wrap-around and fit-to-range behavior.
500
+ * Exposes its bound config via the `_config` property.
501
+ */
345
502
  export type StepsFromIndexFunction = ((startIndex: number, wrapAround?: boolean, steps?: number) => Maybe<number>) & {
346
503
  readonly _config: StepsFromIndexFunctionConfig;
347
504
  };
348
- export declare function stepsFromIndexFunction(config: StepsFromIndexFunctionConfig): StepsFromIndexFunction;
349
505
  /**
350
- * Steps to the next index in the given direction based on the number of steps to take.
506
+ * Creates a {@link StepsFromIndexFunction} that computes the next index after stepping from a start position.
507
+ * Returns undefined when the result falls outside the range (unless wrapping or fitting is enabled).
351
508
  *
352
- * Starting indexes less than the minIndex are considered to not exist and will return undefined.
509
+ * @param config - stepping behavior configuration
510
+ * @returns a function that computes the stepped index
511
+ */
512
+ export declare function stepsFromIndexFunction(config: StepsFromIndexFunctionConfig): StepsFromIndexFunction;
513
+ /**
514
+ * Convenience function that steps from a start index within a range without pre-creating a reusable function.
353
515
  *
354
- * When wrapAround is true, indexes that are larger than the max index will be used to find an index that is that many steps into the index range.
516
+ * Start indexes outside the range return undefined. When `wrapAround` is true, out-of-bound results
517
+ * wrap to the other side of the range (e.g., stepping past maxIndex wraps to minIndex).
355
518
  *
356
- * For instance, an index of 5 on a range of 0 to 3 will return the index 1.
519
+ * @param range - the index range to step within
520
+ * @param startIndex - the starting position
521
+ * @param step - number of steps to take (positive or negative); defaults to 1
522
+ * @param wrapAround - whether to wrap out-of-bound results; defaults to false
523
+ * @returns the resulting index, or undefined if out of bounds without wrapping
357
524
  */
358
525
  export declare function stepsFromIndex(range: IndexRange, startIndex: number, step?: number, wrapAround?: boolean): Maybe<number>;
526
+ /**
527
+ * Pre-built decision function factory for determining whether an IndexRef item is selected,
528
+ * using the item's index number as the selection key.
529
+ */
359
530
  export declare const isSelectedIndexDecisionFunction: import("..").IsSelectedDecisionFunctionFactory<IndexRef, number>;
@@ -1,20 +1,31 @@
1
1
  import { type PrimativeKey } from '../key';
2
2
  /**
3
- * Refernce to a label string.
3
+ * Reference to a human-readable label string.
4
4
  */
5
5
  export interface LabelRef {
6
6
  label: string;
7
7
  }
8
8
  /**
9
- * Labeled value
9
+ * Pairs a value with a human-readable label, useful for dropdown options, tags, and display lists.
10
10
  */
11
11
  export interface LabeledValue<T> extends LabelRef {
12
12
  value: T;
13
13
  }
14
14
  /**
15
- * Creates a new Map of LabeledValue values.
15
+ * Creates a {@link Map} from an array of {@link LabeledValue} items, keyed by each item's value.
16
16
  *
17
- * @param values
18
- * @returns
17
+ * Enables fast lookup of labeled items by their value key.
18
+ *
19
+ * @param values - array of labeled values to index
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const items: LabeledValue<string>[] = [
24
+ * { value: 'a', label: 'Alpha' },
25
+ * { value: 'b', label: 'Beta' }
26
+ * ];
27
+ * const map = labeledValueMap(items);
28
+ * map.get('a')?.label; // 'Alpha'
29
+ * ```
19
30
  */
20
31
  export declare function labeledValueMap<V extends LabeledValue<T>, T extends PrimativeKey>(values: V[]): Map<T, V>;