@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.
Files changed (64) hide show
  1. package/fetch/package.json +2 -2
  2. package/index.cjs.js +2578 -51
  3. package/index.esm.js +2568 -52
  4. package/package.json +1 -1
  5. package/src/lib/array/array.d.ts +79 -0
  6. package/src/lib/array/array.factory.d.ts +12 -0
  7. package/src/lib/array/array.find.d.ts +11 -0
  8. package/src/lib/array/array.limit.d.ts +5 -0
  9. package/src/lib/array/array.random.d.ts +16 -0
  10. package/src/lib/array/array.set.d.ts +20 -0
  11. package/src/lib/array/array.unique.d.ts +38 -0
  12. package/src/lib/array/array.value.d.ts +10 -0
  13. package/src/lib/auth/index.d.ts +2 -0
  14. package/src/lib/auth/oauth.d.ts +12 -0
  15. package/src/lib/auth/pkce.d.ts +13 -0
  16. package/src/lib/boolean.d.ts +36 -0
  17. package/src/lib/cache/cache.d.ts +48 -0
  18. package/src/lib/cache/cache.memoize.d.ts +59 -0
  19. package/src/lib/cache/cache.memory.d.ts +39 -0
  20. package/src/lib/cache/cache.merge.d.ts +48 -0
  21. package/src/lib/cache/index.d.ts +4 -0
  22. package/src/lib/contact/domain.d.ts +15 -0
  23. package/src/lib/contact/email.d.ts +15 -0
  24. package/src/lib/date/date.unix.d.ts +20 -0
  25. package/src/lib/date/expires.d.ts +85 -16
  26. package/src/lib/function/function.d.ts +5 -0
  27. package/src/lib/getter/getter.d.ts +21 -0
  28. package/src/lib/grouping.d.ts +30 -0
  29. package/src/lib/hash.d.ts +10 -0
  30. package/src/lib/index.d.ts +1 -0
  31. package/src/lib/iterable/iterable.d.ts +20 -0
  32. package/src/lib/iterate.d.ts +5 -0
  33. package/src/lib/number/bound.d.ts +23 -0
  34. package/src/lib/number/number.d.ts +47 -0
  35. package/src/lib/number/random.d.ts +11 -0
  36. package/src/lib/number/round.d.ts +16 -0
  37. package/src/lib/object/object.d.ts +24 -0
  38. package/src/lib/object/object.empty.d.ts +5 -0
  39. package/src/lib/object/object.equal.d.ts +5 -0
  40. package/src/lib/object/object.filter.pojo.d.ts +31 -1
  41. package/src/lib/object/object.flatten.d.ts +4 -0
  42. package/src/lib/path/path.d.ts +191 -0
  43. package/src/lib/promise/is.d.ts +10 -0
  44. package/src/lib/promise/poll.d.ts +5 -0
  45. package/src/lib/promise/promise.d.ts +20 -0
  46. package/src/lib/promise/promise.type.d.ts +4 -0
  47. package/src/lib/promise/wait.d.ts +5 -0
  48. package/src/lib/set/set.d.ts +15 -0
  49. package/src/lib/sort.d.ts +16 -0
  50. package/src/lib/string/case.d.ts +10 -0
  51. package/src/lib/string/string.d.ts +54 -0
  52. package/src/lib/tree/tree.array.d.ts +6 -0
  53. package/src/lib/tree/tree.expand.d.ts +5 -0
  54. package/src/lib/tree/tree.explore.d.ts +24 -0
  55. package/src/lib/tree/tree.flatten.d.ts +16 -0
  56. package/src/lib/type.d.ts +20 -0
  57. package/src/lib/value/build.d.ts +4 -0
  58. package/src/lib/value/comparator.d.ts +11 -0
  59. package/src/lib/value/decision.d.ts +17 -0
  60. package/src/lib/value/equal.d.ts +17 -0
  61. package/src/lib/value/map.d.ts +23 -0
  62. package/src/lib/value/maybe.d.ts +49 -0
  63. package/src/lib/value/modifier.d.ts +5 -0
  64. package/test/package.json +2 -2
