@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
@@ -2,7 +2,7 @@ import { type ArrayOrValue } from '../array/array';
2
2
  import { type PromiseOrValue } from '../promise/promise.type';
3
3
  import { type Maybe, type MaybeNot } from './maybe.type';
4
4
  /**
5
- * Converts one value to another.
5
+ * Converts a value of one type to another, serving as the fundamental transformation primitive throughout the library.
6
6
  */
7
7
  export type MapFunction<I, O> = (input: I) => O;
8
8
  /**
@@ -12,45 +12,77 @@ export type MapFunction<I, O> = (input: I) => O;
12
12
  */
13
13
  export type ReadValueFunction<I, O> = MapFunction<I, O>;
14
14
  /**
15
- * Turns a normal MapFunction into one that passes through Maybe values without attempting to map them.
15
+ * Wraps a MapFunction so that null/undefined inputs are passed through without invoking the map,
16
+ * avoiding errors on nullable values.
16
17
  *
17
- * @param mapFunction
18
- * @returns
18
+ * @param mapFunction - function to apply only when the input is defined
19
+ * @returns a new function that short-circuits on null/undefined inputs
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const double = (x: number) => x * 2;
24
+ * const maybeDouble = mapMaybeFunction(double);
25
+ *
26
+ * maybeDouble(3); // 6
27
+ * maybeDouble(undefined); // undefined
28
+ * maybeDouble(null); // null
29
+ * ```
19
30
  */
20
31
  export declare function mapMaybeFunction<I, O>(mapFunction: MapFunction<I, O>): MapFunction<Maybe<I>, Maybe<O>>;
21
32
  /**
22
- * MapFunction with the same input as output.
33
+ * A MapFunction whose output type matches its input type, useful for in-place transformations or chained pipelines.
23
34
  */
24
35
  export type MapSameFunction<I> = MapFunction<I, I>;
25
36
  /**
26
- * Converts a MapFunction into one that returns a promise.
37
+ * Derives an asynchronous variant of a MapFunction, allowing the output to be either a value or a Promise.
27
38
  */
28
39
  export type AsyncMapFunction<F extends MapFunction<any, any>> = F extends MapFunction<infer I, infer O> ? MapFunction<I, PromiseOrValue<O>> : never;
29
40
  /**
30
- * Converts a MapFunction into one that takes in arrays and returns arrays.
41
+ * Derives an array variant of a MapFunction that maps each element individually, producing an array of results.
31
42
  */
32
43
  export type MapArrayFunction<F extends MapFunction<any, any>> = F extends MapFunction<infer I, infer O> ? MapFunction<I[], O[]> : never;
33
44
  /**
34
- * Converts values from the input, and applies them to the target if a target is supplied.
45
+ * Maps values from the input to the output type, optionally merging into an existing partial target object.
35
46
  */
36
47
  export type ApplyMapFunction<I, O> = (input: I, target?: Maybe<Partial<O>>) => O;
37
48
  /**
38
- * Converts values from the input, and applies them to the target if a target is supplied.
49
+ * Maps values from the input to the output type, optionally merging into a partial target and accepting additional options.
39
50
  */
40
51
  export type ApplyMapFunctionWithOptions<I, O, C> = (input: I, target?: Maybe<Partial<O>>, options?: Maybe<C>) => O;
52
+ /**
53
+ * Lifts a per-element MapFunction into one that operates on arrays, applying the mapping to each element.
54
+ *
55
+ * @param mapFunction - per-element transformation
56
+ * @returns a function that maps entire arrays
57
+ */
41
58
  export declare function mapArrayFunction<I, O>(mapFunction: MapFunction<I, O>): MapArrayFunction<MapFunction<I, O>>;
59
+ /**
60
+ * The canonical identity MapFunction. Returns its input unchanged.
61
+ *
62
+ * Used as a sentinel value so that {@link chainMapSameFunctions} and other combinators can detect
63
+ * and skip no-op mappings for efficiency.
64
+ */
42
65
  export declare const MAP_IDENTITY: <T>(input: T) => T;
66
+ /**
67
+ * Returns the shared {@link MAP_IDENTITY} function cast to the requested type, useful for providing a typed no-op transformation.
68
+ */
43
69
  export declare function mapIdentityFunction<T>(): MapFunction<T, T>;
70
+ /**
71
+ * Checks whether the given function is the singleton {@link MAP_IDENTITY} reference.
72
+ */
44
73
  export declare function isMapIdentityFunction(fn: unknown): fn is typeof MAP_IDENTITY;
