@dereekb/util 13.10.9 → 13.11.1
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 +2578 -51
- package/index.esm.js +2568 -52
- package/package.json +1 -1
- package/src/lib/array/array.d.ts +79 -0
- package/src/lib/array/array.factory.d.ts +12 -0
- package/src/lib/array/array.find.d.ts +11 -0
- package/src/lib/array/array.limit.d.ts +5 -0
- package/src/lib/array/array.random.d.ts +16 -0
- package/src/lib/array/array.set.d.ts +20 -0
- package/src/lib/array/array.unique.d.ts +38 -0
- package/src/lib/array/array.value.d.ts +10 -0
- package/src/lib/auth/index.d.ts +2 -0
- package/src/lib/auth/oauth.d.ts +12 -0
- package/src/lib/auth/pkce.d.ts +13 -0
- package/src/lib/boolean.d.ts +36 -0
- package/src/lib/cache/cache.d.ts +48 -0
- package/src/lib/cache/cache.memoize.d.ts +59 -0
- package/src/lib/cache/cache.memory.d.ts +39 -0
- package/src/lib/cache/cache.merge.d.ts +48 -0
- package/src/lib/cache/index.d.ts +4 -0
- package/src/lib/contact/domain.d.ts +15 -0
- package/src/lib/contact/email.d.ts +15 -0
- package/src/lib/date/date.unix.d.ts +20 -0
- package/src/lib/date/expires.d.ts +85 -16
- package/src/lib/function/function.d.ts +5 -0
- package/src/lib/getter/getter.d.ts +21 -0
- package/src/lib/grouping.d.ts +30 -0
- package/src/lib/hash.d.ts +10 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/iterable/iterable.d.ts +20 -0
- package/src/lib/iterate.d.ts +5 -0
- package/src/lib/number/bound.d.ts +23 -0
- package/src/lib/number/number.d.ts +47 -0
- package/src/lib/number/random.d.ts +11 -0
- package/src/lib/number/round.d.ts +16 -0
- package/src/lib/object/object.d.ts +24 -0
- package/src/lib/object/object.empty.d.ts +5 -0
- package/src/lib/object/object.equal.d.ts +5 -0
- package/src/lib/object/object.filter.pojo.d.ts +31 -1
- package/src/lib/object/object.flatten.d.ts +4 -0
- package/src/lib/path/path.d.ts +191 -0
- package/src/lib/promise/is.d.ts +10 -0
- package/src/lib/promise/poll.d.ts +5 -0
- package/src/lib/promise/promise.d.ts +20 -0
- package/src/lib/promise/promise.type.d.ts +4 -0
- package/src/lib/promise/wait.d.ts +5 -0
- package/src/lib/set/set.d.ts +15 -0
- package/src/lib/sort.d.ts +16 -0
- package/src/lib/string/case.d.ts +10 -0
- package/src/lib/string/string.d.ts +54 -0
- package/src/lib/tree/tree.array.d.ts +6 -0
- package/src/lib/tree/tree.expand.d.ts +5 -0
- package/src/lib/tree/tree.explore.d.ts +24 -0
- package/src/lib/tree/tree.flatten.d.ts +16 -0
- package/src/lib/type.d.ts +20 -0
- package/src/lib/value/build.d.ts +4 -0
- package/src/lib/value/comparator.d.ts +11 -0
- package/src/lib/value/decision.d.ts +17 -0
- package/src/lib/value/equal.d.ts +17 -0
- package/src/lib/value/map.d.ts +23 -0
- package/src/lib/value/maybe.d.ts +49 -0
- package/src/lib/value/modifier.d.ts +5 -0
- package/test/package.json +2 -2
|
@@ -42,6 +42,11 @@ export declare const SPACE_JOINER = " ";
|
|
|
42
42
|
/**
|
|
43
43
|
* Joins an array of strings into a single string. Trims and omits empty values.
|
|
44
44
|
*
|
|
45
|
+
* @dbxUtil
|
|
46
|
+
* @dbxUtilCategory string
|
|
47
|
+
* @dbxUtilTags string, join, concat, combine, separator, delimiter
|
|
48
|
+
* @dbxUtilRelated split-join-remainder, join-strings-instance, string-split-join-instance
|
|
49
|
+
*
|
|
45
50
|
* @param input string or array of strings
|
|
46
51
|
* @param joiner string to join the strings with. Defaults to a comma.
|
|
47
52
|
* @param trim whether or not to trim the strings before joining. Defaults to false.
|
|
@@ -53,6 +58,11 @@ export declare function joinStrings(input: ArrayOrValue<Maybe<string>>, joiner?:
|
|
|
53
58
|
* Splits a string like {@link String.prototype.split}, but joins overflow segments back together
|
|
54
59
|
* instead of discarding them. Useful when you only want to split on the first N-1 occurrences.
|
|
55
60
|
*
|
|
61
|
+
* @dbxUtil
|
|
62
|
+
* @dbxUtilCategory string
|
|
63
|
+
* @dbxUtilTags string, split, limit, separator, parts, segments
|
|
64
|
+
* @dbxUtilRelated join-strings, string-split-join-instance
|
|
65
|
+
*
|
|
56
66
|
* @param input - string to split
|
|
57
67
|
* @param separator - delimiter to split on
|
|
58
68
|
* @param limit - maximum number of resulting segments; overflow segments are rejoined with the separator
|
|
@@ -175,6 +185,11 @@ export declare const SPACE_STRING_SPLIT_JOIN: StringSplitJoinInstance<SpaceSepar
|
|
|
175
185
|
/**
|
|
176
186
|
* Converts a string to its lowercase equivalent for case-insensitive comparison.
|
|
177
187
|
*
|
|
188
|
+
* @dbxUtil
|
|
189
|
+
* @dbxUtilCategory string
|
|
190
|
+
* @dbxUtilTags string, lowercase, case, normalize, compare
|
|
191
|
+
* @dbxUtilRelated capitalize-first-letter, lowercase-first-letter
|
|
192
|
+
*
|
|
178
193
|
* @param input - string to convert to lowercase
|
|
179
194
|
* @returns the lowercased string, or undefined if the input is undefined
|
|
180
195
|
*/
|
|
@@ -194,6 +209,11 @@ export declare function addPlusPrefixToNumber(value?: Maybe<number>, prefix?: st
|
|
|
194
209
|
/**
|
|
195
210
|
* Capitalizes the first letter of the input string.
|
|
196
211
|
*
|
|
212
|
+
* @dbxUtil
|
|
213
|
+
* @dbxUtilCategory string
|
|
214
|
+
* @dbxUtilTags string, capitalize, case, uppercase, first
|
|
215
|
+
* @dbxUtilRelated lowercase-first-letter, case-insensitive-string
|
|
216
|
+
*
|
|
197
217
|
* @param value - string to capitalize
|
|
198
218
|
* @returns the input string with its first character uppercased
|
|
199
219
|
*/
|
|
@@ -201,6 +221,11 @@ export declare function capitalizeFirstLetter(value: string): string;
|
|
|
201
221
|
/**
|
|
202
222
|
* Lowercases the first letter of the input string.
|
|
203
223
|
*
|
|
224
|
+
* @dbxUtil
|
|
225
|
+
* @dbxUtilCategory string
|
|
226
|
+
* @dbxUtilTags string, lowercase, case, first, decapitalize
|
|
227
|
+
* @dbxUtilRelated capitalize-first-letter, case-insensitive-string
|
|
228
|
+
*
|
|
204
229
|
* @param value - string to modify
|
|
205
230
|
* @returns the input string with its first character lowercased
|
|
206
231
|
*/
|
|
@@ -213,6 +238,11 @@ export type FirstNameLastNameTuple = [string, string | undefined];
|
|
|
213
238
|
* Splits the input string into a first name and last name tuple using a space as the delimiter.
|
|
214
239
|
* If the name contains more than one space, the remainder is treated as the last name.
|
|
215
240
|
*
|
|
241
|
+
* @dbxUtil
|
|
242
|
+
* @dbxUtilCategory string
|
|
243
|
+
* @dbxUtilTags string, name, split, first, last, person, parse
|
|
244
|
+
* @dbxUtilRelated split-join-remainder
|
|
245
|
+
*
|
|
216
246
|
* @param input - full name string to split
|
|
217
247
|
* @returns a tuple of [firstName, lastName], where lastName includes all text after the first space
|
|
218
248
|
*/
|
|
@@ -220,6 +250,10 @@ export declare function splitJoinNameString(input: string): FirstNameLastNameTup
|
|
|
220
250
|
/**
|
|
221
251
|
* Creates a string that repeats the given string a specified number of times.
|
|
222
252
|
*
|
|
253
|
+
* @dbxUtil
|
|
254
|
+
* @dbxUtilCategory string
|
|
255
|
+
* @dbxUtilTags string, repeat, build, generate, fill
|
|
256
|
+
*
|
|
223
257
|
* @param string - the string to repeat
|
|
224
258
|
* @param reapeat - number of times to repeat the string
|
|
225
259
|
* @returns the repeated string concatenation
|
|
@@ -257,6 +291,11 @@ export type CutStringFunction = ((input: string) => string) & ((input: Maybe<str
|
|
|
257
291
|
/**
|
|
258
292
|
* Creates a {@link CutStringFunction} that truncates strings exceeding the configured maximum length.
|
|
259
293
|
*
|
|
294
|
+
* @dbxUtil
|
|
295
|
+
* @dbxUtilCategory string
|
|
296
|
+
* @dbxUtilKind factory
|
|
297
|
+
* @dbxUtilTags string, cut, truncate, ellipsis, max-length, factory, abbreviate
|
|
298
|
+
*
|
|
260
299
|
* @param config - configuration controlling max length and end text behavior
|
|
261
300
|
* @returns a reusable function that truncates input strings
|
|
262
301
|
*/
|
|
@@ -264,6 +303,11 @@ export declare function cutStringFunction(config: CutStringFunctionConfig): CutS
|
|
|
264
303
|
/**
|
|
265
304
|
* Truncates a string to the given maximum length, appending end text (defaults to "...") if truncated.
|
|
266
305
|
*
|
|
306
|
+
* @dbxUtil
|
|
307
|
+
* @dbxUtilCategory string
|
|
308
|
+
* @dbxUtilTags string, cut, truncate, ellipsis, max-length, abbreviate, shorten
|
|
309
|
+
* @dbxUtilRelated cut-string-function
|
|
310
|
+
*
|
|
267
311
|
* @param input - the string to truncate, or null/undefined
|
|
268
312
|
* @param maxLength - maximum allowed length for the output string
|
|
269
313
|
* @param endText - text to append when truncated; defaults to "..."
|
|
@@ -275,6 +319,11 @@ export declare function cutString(input: Maybe<string>, maxLength: number, endTe
|
|
|
275
319
|
*
|
|
276
320
|
* Newlines are preserved.
|
|
277
321
|
*
|
|
322
|
+
* @dbxUtil
|
|
323
|
+
* @dbxUtilCategory string
|
|
324
|
+
* @dbxUtilTags string, whitespace, flatten, collapse, normalize, trim
|
|
325
|
+
* @dbxUtilRelated simplify-whitespace
|
|
326
|
+
*
|
|
278
327
|
* @param input - string to flatten
|
|
279
328
|
* @returns the string with collapsed whitespace
|
|
280
329
|
*/
|
|
@@ -282,6 +331,11 @@ export declare function flattenWhitespace(input: string): string;
|
|
|
282
331
|
/**
|
|
283
332
|
* Reduces multiple consecutive newlines to a single newline and collapses multiple whitespace characters to a single space.
|
|
284
333
|
*
|
|
334
|
+
* @dbxUtil
|
|
335
|
+
* @dbxUtilCategory string
|
|
336
|
+
* @dbxUtilTags string, whitespace, simplify, normalize, newline, trim
|
|
337
|
+
* @dbxUtilRelated flatten-whitespace
|
|
338
|
+
*
|
|
285
339
|
* @param input - string to simplify
|
|
286
340
|
* @returns the string with simplified whitespace and newlines
|
|
287
341
|
*/
|
|
@@ -16,6 +16,12 @@ export type ExpandFlattenTreeFunction<T, V> = (values: T[]) => V[];
|
|
|
16
16
|
* This higher-order function takes a function to expand an array of values `T` into a list of trees (`N[]` where `N` is a TreeNode)
|
|
17
17
|
* and another function to flatten these trees into a single array of values `V`.
|
|
18
18
|
*
|
|
19
|
+
* @dbxUtil
|
|
20
|
+
* @dbxUtilCategory tree
|
|
21
|
+
* @dbxUtilKind factory
|
|
22
|
+
* @dbxUtilTags tree, expand, flatten, compose, factory, transform
|
|
23
|
+
* @dbxUtilRelated expand-tree-function, flatten-tree-to-array-function, expand-trees
|
|
24
|
+
*
|
|
19
25
|
* @template T The type of the initial input values.
|
|
20
26
|
* @template V The type of the values in the final flattened output array.
|
|
21
27
|
* @template N The type of the intermediate tree nodes. Must extend TreeNode with value T and children of type N.
|
|
@@ -65,6 +65,11 @@ export declare function expandTreeFunction<T, N extends TreeNode<T, N>>(config:
|
|
|
65
65
|
* Convenience function for expanding multiple root values into an array of trees.
|
|
66
66
|
* Each value in the input array is treated as a root for a new tree.
|
|
67
67
|
*
|
|
68
|
+
* @dbxUtil
|
|
69
|
+
* @dbxUtilCategory tree
|
|
70
|
+
* @dbxUtilTags tree, expand, multiple, roots, hierarchy, build, batch
|
|
71
|
+
* @dbxUtilRelated expand-tree-function, expand-flatten-tree-function
|
|
72
|
+
*
|
|
68
73
|
* @template T The type of the input values.
|
|
69
74
|
* @template N The type of the TreeNode in the resulting trees. Must extend TreeNode<T, N>.
|
|
70
75
|
* @param values An array of root values of type T to expand.
|
|
@@ -3,6 +3,12 @@ import { type Maybe } from '../value/maybe.type';
|
|
|
3
3
|
import { type TreeNode } from './tree';
|
|
4
4
|
/**
|
|
5
5
|
* Decides how to visit a node during tree exploration.
|
|
6
|
+
*
|
|
7
|
+
* @dbxUtil
|
|
8
|
+
* @dbxUtilCategory tree
|
|
9
|
+
* @dbxUtilKind const
|
|
10
|
+
* @dbxUtilTags tree, explore, visit, decision, enum, traversal, control
|
|
11
|
+
* @dbxUtilRelated explore-tree-function, flatten-tree-add-node-decision
|
|
6
12
|
*/
|
|
7
13
|
export declare const ExploreTreeVisitNodeDecision: {
|
|
8
14
|
/**
|
|
@@ -94,6 +100,12 @@ export type ExploreTreeFunction<N extends TreeNode<unknown, N>, V> = (trees: Arr
|
|
|
94
100
|
* By default uses depth-first traversal, identity mapping, and visits all nodes. All options
|
|
95
101
|
* can be overridden per-call.
|
|
96
102
|
*
|
|
103
|
+
* @dbxUtil
|
|
104
|
+
* @dbxUtilCategory tree
|
|
105
|
+
* @dbxUtilKind factory
|
|
106
|
+
* @dbxUtilTags tree, explore, traverse, visit, factory, depth-first, breadth-first, walk
|
|
107
|
+
* @dbxUtilRelated depth-first-explore-tree-traversal-factory-function, breadth-first-explore-tree-traversal-factory-function, flatten-tree-to-array-function
|
|
108
|
+
*
|
|
97
109
|
* @param config - Optional default configuration for mapping, filtering, and traversal strategy.
|
|
98
110
|
* @returns A reusable function that explores trees with the configured behavior.
|
|
99
111
|
*
|
|
@@ -116,6 +128,12 @@ export declare function exploreTreeFunction<N extends TreeNode<unknown, N>, V>(c
|
|
|
116
128
|
* Visits each node before its children (pre-order). This is the default traversal
|
|
117
129
|
* strategy used by {@link exploreTreeFunction}.
|
|
118
130
|
*
|
|
131
|
+
* @dbxUtil
|
|
132
|
+
* @dbxUtilCategory tree
|
|
133
|
+
* @dbxUtilKind factory
|
|
134
|
+
* @dbxUtilTags tree, traverse, depth-first, dfs, pre-order, factory, strategy
|
|
135
|
+
* @dbxUtilRelated breadth-first-explore-tree-traversal-factory-function, explore-tree-function
|
|
136
|
+
*
|
|
119
137
|
* @returns A traversal factory that processes nodes in depth-first order.
|
|
120
138
|
*
|
|
121
139
|
* @example
|
|
@@ -133,6 +151,12 @@ export declare function depthFirstExploreTreeTraversalFactoryFunction<N extends
|
|
|
133
151
|
* Visits nodes level by level, processing all nodes at depth N before moving to depth N+1.
|
|
134
152
|
* Uses an internal queue to defer child processing until the current level is complete.
|
|
135
153
|
*
|
|
154
|
+
* @dbxUtil
|
|
155
|
+
* @dbxUtilCategory tree
|
|
156
|
+
* @dbxUtilKind factory
|
|
157
|
+
* @dbxUtilTags tree, traverse, breadth-first, bfs, level-order, factory, strategy, queue
|
|
158
|
+
* @dbxUtilRelated depth-first-explore-tree-traversal-factory-function, explore-tree-function
|
|
159
|
+
*
|
|
136
160
|
* @returns A traversal factory that processes nodes in breadth-first order.
|
|
137
161
|
*
|
|
138
162
|
* @example
|
|
@@ -15,6 +15,12 @@ import { type ExploreTreeFunctionConfig, ExploreTreeVisitNodeDecision, type Expl
|
|
|
15
15
|
export type FlattenTreeFunction<N extends TreeNode<unknown>, V> = (trees: ArrayOrValue<N>, array?: V[], addNodeFn?: Maybe<FlattenTreeAddNodeDecisionFunction<N, V>>) => V[];
|
|
16
16
|
/**
|
|
17
17
|
* Decides how to add a node to the flattened array during flattening.
|
|
18
|
+
*
|
|
19
|
+
* @dbxUtil
|
|
20
|
+
* @dbxUtilCategory tree
|
|
21
|
+
* @dbxUtilKind const
|
|
22
|
+
* @dbxUtilTags tree, flatten, decision, enum, traversal, control
|
|
23
|
+
* @dbxUtilRelated explore-tree-visit-node-decision, flatten-tree
|
|
18
24
|
*/
|
|
19
25
|
export declare const FlattenTreeAddNodeDecision: {
|
|
20
26
|
/**
|
|
@@ -48,6 +54,11 @@ export type FlattenTreeAddNodeDecisionFunction<N extends TreeNode<unknown>, V =
|
|
|
48
54
|
/**
|
|
49
55
|
* Flattens a tree into an array containing all its nodes using depth-first traversal.
|
|
50
56
|
*
|
|
57
|
+
* @dbxUtil
|
|
58
|
+
* @dbxUtilCategory tree
|
|
59
|
+
* @dbxUtilTags tree, flatten, traverse, depth-first, collect, nodes, array
|
|
60
|
+
* @dbxUtilRelated flatten-tree-to-array, flatten-tree-to-array-function, explore-tree-function
|
|
61
|
+
*
|
|
51
62
|
* @param tree - The root node to flatten.
|
|
52
63
|
* @param addNodeFn - Optional filter controlling which nodes and subtrees are included.
|
|
53
64
|
* @returns An array of all nodes in the tree that pass the filter.
|
|
@@ -64,6 +75,11 @@ export declare function flattenTree<N extends TreeNode<unknown> = TreeNode<unkno
|
|
|
64
75
|
*
|
|
65
76
|
* Useful for accumulating nodes from multiple trees into a single collection.
|
|
66
77
|
*
|
|
78
|
+
* @dbxUtil
|
|
79
|
+
* @dbxUtilCategory tree
|
|
80
|
+
* @dbxUtilTags tree, flatten, append, accumulate, collect, mutate, array
|
|
81
|
+
* @dbxUtilRelated flatten-tree, flatten-tree-to-array-function
|
|
82
|
+
*
|
|
67
83
|
* @param tree - The root node to flatten.
|
|
68
84
|
* @param array - The target array to push flattened nodes into.
|
|
69
85
|
* @param addNodeFn - Optional filter controlling which nodes and subtrees are included.
|
package/src/lib/type.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export type ObjectWithConstructor = {
|
|
|
17
17
|
* Returns true if the input is a function-like value with a prototype and constructor (i.e., a class or named function declaration).
|
|
18
18
|
* Returns false for arrow functions, class instances, plain objects, and primitives.
|
|
19
19
|
*
|
|
20
|
+
* @dbxUtil
|
|
21
|
+
* @dbxUtilCategory type
|
|
22
|
+
* @dbxUtilTags type, type-guard, function, class, constructor, reflection
|
|
23
|
+
* @dbxUtilRelated is-class-like-type, get-function-type, is-non-class-function
|
|
24
|
+
*
|
|
20
25
|
* @param obj - The value to check.
|
|
21
26
|
* @returns Whether the value is a function with a constructor.
|
|
22
27
|
*/
|
|
@@ -25,6 +30,11 @@ export declare function isObjectWithConstructor(obj: any): obj is ObjectWithCons
|
|
|
25
30
|
* Returns true if the input is a class (requires `new` to instantiate). Distinguishes classes from regular functions
|
|
26
31
|
* by checking that the prototype is non-writable.
|
|
27
32
|
*
|
|
33
|
+
* @dbxUtil
|
|
34
|
+
* @dbxUtilCategory type
|
|
35
|
+
* @dbxUtilTags type, type-guard, class, reflection, instance
|
|
36
|
+
* @dbxUtilRelated is-object-with-constructor, get-function-type
|
|
37
|
+
*
|
|
28
38
|
* @param obj - The value to check.
|
|
29
39
|
* @returns Whether the value is a class type.
|
|
30
40
|
*/
|
|
@@ -34,6 +44,11 @@ export type FunctionType = 'function' | 'class' | 'arrow';
|
|
|
34
44
|
* Determines the function type of the input value: `'class'`, `'function'`, or `'arrow'`.
|
|
35
45
|
* Returns `null` if the input is not a function.
|
|
36
46
|
*
|
|
47
|
+
* @dbxUtil
|
|
48
|
+
* @dbxUtilCategory type
|
|
49
|
+
* @dbxUtilTags type, function, class, arrow, reflection, kind, detect
|
|
50
|
+
* @dbxUtilRelated is-class-like-type, is-non-class-function, is-object-with-constructor
|
|
51
|
+
*
|
|
37
52
|
* @param x - The value to inspect.
|
|
38
53
|
* @returns The {@link FunctionType}, or `null` for non-functions.
|
|
39
54
|
*/
|
|
@@ -41,6 +56,11 @@ export declare function getFunctionType(x: unknown): Maybe<FunctionType>;
|
|
|
41
56
|
/**
|
|
42
57
|
* Returns true if the input is a function but not a class (i.e., a regular function or arrow function).
|
|
43
58
|
*
|
|
59
|
+
* @dbxUtil
|
|
60
|
+
* @dbxUtilCategory type
|
|
61
|
+
* @dbxUtilTags type, type-guard, function, arrow, reflection, callable
|
|
62
|
+
* @dbxUtilRelated is-class-like-type, get-function-type
|
|
63
|
+
*
|
|
44
64
|
* @param x - The value to check.
|
|
45
65
|
* @returns Whether the value is a non-class function.
|
|
46
66
|
*/
|
package/src/lib/value/build.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export interface BuildConfig<T extends object> {
|
|
|
32
32
|
* @param config.build - function that mutates the base object to populate it with desired values
|
|
33
33
|
* @returns the fully constructed object of type T
|
|
34
34
|
*
|
|
35
|
+
* @dbxUtil
|
|
36
|
+
* @dbxUtilCategory value
|
|
37
|
+
* @dbxUtilTags build, builder, construct, mutate, configure, factory
|
|
38
|
+
*
|
|
35
39
|
* @example
|
|
36
40
|
* ```ts
|
|
37
41
|
* interface User { name: string; age: number; }
|
|
@@ -14,6 +14,12 @@ export type EqualityComparatorFunction<T> = (a: T, b: T) => boolean;
|
|
|
14
14
|
* @param compare - the comparator to wrap
|
|
15
15
|
* @returns a new comparator that handles nullish values safely before delegating to the wrapped comparator
|
|
16
16
|
*
|
|
17
|
+
* @dbxUtil
|
|
18
|
+
* @dbxUtilCategory value
|
|
19
|
+
* @dbxUtilKind factory
|
|
20
|
+
* @dbxUtilTags equal, equality, compare, comparator, maybe, safe, factory
|
|
21
|
+
* @dbxUtilRelated safe-compare-equality
|
|
22
|
+
*
|
|
17
23
|
* @example
|
|
18
24
|
* ```ts
|
|
19
25
|
* const safeCompare = safeEqualityComparatorFunction((a: number, b: number) => a === b);
|
|
@@ -34,6 +40,11 @@ export declare function safeEqualityComparatorFunction<T>(compare: EqualityCompa
|
|
|
34
40
|
* @param compare - the equality comparator for non-nullish values
|
|
35
41
|
* @returns `true` if the values are considered equal
|
|
36
42
|
*
|
|
43
|
+
* @dbxUtil
|
|
44
|
+
* @dbxUtilCategory value
|
|
45
|
+
* @dbxUtilTags equal, equality, compare, maybe, safe
|
|
46
|
+
* @dbxUtilRelated safe-equality-comparator-function
|
|
47
|
+
*
|
|
37
48
|
* @example
|
|
38
49
|
* ```ts
|
|
39
50
|
* safeCompareEquality(0, 1, (a, b) => a === b);
|
|
@@ -21,6 +21,12 @@ export type DecisionFunctionFactory<C, I> = FactoryWithRequiredInput<DecisionFun
|
|
|
21
21
|
* @param decision - the constant boolean value to return
|
|
22
22
|
* @returns a decision function that always returns the given boolean
|
|
23
23
|
*
|
|
24
|
+
* @dbxUtil
|
|
25
|
+
* @dbxUtilCategory value
|
|
26
|
+
* @dbxUtilKind factory
|
|
27
|
+
* @dbxUtilTags decision, boolean, predicate, factory, constant
|
|
28
|
+
* @dbxUtilRelated as-decision-function, invert-decision
|
|
29
|
+
*
|
|
24
30
|
* @example
|
|
25
31
|
* ```ts
|
|
26
32
|
* const alwaysTrue = decisionFunction(true);
|
|
@@ -53,6 +59,11 @@ export declare const invertDecision: <F extends DecisionFunction<any>>(fn: F, in
|
|
|
53
59
|
* @param defaultIfUndefined - fallback boolean when the input is nullish (defaults to true)
|
|
54
60
|
* @returns a {@link DecisionFunction} derived from the input
|
|
55
61
|
*
|
|
62
|
+
* @dbxUtil
|
|
63
|
+
* @dbxUtilCategory value
|
|
64
|
+
* @dbxUtilTags decision, normalize, boolean, default, coerce, predicate
|
|
65
|
+
* @dbxUtilRelated decision-function, invert-decision
|
|
66
|
+
*
|
|
56
67
|
* @example
|
|
57
68
|
* ```ts
|
|
58
69
|
* const fn = asDecisionFunction(true);
|
|
@@ -72,6 +83,12 @@ export declare function asDecisionFunction<T = unknown>(valueOrFunction: Maybe<b
|
|
|
72
83
|
* @param equalityValue - the value to compare against, or an existing decision function
|
|
73
84
|
* @returns a decision function that checks strict equality with the given value
|
|
74
85
|
*
|
|
86
|
+
* @dbxUtil
|
|
87
|
+
* @dbxUtilCategory value
|
|
88
|
+
* @dbxUtilKind factory
|
|
89
|
+
* @dbxUtilTags decision, equal, equality, factory, predicate, compare
|
|
90
|
+
* @dbxUtilRelated decision-function, as-decision-function
|
|
91
|
+
*
|
|
75
92
|
* @example
|
|
76
93
|
* ```ts
|
|
77
94
|
* const isThree = isEqualToValueDecisionFunction(3);
|
package/src/lib/value/equal.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export type AreEqualContext<T = unknown> = (x: IterableOrValue<T>) => boolean;
|
|
|
18
18
|
* @param fn - the equality comparator
|
|
19
19
|
* @returns a function that checks whether a given value equals the captured reference
|
|
20
20
|
*
|
|
21
|
+
* @dbxUtil
|
|
22
|
+
* @dbxUtilCategory value
|
|
23
|
+
* @dbxUtilKind factory
|
|
24
|
+
* @dbxUtilTags equal, equality, compare, context, factory
|
|
25
|
+
* @dbxUtilRelated are-equal-context, all-objects-are-equal
|
|
26
|
+
*
|
|
21
27
|
* @example
|
|
22
28
|
* ```ts
|
|
23
29
|
* const isEqual = (a: number, b: number) => a === b;
|
|
@@ -38,6 +44,12 @@ export declare function isEqualContext<T>(contextValue: T, fn: EqualityComparato
|
|
|
38
44
|
* @param fn - the equality comparator
|
|
39
45
|
* @returns a function that checks whether all input values equal the captured reference
|
|
40
46
|
*
|
|
47
|
+
* @dbxUtil
|
|
48
|
+
* @dbxUtilCategory value
|
|
49
|
+
* @dbxUtilKind factory
|
|
50
|
+
* @dbxUtilTags equal, equality, compare, context, iterable, all, factory
|
|
51
|
+
* @dbxUtilRelated is-equal-context, all-objects-are-equal
|
|
52
|
+
*
|
|
41
53
|
* @example
|
|
42
54
|
* ```ts
|
|
43
55
|
* const isEqual = (a: number, b: number) => a === b;
|
|
@@ -58,6 +70,11 @@ export declare function areEqualContext<T>(contextValue: T, fn: EqualityComparat
|
|
|
58
70
|
* @param fn - the equality comparator
|
|
59
71
|
* @returns `true` if all values are equal to each other, or if fewer than two values are provided
|
|
60
72
|
*
|
|
73
|
+
* @dbxUtil
|
|
74
|
+
* @dbxUtilCategory value
|
|
75
|
+
* @dbxUtilTags equal, equality, compare, all, iterable, every
|
|
76
|
+
* @dbxUtilRelated is-equal-context, are-equal-context
|
|
77
|
+
*
|
|
61
78
|
* @example
|
|
62
79
|
* ```ts
|
|
63
80
|
* const isEqual = (a: unknown, b: unknown) => a === b;
|
package/src/lib/value/map.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export type ReadValueFunction<I, O> = MapFunction<I, O>;
|
|
|
18
18
|
* @param mapFunction - function to apply only when the input is defined
|
|
19
19
|
* @returns a new function that short-circuits on null/undefined inputs
|
|
20
20
|
*
|
|
21
|
+
* @dbxUtil
|
|
22
|
+
* @dbxUtilCategory value
|
|
23
|
+
* @dbxUtilKind factory
|
|
24
|
+
* @dbxUtilTags map, transform, maybe, nullish, factory, optional
|
|
25
|
+
* @dbxUtilRelated map-array-function, map-identity-function
|
|
26
|
+
*
|
|
21
27
|
* @example
|
|
22
28
|
* ```ts
|
|
23
29
|
* const double = (x: number) => x * 2;
|
|
@@ -52,6 +58,12 @@ export type ApplyMapFunctionWithOptions<I, O, C> = (input: I, target?: Maybe<Par
|
|
|
52
58
|
/**
|
|
53
59
|
* Lifts a per-element MapFunction into one that operates on arrays, applying the mapping to each element.
|
|
54
60
|
*
|
|
61
|
+
* @dbxUtil
|
|
62
|
+
* @dbxUtilCategory value
|
|
63
|
+
* @dbxUtilKind factory
|
|
64
|
+
* @dbxUtilTags map, transform, array, lift, factory
|
|
65
|
+
* @dbxUtilRelated map-maybe-function, chain-map-functions
|
|
66
|
+
*
|
|
55
67
|
* @param mapFunction - per-element transformation
|
|
56
68
|
* @returns a function that maps entire arrays
|
|
57
69
|
*/
|
|
@@ -62,6 +74,12 @@ export declare function mapArrayFunction<I, O>(mapFunction: MapFunction<I, O>):
|
|
|
62
74
|
* Used as a sentinel value so that {@link chainMapSameFunctions} and other combinators can detect
|
|
63
75
|
* and skip no-op mappings for efficiency.
|
|
64
76
|
*
|
|
77
|
+
* @dbxUtil
|
|
78
|
+
* @dbxUtilCategory value
|
|
79
|
+
* @dbxUtilKind const
|
|
80
|
+
* @dbxUtilTags map, identity, no-op, sentinel, pass-through, constant
|
|
81
|
+
* @dbxUtilRelated map-identity-function, is-map-identity-function
|
|
82
|
+
*
|
|
65
83
|
* @param input - the value to pass through unchanged
|
|
66
84
|
* @returns the same input value, unmodified
|
|
67
85
|
*/
|
|
@@ -123,6 +141,11 @@ export declare function mapFunctionOutput<O extends object, I = unknown>(output:
|
|
|
123
141
|
* @param input - one or more optional same-type map functions to chain
|
|
124
142
|
* @returns a single composed function that runs all provided functions in order
|
|
125
143
|
*
|
|
144
|
+
* @dbxUtil
|
|
145
|
+
* @dbxUtilCategory value
|
|
146
|
+
* @dbxUtilTags map, chain, compose, pipeline, identity, transform
|
|
147
|
+
* @dbxUtilRelated chain-map-function, map-identity-function
|
|
148
|
+
*
|
|
126
149
|
* @example
|
|
127
150
|
* ```ts
|
|
128
151
|
* const fnChain = chainMapSameFunctions([
|
package/src/lib/value/maybe.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { type Maybe, type MaybeNot, type MaybeSo } from './maybe.type';
|
|
|
2
2
|
/**
|
|
3
3
|
* Type guard that returns `true` if the value is not `null` or `undefined`.
|
|
4
4
|
*
|
|
5
|
+
* @dbxUtil
|
|
6
|
+
* @dbxUtilCategory value
|
|
7
|
+
* @dbxUtilTags maybe, nullish, type-guard, defined, not-null, value
|
|
8
|
+
* @dbxUtilRelated is-maybe-so, is-maybe-not, has-value-or-not-empty
|
|
9
|
+
*
|
|
5
10
|
* @param value - the value to check
|
|
6
11
|
* @returns `true` if the value is not `null` or `undefined`
|
|
7
12
|
*/
|
|
@@ -15,6 +20,11 @@ export declare function hasNonNullValue<T = unknown>(value: Maybe<T>): value is
|
|
|
15
20
|
*
|
|
16
21
|
* NaN has undefined behavior.
|
|
17
22
|
*
|
|
23
|
+
* @dbxUtil
|
|
24
|
+
* @dbxUtilCategory value
|
|
25
|
+
* @dbxUtilTags maybe, empty, type-guard, non-empty, value, has-value
|
|
26
|
+
* @dbxUtilRelated has-value-or-not-empty-object, has-non-null-value, is-not-null-or-empty-string
|
|
27
|
+
*
|
|
18
28
|
* @param value - the value to check
|
|
19
29
|
* @returns `true` if the value is non-nullish and not empty
|
|
20
30
|
*/
|
|
@@ -27,6 +37,11 @@ export declare function hasValueOrNotEmpty<T = unknown>(value: Maybe<T>): value
|
|
|
27
37
|
*
|
|
28
38
|
* NaN has undefined behavior.
|
|
29
39
|
*
|
|
40
|
+
* @dbxUtil
|
|
41
|
+
* @dbxUtilCategory value
|
|
42
|
+
* @dbxUtilTags maybe, empty, type-guard, object, non-empty, strict
|
|
43
|
+
* @dbxUtilRelated has-value-or-not-empty, has-non-null-value, object-has-no-keys
|
|
44
|
+
*
|
|
30
45
|
* @param value - the value to check
|
|
31
46
|
* @returns `true` if the value is non-nullish, non-empty, and not an empty object
|
|
32
47
|
*/
|
|
@@ -43,6 +58,11 @@ export declare function isStringOrTrue(value: Maybe<string | boolean>): boolean;
|
|
|
43
58
|
*
|
|
44
59
|
* Useful for filtering out both nullish values and empty strings in a single check.
|
|
45
60
|
*
|
|
61
|
+
* @dbxUtil
|
|
62
|
+
* @dbxUtilCategory value
|
|
63
|
+
* @dbxUtilTags maybe, string, empty, type-guard, nullish, non-empty
|
|
64
|
+
* @dbxUtilRelated has-value-or-not-empty, has-non-null-value
|
|
65
|
+
*
|
|
46
66
|
* @param value - the value to check
|
|
47
67
|
* @returns `true` if the value is not nullish and not an empty string
|
|
48
68
|
*/
|
|
@@ -50,6 +70,11 @@ export declare function isNotNullOrEmptyString<T>(value: Maybe<MaybeNot | '' | T
|
|
|
50
70
|
/**
|
|
51
71
|
* Type guard that returns `true` if the input is `null` or `undefined`.
|
|
52
72
|
*
|
|
73
|
+
* @dbxUtil
|
|
74
|
+
* @dbxUtilCategory value
|
|
75
|
+
* @dbxUtilTags maybe, nullish, type-guard, null, undefined, missing
|
|
76
|
+
* @dbxUtilRelated is-maybe-so, has-non-null-value
|
|
77
|
+
*
|
|
53
78
|
* @param value - the value to check
|
|
54
79
|
* @returns `true` if the value is `null` or `undefined`
|
|
55
80
|
*/
|
|
@@ -59,6 +84,11 @@ export declare function isMaybeNot<T = unknown>(value: Maybe<T>): value is Maybe
|
|
|
59
84
|
*
|
|
60
85
|
* Equivalent to {@link hasNonNullValue} but with the `MaybeSo` narrowing type.
|
|
61
86
|
*
|
|
87
|
+
* @dbxUtil
|
|
88
|
+
* @dbxUtilCategory value
|
|
89
|
+
* @dbxUtilTags maybe, nullish, type-guard, defined, present, non-null
|
|
90
|
+
* @dbxUtilRelated is-maybe-not, has-non-null-value
|
|
91
|
+
*
|
|
62
92
|
* @param value - the value to check
|
|
63
93
|
* @returns `true` if the value is neither `null` nor `undefined`
|
|
64
94
|
*/
|
|
@@ -75,6 +105,11 @@ export declare function isMaybeNotOrTrue<T = unknown>(value: Maybe<T | true>): v
|
|
|
75
105
|
/**
|
|
76
106
|
* Returns `true` if the input is not `null`, `undefined`, or `false`.
|
|
77
107
|
*
|
|
108
|
+
* @dbxUtil
|
|
109
|
+
* @dbxUtilCategory value
|
|
110
|
+
* @dbxUtilTags maybe, boolean, defined, truthy, type-guard
|
|
111
|
+
* @dbxUtilRelated is-not-false, has-non-null-value
|
|
112
|
+
*
|
|
78
113
|
* @param value - the value to check
|
|
79
114
|
* @returns `true` if the value is not `null`, `undefined`, or `false`
|
|
80
115
|
*/
|
|
@@ -89,6 +124,11 @@ export declare function isNotFalse<T = unknown>(value: Maybe<T>): boolean;
|
|
|
89
124
|
/**
|
|
90
125
|
* Returns `true` if both inputs are non-nullish and strictly equal (`===`).
|
|
91
126
|
*
|
|
127
|
+
* @dbxUtil
|
|
128
|
+
* @dbxUtilCategory value
|
|
129
|
+
* @dbxUtilTags maybe, equal, equality, compare, non-null
|
|
130
|
+
* @dbxUtilRelated values-are-both-nullish-or-equivalent, has-non-null-value
|
|
131
|
+
*
|
|
92
132
|
* @param a - first value
|
|
93
133
|
* @param b - second value
|
|
94
134
|
* @returns `true` if both values are non-nullish and strictly equal
|
|
@@ -99,6 +139,11 @@ export declare function isSameNonNullValue<T>(a: Maybe<T>, b: Maybe<T>): a is No
|
|
|
99
139
|
*
|
|
100
140
|
* This means `null` and `undefined` are considered equivalent to each other, but `false` and `null` are not.
|
|
101
141
|
*
|
|
142
|
+
* @dbxUtil
|
|
143
|
+
* @dbxUtilCategory value
|
|
144
|
+
* @dbxUtilTags maybe, equal, equality, nullish, compare
|
|
145
|
+
* @dbxUtilRelated is-same-non-null-value
|
|
146
|
+
*
|
|
102
147
|
* @param a - first value
|
|
103
148
|
* @param b - second value
|
|
104
149
|
* @returns `true` if both are nullish or both are the same value
|
|
@@ -111,6 +156,10 @@ export declare function valuesAreBothNullishOrEquivalent<T>(a: Maybe<T>, b: Mayb
|
|
|
111
156
|
* - If `b` is `null`, returns `null` (explicit clear).
|
|
112
157
|
* - If `b` is defined, returns `b` (new value).
|
|
113
158
|
*
|
|
159
|
+
* @dbxUtil
|
|
160
|
+
* @dbxUtilCategory value
|
|
161
|
+
* @dbxUtilTags maybe, update, merge, sentinel, patch, optional
|
|
162
|
+
*
|
|
114
163
|
* @param a - the current value
|
|
115
164
|
* @param b - the update value
|
|
116
165
|
* @returns `a` if `b` is undefined, otherwise `b`
|
|
@@ -36,6 +36,11 @@ export interface Modifier<T> extends ModifierFunctionRef<T> {
|
|
|
36
36
|
* @param modify - function that mutates the target value
|
|
37
37
|
* @returns a new {@link Modifier} pairing the key with the modify function
|
|
38
38
|
*
|
|
39
|
+
* @dbxUtil
|
|
40
|
+
* @dbxUtilCategory value
|
|
41
|
+
* @dbxUtilTags modifier, mutate, transform, key, factory
|
|
42
|
+
* @dbxUtilRelated apply-modifiers, modifier-function
|
|
43
|
+
*
|
|
39
44
|
* @example
|
|
40
45
|
* ```ts
|
|
41
46
|
* const uppercaseName = modifier<{ name: string }>('uppercase', (x) => { x.name = x.name.toUpperCase(); });
|