@@ -46,6 +46,11 @@ export type PercentDecimal = number;
46
46
  *
47
47
  * Returns 0 for null/undefined input.
48
48
  *
49
+ * @dbxUtil
50
+ * @dbxUtilCategory number
51
+ * @dbxUtilTags number, percent, decimal, convert, ratio
52
+ * @dbxUtilRelated percent-number-from-decimal
53
+ *
49
54
  * @param input - A percent number value (e.g., 5 means 5%)
50
55
  * @returns The decimal equivalent
51
56
  */
@@ -55,6 +60,11 @@ export declare function percentNumberToDecimal(input: Maybe<number>): number;
55
60
  *
56
61
  * Returns 0 for null/undefined input.
57
62
  *
63
+ * @dbxUtil
64
+ * @dbxUtilCategory number
65
+ * @dbxUtilTags number, percent, decimal, convert, ratio
66
+ * @dbxUtilRelated percent-number-to-decimal
67
+ *
58
68
  * @param input - A decimal percent value (e.g., 0.05 means 5%)
59
69
  * @returns The percent number equivalent
60
70
  */
@@ -73,6 +83,10 @@ export type AsNumberInput = Maybe<NumberOrNumberString>;
73
83
  *
74
84
  * Strings are parsed via `Number()`. Null/undefined returns 0.
75
85
  *
86
+ * @dbxUtil
87
+ * @dbxUtilCategory number
88
+ * @dbxUtilTags number, parse, convert, coerce, string, normalize
89
+ *
76
90
  * @param input - A number, number string, or null/undefined
77
91
  * @returns The numeric value, or 0 for null/undefined
78
92
  */
@@ -82,6 +96,11 @@ export declare function asNumber(input: AsNumberInput): number;
82
96
  *
83
97
  * Treats null/undefined as 0.
84
98
  *
99
+ * @dbxUtil
100
+ * @dbxUtilCategory number
101
+ * @dbxUtilTags number, divisible, modulo, division, math, check
102
+ * @dbxUtilRelated nearest-divisible-values, is-even-number, is-odd-number
103
+ *
85
104
  * @param value - The number to check
86
105
  * @param divisor - The divisor to test against
87
106
  * @returns `true` if the remainder is zero