74
+ /**
75
+ * Captures both the input and output of a MapFunction invocation, useful for debugging or auditing transformations.
76
+ */
45
77
  export type MapFunctionOutputPair<O, I = unknown> = {
46
78
  input: I;
47
79
  output: O;
48
80
  };
49
81
  /**
50
- * Wraps a MapFunction to instead provide the input and output values.
82
+ * Wraps a MapFunction so that each invocation returns a {@link MapFunctionOutputPair} containing both the original input and the computed output.
51
83
  *
52
- * @param fn
53
- * @returns
84
+ * @param fn - the map function to wrap
85
+ * @returns a new function that returns input/output pairs
54
86
  */
55
87
  export declare function mapFunctionOutputPair<O, I = unknown>(fn: MapFunction<I, O>): MapFunction<I, MapFunctionOutputPair<O, I>>;
56
88
  /**
@@ -60,25 +92,50 @@ export type MapFunctionOutput<O extends object, I = unknown> = O & {
60
92
  readonly _input: I;
61
93
  };
62
94
  /**
95
+ * Wraps a MapFunction so that its object output is augmented with a readonly `_input` property referencing the original input.
96
+ * Useful for retaining provenance through a transformation pipeline.
63
97
  *
64
- * @param fn
65
- * @returns
98
+ * @param fn - the map function whose output will be augmented
99
+ * @returns a new function that returns a {@link MapFunctionOutput} with the `_input` reference attached
66
100
  */
67
101
  export declare function wrapMapFunctionOutput<O extends object, I = unknown>(fn: MapFunction<I, O>): MapFunction<I, MapFunctionOutput<O, I>>;
102
+ /**
103
+ * Attaches a readonly `_input` property to the given output object, creating a {@link MapFunctionOutput}.
104
+ *
105
+ * @param output - the computed output object
106
+ * @param input - the original input value to attach
107
+ * @returns the output augmented with `_input`
108
+ */
68
109
  export declare function mapFunctionOutput<O extends object, I = unknown>(output: O, input: I): MapFunctionOutput<O, I>;
69
110
  /**
70
- * Chains together multiple MapSameFunctions in the same order. Functions that are not defined are ignored.
111
+ * Chains together multiple MapSameFunctions into a single pipeline executed left-to-right.
112
+ * Null/undefined entries and identity functions are automatically removed for efficiency.
113
+ * Returns the identity function if no meaningful functions remain.
114
+ *
115
+ * @param input - one or more optional same-type map functions to chain
116
+ * @returns a single composed function that runs all provided functions in order
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const fnChain = chainMapSameFunctions([
121
+ * (x: string) => x,
122
+ * (x: string) => x,
123
+ * ]);
71
124
  *
72
- * @param fns
125
+ * const result = fnChain('aaaab');
126
+ * // result === 'aaaab'
127
+ * ```
73
128
  */
74
129
  export declare function chainMapSameFunctions<I>(input: ArrayOrValue<Maybe<MapSameFunction<I>>>): MapSameFunction<I>;
75
130
  /**
76
- * Creates a single function that chains the two map functions together, if apply is true or undefined.
131
+ * Creates a single function that pipes the output of `a` into `b`.
77
132
  *
78
- * If apply is false, or the second map function is not defined, returns the first map function.
133
+ * If `apply` is false, or `b` is null/undefined, returns `a` unchanged. This conditional chaining
134
+ * is useful when a second transform step is optional.
79
135
  *
80
- * @param a
81
- * @param b
136
+ * @param a - the first map function
137
+ * @param b - the optional second map function to chain after `a`
138
+ * @param apply - when false, skips chaining and returns `a` directly
82
139
  */
83
140
  export declare function chainMapFunction<I>(a: MapSameFunction<I>, b: Maybe<MapSameFunction<I>>): MapSameFunction<I>;
84
141
  export declare function chainMapFunction<I>(a: MapSameFunction<I>, b: Maybe<MapSameFunction<I>>, apply?: boolean): MapSameFunction<I>;
@@ -1,107 +1,105 @@
1
1
  import { type Maybe, type MaybeNot, type MaybeSo } from './maybe.type';
2
2
  /**
3
- * Returns true if the value is not null or undefined.
3
+ * Type guard that returns `true` if the value is not `null` or `undefined`.
4
4
  *
5
- * @param value
6
- * @returns
5
+ * @param value - the value to check
7
6
  */
8
7
  export declare function hasNonNullValue<T = unknown>(value: Maybe<T>): value is MaybeSo<T>;
9
8
  /**
10
- * Whether or not the input has any value.
9
+ * Type guard that checks whether the input has a meaningful value.
11
10
  *
12
- * Will return false for:
13
- * - empty iterables
14
- * - empty strings
15
- * - null/undefined values.
11
+ * Returns `false` for empty iterables (arrays, Sets, Maps), empty strings, and nullish values.
12
+ * Non-iterable objects (e.g. `{}`) are considered non-empty by this function;
13
+ * use {@link hasValueOrNotEmptyObject} to also reject empty objects.
16
14
  *
17
15
  * NaN has undefined behavior.
16
+ *
17
+ * @param value - the value to check
18
18
  */
19
19
  export declare function hasValueOrNotEmpty<T = unknown>(value: Maybe<T>): value is MaybeSo<T>;
20
20
  /**
21
- * Whether or not the input has any value.
21
+ * Type guard that checks whether the input has a meaningful value, including checking for empty objects.
22
22
  *
23
- * Will return false for:
24
- * - empty iterables
25
- * - empty strings
26
- * - empty objects (no keys)
27
- * - null/undefined values.
23
+ * Returns `false` for empty iterables, empty strings, objects with no own keys (`{}`), and nullish values.
24
+ * This is stricter than {@link hasValueOrNotEmpty}, which considers `{}` as having a value.
28
25
  *
29
26
  * NaN has undefined behavior.
27
+ *
28
+ * @param value - the value to check
30
29
  */
31
30
  export declare function hasValueOrNotEmptyObject<T = unknown>(value: Maybe<T>): value is MaybeSo<T>;
32
31
  /**
33
- * Returns true if the input value is a non-empty string or is true.
32
+ * Returns `true` if the input value is a non-empty string or is `true`.
34
33
  *
35
- * @param value
36
- * @returns
34
+ * @param value - the value to check
37
35
  */
38
36
  export declare function isStringOrTrue(value: Maybe<string | boolean>): boolean;
39
37
  /**
40
- * Returns true if the input is not MaybeNot and not an empty string.
38
+ * Type guard that returns `true` if the input is not nullish and not an empty string.
39
+ *
40
+ * Useful for filtering out both nullish values and empty strings in a single check.
41
41
  *
42
- * @param value
43
- * @returns
42
+ * @param value - the value to check
44
43
  */
45
44
  export declare function isNotNullOrEmptyString<T>(value: Maybe<MaybeNot | '' | T>): value is MaybeSo<T>;
46
45
  /**
47
- * True if the input is MaybeNot.
46
+ * Type guard that returns `true` if the input is `null` or `undefined`.
48
47
  *
49
- * @param value
50
- * @returns
48
+ * @param value - the value to check
51
49
  */
52
50
  export declare function isMaybeNot<T = unknown>(value: Maybe<T>): value is MaybeNot;
53
51
  /**
54
- * True if the input is MaybeSo
52
+ * Type guard that returns `true` if the input is neither `null` nor `undefined`.
55
53
  *
56
- * @param value
57
- * @returns
54
+ * Equivalent to {@link hasNonNullValue} but with the `MaybeSo` narrowing type.
55
+ *
56
+ * @param value - the value to check
58
57
  */
59
58
  export declare function isMaybeSo<T>(value: Maybe<T>): value is MaybeSo<T>;
60
59
  /**
61
- * True if the input is MaybeNot and true.
60
+ * Type guard that returns `true` if the input is nullish or is strictly `true`.
61
+ *
62
+ * Useful for optional boolean flags where both absence and `true` indicate the same behavior.
62
63
  *
63
- * @param value
64
- * @returns
64
+ * @param value - the value to check
65
65
  */
66
66
  export declare function isMaybeNotOrTrue<T = unknown>(value: Maybe<T | true>): value is MaybeNot | true;
67
67
  /**
68
- * True if the input is not null/undefined/false.
68
+ * Returns `true` if the input is not `null`, `undefined`, or `false`.
69
69
  *
70
- * @param value
71
- * @returns
70
+ * @param value - the value to check
72
71
  */
73
72
  export declare function isDefinedAndNotFalse<T = unknown>(value: Maybe<T>): boolean;
74
73
  /**
75
- * True if the input is not false
74
+ * Returns `true` if the input is not strictly `false`. Nullish values return `true`.
76
75
  *
77
- * @param value
78
- * @returns
76
+ * @param value - the value to check
79
77
  */
80
78
  export declare function isNotFalse<T = unknown>(value: Maybe<T>): boolean;