@@ -96,6 +115,11 @@ export interface NearestDivisibleValues {
96
115
  /**
97
116
  * Finds the nearest values that are evenly divisible by the divisor, both above (ceil) and below (floor) the input value.
98
117
  *
118
+ * @dbxUtil
119
+ * @dbxUtilCategory number
120
+ * @dbxUtilTags number, divisible, nearest, ceil, floor, round, snap, math
121
+ * @dbxUtilRelated is-number-divisible-by
122
+ *
99
123
  * @param value - The value to find divisible neighbors for
100
124
  * @param divisor - The divisor to align to
101
125
  * @returns Object with the input value, divisor, and the nearest ceil/floor divisible values
@@ -104,6 +128,11 @@ export declare function nearestDivisibleValues(value: number, divisor: number):
104
128
  /**
105
129
  * Checks whether the input is an even number.
106
130
  *
131
+ * @dbxUtil
132
+ * @dbxUtilCategory number
133
+ * @dbxUtilTags number, even, parity, math, check
134
+ * @dbxUtilRelated is-odd-number, is-number-divisible-by
135
+ *
107
136
  * @param value - Number to test
108
137
  * @returns `true` if even
109
138
  */
@@ -111,6 +140,11 @@ export declare function isEvenNumber(value: number): boolean;
111
140
  /**
112
141
  * Checks whether the input is an odd number.
113
142
  *
143
+ * @dbxUtil
144
+ * @dbxUtilCategory number
145
+ * @dbxUtilTags number, odd, parity, math, check
146
+ * @dbxUtilRelated is-even-number, is-number-divisible-by
147
+ *
114
148
  * @param value - Number to test
115
149
  * @returns `true` if odd
116
150
  */
@@ -120,6 +154,10 @@ export declare function isOddNumber(value: number): boolean;
120
154
  *
121
155
  * The `from` value is floored and the `to` value is ceiled before computation.
122
156
  *
157
+ * @dbxUtil
158
+ * @dbxUtilCategory number
159
+ * @dbxUtilTags number, sum, range, integers, math, gauss, total
160
+ *
123
161
  * @param from - The starting value (floored to nearest integer)
124
162
  * @param to - The ending value (ceiled to nearest integer)
125
163
  * @returns Sum of all integers in the range
@@ -136,6 +174,11 @@ export declare const sortCompareNumberFunction: SortCompareFunction<number>;
136
174
  /**
137
175
  * Finds the minimum and maximum values from an iterable of numbers.
138
176
  *
177
+ * @dbxUtil
178
+ * @dbxUtilCategory number
179
+ * @dbxUtilTags number, min, max, range, sort, bounds, extremes
180
+ * @dbxUtilRelated sort-compare-number-function
181
+ *
139
182
  * @param values - Iterable of numbers to examine
140
183
  * @returns Object with `min` and `max` values
141
184
  */
@@ -143,6 +186,10 @@ export declare function minAndMaxNumber(values: Iterable<number>): MinAndMaxFunc
143
186
  /**
144
187
  * Computes the logarithm of `y` with base `x`.
145
188
  *
189
+ * @dbxUtil
190
+ * @dbxUtilCategory number
191
+ * @dbxUtilTags number, log, logarithm, math, base
192
+ *
146
193
  * @param x - The base of the logarithm
147
194
  * @param y - The value to compute the logarithm of
148
195
  * @returns The base-x logarithm of y
@@ -29,6 +29,12 @@ export type RandomNumberFactoryInput = number | RandomNumberFactoryConfig;
29
29
  *
30
30
  * Accepts either a simple max number or a full config object with min, max, and rounding options.
31
31
  *
32
+ * @dbxUtil
33
+ * @dbxUtilCategory number
34
+ * @dbxUtilKind factory
35
+ * @dbxUtilTags number, random, factory, range, min, max, generate
36
+ * @dbxUtilRelated random-number, rounding-function
37
+ *
32
38
  * @param maxOrArgs - Maximum value (exclusive) or full configuration object
33
39
  * @param roundingInput - Optional rounding mode override
34
40
  * @returns A factory function that produces random numbers within the range
@@ -37,6 +43,11 @@ export declare function randomNumberFactory(maxOrArgs: RandomNumberFactoryInput,
37
43
  /**
38
44
  * Generates a single random number using {@link randomNumberFactory}. Convenience function for one-off usage.
39
45
  *
46
+ * @dbxUtil
47
+ * @dbxUtilCategory number
48
+ * @dbxUtilTags number, random, range, generate
49
+ * @dbxUtilRelated random-number-factory
50
+ *
40
51
  * @param maxOrArgs - Maximum value (exclusive) or full configuration object
41
52
  * @param roundingInput - Optional rounding mode
42
53
  * @returns A single random number
@@ -7,6 +7,12 @@ export type RoundingFunction = MapFunction<number, number>;
7
7
  /**
8
8
  * Returns a rounding function for the specified rounding type.
9
9
  *
10
+ * @dbxUtil
11
+ * @dbxUtilCategory number
12
+ * @dbxUtilKind factory
13
+ * @dbxUtilTags number, round, floor, ceil, math, factory, rounding
14
+ * @dbxUtilRelated cut-value-to-precision-function, round-to-precision-function
15
+ *
10
16
  * @param type - The rounding strategy: 'floor', 'ceil', 'round', or 'none'
11
17
  * @returns The corresponding Math function, or an identity function for 'none'
12
18
  */
@@ -25,6 +31,11 @@ export type NumberPrecision = number;
25
31
  *
26
32
  * Accepts strings and null/undefined via {@link asNumber}.
27
33
  *
34
+ * @dbxUtil
35
+ * @dbxUtilCategory number
36
+ * @dbxUtilTags number, precision, decimal, truncate, cut, round
37
+ * @dbxUtilRelated cut-value-to-precision-function, cut-value-to-integer, round-to-precision
38
+ *
28
39
  * @param input - Number, number string, or null/undefined
29
40
  * @param precision - Number of decimal places to retain
30
41
  * @returns The truncated number value
@@ -37,6 +48,11 @@ export declare const CUT_VALUE_TO_ZERO_PRECISION: CutValueToPrecisionFunction;
37
48
  /**
38
49
  * Truncates a value to an integer by cutting to zero decimal precision.
39
50
  *
51
+ * @dbxUtil
52
+ * @dbxUtilCategory number
53
+ * @dbxUtilTags number, integer, truncate, floor, cut, parse
54
+ * @dbxUtilRelated cut-value-to-precision, as-number
55
+ *
40
56
  * @param input - Number, number string, or null/undefined
41
57
  * @returns The truncated integer value
42
58
  */
@@ -24,6 +24,11 @@ export type EmptyObject = Record<string, never>;
24
24
  /**
25
25
  * Checks whether the object has no own enumerable keys.
26
26
  *
27
+ * @dbxUtil
28
+ * @dbxUtilCategory object
29
+ * @dbxUtilTags object, empty, keys, check, type-guard
30
+ * @dbxUtilRelated object-has-key, object-has-keys, has-value-or-not-empty-object
31
+ *
27
32
  * @param obj - Object to check
28
33
  * @returns `true` if the object has zero keys
29
34
  */
@@ -31,6 +36,11 @@ export declare function objectHasNoKeys(obj: object): obj is EmptyObject;
31
36
  /**
32
37
  * Checks whether the object has the specified own property using `Object.prototype.hasOwnProperty`.
33
38
  *
39
+ * @dbxUtil
40
+ * @dbxUtilCategory object
41
+ * @dbxUtilTags object, key, has, own-property, check
42
+ * @dbxUtilRelated object-has-keys, object-has-no-keys
43
+ *
34
44
  * @param obj - Object to check
35
45
  * @param key - Property key to test for
36
46
  * @returns `true` if the object has the key as an own property
@@ -41,6 +51,11 @@ export declare function objectHasKey<T, K extends keyof T>(obj: T, key: K): bool
41
51
  /**
42
52
  * Checks whether the object has all or any of the specified keys, based on the mode.
43
53
  *
54
+ * @dbxUtil
55
+ * @dbxUtilCategory object
56
+ * @dbxUtilTags object, keys, has, check, all, any
57
+ * @dbxUtilRelated object-has-key, object-has-no-keys
58
+ *
44
59
  * @param obj - Object to check
45
60
  * @param keys - Keys to test for
46
61
  * @param mode - Whether to require 'all' keys or just 'any'; defaults to 'all'
@@ -62,6 +77,10 @@ export declare function applyToMultipleFields<T extends object, X = unknown>(val
62
77
  /**
63
78
  * Converts a Map to a plain object by iterating entries and assigning key-value pairs.
64
79
  *
80
+ * @dbxUtil
81
+ * @dbxUtilCategory object
82
+ * @dbxUtilTags object, map, convert, transform, dictionary
83
+ *
65
84
  * @param map - Map to convert
66
85
  * @returns A plain object with the same key-value pairs
67
86
  */
@@ -75,6 +94,11 @@ export type CopyObjectFunction<T> = (input: T) => T;
75
94
  /**
76
95
  * Creates a shallow copy of an object using the spread operator.
77
96
  *
97
+ * @dbxUtil
98
+ * @dbxUtilCategory object
99
+ * @dbxUtilTags object, copy, clone, shallow, spread
100
+ * @dbxUtilRelated copy-array
101
+ *
78
102
  * @param input - Object to copy
79
103
  * @returns A new object with the same properties
80
104
  */
@@ -3,6 +3,11 @@ import { type Maybe } from '../value/maybe.type';
3
3
  * Recursively checks whether an object is "empty" — meaning it is null/undefined, has no keys,
4
4
  * or all of its values are themselves empty (recursively for nested objects, or falsy for primitives).
5
5
  *
6
+ * @dbxUtil
7
+ * @dbxUtilCategory object
8
+ * @dbxUtilTags object, empty, recursive, deep, check, has-value
9
+ * @dbxUtilRelated object-has-no-keys, has-value-or-not-empty-object
10
+ *
6
11
  * @param obj - Object to check
7
12
  * @returns `true` if the object is considered empty
8
13
  */
@@ -6,6 +6,11 @@ import { type FilterFromPOJOFunction } from './object.filter.pojo';
6
6
  *
7
7
  * Recursively compares arrays, objects, Maps, Sets, primitives, and Dates.
8
8
  *
9
+ * @dbxUtil
10
+ * @dbxUtilCategory object
11
+ * @dbxUtilTags object, equal, equality, deep, compare, recursive, pojo
12
+ * @dbxUtilRelated are-equal-pojo-values-using-pojo-filter, all-objects-are-equal
13
+ *
9
14
  * @param a - First value to compare
10
15
  * @param b - Second value to compare
11
16
  * @returns `true` if the values are deeply equal
@@ -6,10 +6,40 @@ import { type FilterKeyValueTuplesInput, type KeyValueTuple, type KeyValueTupleF
6
6
  */
7
7
  export type StripObjectFunction<T extends object> = (input: Maybe<T>, copy?: Maybe<boolean>) => T | undefined;
8
8
  /**
9
+ * Creates a reusable {@link StripObjectFunction} that filters values from an object and returns
10
+ * `undefined` when no keys remain after filtering.
9
11
  *
10
- * @param input
12
+ * Useful when an upstream consumer treats an "empty" object as a missing value (e.g. for skipping
13
+ * persistence or omitting a field from a request body).
14
+ *
15
+ * @param filter - Filter controlling which key/value pairs are removed from the input object.
16
+ * @param copy - When true (default), the returned function shallow-copies the input before filtering instead of mutating it.
17
+ * @returns A function that returns the stripped object, or `undefined` when filtering removed every key.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const stripUndef = stripObjectFunction(KeyValueTypleValueFilter.UNDEFINED);
22
+ * stripUndef({ a: 1, b: undefined }); // { a: 1 }
23
+ * stripUndef({ a: undefined }); // undefined
24
+ * ```
11
25
  */
12
26
  export declare function stripObjectFunction<T extends object>(filter: FilterKeyValueTuplesInput<T>, copy?: boolean): StripObjectFunction<T>;
27
+ /**
28
+ * Removes `undefined` values from the input object and returns `undefined` when no keys remain.
29
+ *
30
+ * Convenience wrapper around {@link stripObjectFunction} pre-configured to filter out `undefined`.
31
+ *
32
+ * @param input - The object to strip; null/undefined inputs short-circuit and return `undefined`.
33
+ * @param copy - When true (default), shallow-copies the input before filtering instead of mutating it.
34
+ * @returns The stripped object, or `undefined` when input was missing or filtering removed every key.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * stripObject({ a: 1, b: undefined }); // { a: 1 }
39
+ * stripObject({ a: undefined }); // undefined
40
+ * stripObject(null); // undefined
41
+ * ```
42
+ */
13
43
  export declare function stripObject<T extends object>(input: Maybe<T>, copy?: boolean): T | undefined;
14
44
  /**
15
45
  * Assigns all non-filtered values from one or more source objects into the target object.
@@ -24,6 +24,10 @@ export interface FlattenObjectConfig {
24
24
  * Empty nested objects are omitted from the result (they produce no keys).
25
25
  * Circular references are detected and treated as leaf values to avoid infinite recursion.
26
26
  *
27
+ * @dbxUtil
28
+ * @dbxUtilCategory object
29
+ * @dbxUtilTags object, flatten, flat, nested, dot-notation, deep, traverse
30
+ *
27
31
  * @example
28
32
  * ```ts
29
33
  * flattenObject({ a: 1, b: { c: 2, d: { e: 3 } } });