81
79
  /**
82
- * Returns true if both the inputs are not null/undefined but the same value.
80
+ * Returns `true` if both inputs are non-nullish and strictly equal (`===`).
83
81
  *
84
- * @param a
85
- * @param b
86
- * @returns
82
+ * @param a - first value
83
+ * @param b - second value
87
84
  */
88
85
  export declare function isSameNonNullValue<T>(a: Maybe<T>, b: Maybe<T>): a is NonNullable<T>;
89
86
  /**
90
- * Returns true if both inputs are null/undefined, or are the same value.
87
+ * Returns `true` if both inputs are nullish (using loose equality `==`) or are strictly the same value.
88
+ *
89
+ * This means `null` and `undefined` are considered equivalent to each other, but `false` and `null` are not.
91
90
  *
92
- * @param a
93
- * @param b
94
- * @returns
91
+ * @param a - first value
92
+ * @param b - second value
95
93
  */
96
94
  export declare function valuesAreBothNullishOrEquivalent<T>(a: Maybe<T>, b: Maybe<T>): boolean;
97
95
  /**
98
- * Updates "a" with "b".
96
+ * Merges two `Maybe` values using `undefined` as the "no change" sentinel.
99
97
  *
100
- * - If b is defined, then returns b
101
- * - If b is undefined, then returns a
102
- * - If b is null, then returns null
98
+ * - If `b` is `undefined`, returns `a` (no update).
99
+ * - If `b` is `null`, returns `null` (explicit clear).
100
+ * - If `b` is defined, returns `b` (new value).
103
101
  *
104
- * @param a
105
- * @param b
102
+ * @param a - the current value
103
+ * @param b - the update value
106
104
  */
107
105
  export declare function updateMaybeValue<T>(a: Maybe<T>, b: Maybe<T>): Maybe<T>;
@@ -1,78 +1,133 @@
1
1
  import { type ArrayOrValue } from '../array';
2
2
  import { type Maybe } from './maybe.type';
3
3
  /**
4
- * Modifier key
4
+ * String key that uniquely identifies a modifier within a {@link ModifierMap}.
5
5
  */
6
6
  export type ModifierKey = string;
7
7
  /**
8
- * Modifies the input value.
8
+ * Function that mutates the input value in place.
9
9
  */
10
10
  export type ModifierFunction<T> = (input: T) => void;
11
11
  /**
12
- * Retains a reference to a ModifierFunction
12
+ * Holds a reference to a {@link ModifierFunction}.
13
13
  */
14
14
  export interface ModifierFunctionRef<T> {
15
15
  readonly modify: ModifierFunction<T>;
16
16
  }
17
17
  /**
18
- * A modifier that has a key and modify function.
18
+ * A keyed modifier that pairs a unique {@link ModifierKey} with a {@link ModifierFunction}.
19
+ *
20
+ * The key allows modifiers to be added, replaced, or removed from a {@link ModifierMap} by identity.
19
21
  */
20
22
  export interface Modifier<T> extends ModifierFunctionRef<T> {
21
23
  /**
22
- * Modifier key.
24
+ * Unique key identifying this modifier.
23
25
  */
24
26
  readonly key: ModifierKey;
25
27
  }
26
28
  /**
27
- * Creates a new modifier
29
+ * Creates a {@link Modifier} with the given key and modify function.
30
+ *
31
+ * @param key - unique identifier for the modifier
32
+ * @param modify - function that mutates the target value
28
33
  *
29
- * @param key
30
- * @param modify
31
- * @returns
34
+ * @example
35
+ * ```ts
36
+ * const uppercaseName = modifier<{ name: string }>('uppercase', (x) => { x.name = x.name.toUpperCase(); });
37
+ * const obj = { name: 'alice' };
38
+ * uppercaseName.modify(obj);
39
+ * // obj.name === 'ALICE'
40
+ * ```
32
41
  */
33
42
  export declare function modifier<T>(key: string, modify: ModifierFunction<T>): Modifier<T>;
34
43
  /**
35
- * No operation modifier.
44
+ * A no-operation modifier that does nothing to the input. Useful as a default/fallback.
36
45
  */
37
46
  export declare const NOOP_MODIFIER: ModifierFunction<any>;
38
47
  /**
39
- * Map of Modifiers keyed by the modifier key.
48
+ * Map of {@link Modifier} instances keyed by their {@link ModifierKey}, enabling lookup, replacement, and removal by key.
40
49
  */
41
50
  export type ModifierMap<T> = Map<ModifierKey, Modifier<T>>;
42
51
  /**
43
- * Adds a modifier to the modifier map and returns the map.
52
+ * Adds one or more modifiers to the map, creating a new map if none is provided.
53
+ *
54
+ * If a modifier with the same key already exists, it is replaced.
55
+ *
56
+ * @param modifiers - modifier(s) to add
57
+ * @param map - existing map to add to, or undefined to create a new one
44
58
  *
45
- * @param modifier
46
- * @param map
47
- * @returns
59
+ * @example
60
+ * ```ts
61
+ * const mod = modifier<{ x: number }>('double', (o) => { o.x *= 2; });
62
+ * const map = addModifiers(mod);
63
+ * map.has('double'); // true
64
+ * ```
48
65
  */
49
66
  export declare function addModifiers<T>(modifiers: ArrayOrValue<Modifier<T>>, map?: Maybe<ModifierMap<T>>): ModifierMap<T>;
50
67
  /**
51
- * Removes a modifier from the modifier map and returns the map.
68
+ * Removes one or more modifiers from the map by key. Returns an empty map if no map is provided.
52
69
  *
53
- * @param modifier
54
- * @param map
70
+ * @param modifiers - modifier(s) whose keys should be removed
71
+ * @param map - the map to remove from
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const mod = modifier<{ x: number }>('double', (o) => { o.x *= 2; });
76
+ * const map = addModifiers(mod);
77
+ * const result = removeModifiers(mod, map);
78
+ * result.has('double'); // false
79
+ * ```
55
80
  */
56
81
  export declare function removeModifiers<T>(modifiers: ArrayOrValue<Modifier<T>>, map: Maybe<ModifierMap<T>>): ModifierMap<T>;
82
+ /**
83
+ * Converts a {@link ModifierMap} to a single {@link ModifierFunction} that applies all modifiers in sequence.
84
+ *
85
+ * Returns {@link NOOP_MODIFIER} if the map is nullish or empty.
86
+ *
87
+ * @param map - the modifier map to convert
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const mod = modifier<{ x: number }>('inc', (o) => { o.x += 1; });
92
+ * const map = addModifiers(mod);
93
+ * const fn = modifierMapToFunction(map);
94
+ * const obj = { x: 0 };
95
+ * fn(obj);
96
+ * // obj.x === 1
97
+ * ```
98
+ */
57
99
  export declare function modifierMapToFunction<T>(map: Maybe<ModifierMap<T>>): ModifierFunction<T>;
58
100
  /**
59
- * Converts a ModifierMap to a ModifierFunction if the map is input or has functions. Otherwise returns undefined.
101
+ * Converts a {@link ModifierMap} to a single {@link ModifierFunction} if the map is non-null.
102
+ *
103
+ * Returns undefined if no map is provided, allowing callers to distinguish "no modifiers" from "empty modifiers".
60
104
  *
61
- * @param map
62
- * @returns
105
+ * @param map - the modifier map to convert
63
106
  */
64
107
  export declare function maybeModifierMapToFunction<T>(map: Maybe<ModifierMap<T>>): Maybe<ModifierFunction<T>>;
65
108
  /**
66
- * Merges all modifiers into a single function.
109
+ * Merges an array of {@link ModifierFunction} values into a single function that applies them all in order.
67
110
  *
68
- * @param map
69
- * @returns
111
+ * Returns {@link NOOP_MODIFIER} if the array is empty or nullish.
112
+ *
113
+ * @param modifiers - array of modifier functions to merge
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const add1 = (o: { x: number }) => { o.x += 1; };
118
+ * const double = (o: { x: number }) => { o.x *= 2; };
119
+ * const merged = mergeModifiers([add1, double]);
120
+ * const obj = { x: 3 };
121
+ * merged(obj);
122
+ * // obj.x === 8 (3 + 1 = 4, then 4 * 2 = 8)
123
+ * ```
70
124
  */
71
125
  export declare function mergeModifiers<T>(modifiers: ModifierFunction<T>[]): ModifierFunction<T>;
72
126
  /**
73
- * Merges all modifiers into a single function. If not modifier functions are input, returns
127
+ * Merges an array of {@link ModifierFunction} values into a single function. Returns undefined if the input is nullish.
128
+ *
129
+ * If only one modifier is provided, returns it directly without wrapping.
74
130
  *
75
- * @param map
76
- * @returns
131
+ * @param modifiers - array of modifier functions to merge, or undefined
77
132
  */
78
133
  export declare function maybeMergeModifiers<T>(modifiers: Maybe<ModifierFunction<T>[]>): Maybe<ModifierFunction<T>>;