@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
@@ -0,0 +1,39 @@
1
+ import { type Maybe } from '../value/maybe.type';
2
+ import { type AsyncKeyedValueCache, type AsyncValueCache } from './cache';
3
+ /**
4
+ * Creates an in-memory {@link AsyncValueCache} backed by a single closure-scoped variable.
5
+ *
6
+ * Useful as the inner of {@link memoizeAsyncValueCache} and as a stand-in for tests.
7
+ *
8
+ * @param initialValue - Optional starting value for the cache. When omitted (or null), the cache starts empty and {@link AsyncValueCache.load} resolves to undefined.
9
+ * @returns An {@link AsyncValueCache} that stores the latest written value in process memory.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const cache = inMemoryAsyncValueCache<string>('hello');
14
+ * await cache.load(); // 'hello'
15
+ * await cache.update('world');
16
+ * await cache.load(); // 'world'
17
+ * ```
18
+ */
19
+ export declare function inMemoryAsyncValueCache<T>(initialValue?: Maybe<T>): AsyncValueCache<T>;
20
+ /**
21
+ * Creates an in-memory {@link AsyncKeyedValueCache} backed by a closure-scoped record.
22
+ *
23
+ * Useful as the inner of {@link memoizeAsyncKeyedValueCache} and as a stand-in for tests.
24
+ *
25
+ * Backed by a null-prototype object so inherited properties (`toString`, `hasOwnProperty`, etc.)
26
+ * are never returned from `get` and `__proto__` keys cannot mutate the prototype chain.
27
+ *
28
+ * @param initialEntries - Optional starting entries for the cache. When omitted (or null), the cache starts empty.
29
+ * @returns An {@link AsyncKeyedValueCache} that stores entries in process memory.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const cache = inMemoryAsyncKeyedValueCache<number>({ a: 1 });
34
+ * await cache.get('a'); // 1
35
+ * await cache.set('b', 2);
36
+ * await cache.load(); // { a: 1, b: 2 }
37
+ * ```
38
+ */
39
+ export declare function inMemoryAsyncKeyedValueCache<T>(initialEntries?: Maybe<Record<string, T>>): AsyncKeyedValueCache<T>;
@@ -0,0 +1,48 @@
1
+ import { type AsyncKeyedValueCache, type AsyncValueCache } from './cache';
2
+ /**
3
+ * Composes multiple {@link AsyncValueCache} instances into a single read-from-first-write-to-all cache.
4
+ *
5
+ * - {@link AsyncValueCache.load} returns the first non-null/undefined value from the input caches in order.
6
+ * - {@link AsyncValueCache.update} writes the value to every input cache, propagating from the
7
+ * lowest-precedence (slowest, source-of-truth) tier up to the highest-precedence (fastest) tier
8
+ * so a failed write to the backing store is not masked by a successful write to memory.
9
+ * - {@link AsyncValueCache.clear} clears every input cache in the same lower-to-higher order.
10
+ *
11
+ * Useful for memory-then-disk layering or for combining a fast tier with a slow source-of-truth tier.
12
+ *
13
+ * @param caches - Ordered tiers from highest-precedence (fastest, e.g. memory) to lowest-precedence (source-of-truth, e.g. disk). Reads honor this order; writes propagate in reverse.
14
+ * @returns A single {@link AsyncValueCache} layered across the provided tiers.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const layered = mergeAsyncValueCaches<string>([
19
+ * inMemoryAsyncValueCache(),
20
+ * diskBackedAsyncValueCache()
21
+ * ]);
22
+ * await layered.update('hello'); // writes to disk first, then memory
23
+ * await layered.load(); // returns from memory if present
24
+ * ```
25
+ */
26
+ export declare function mergeAsyncValueCaches<T>(caches: ReadonlyArray<AsyncValueCache<T>>): AsyncValueCache<T>;
27
+ /**
28
+ * Composes multiple {@link AsyncKeyedValueCache} instances into a single read-from-first-write-to-all cache.
29
+ *
30
+ * - {@link AsyncKeyedValueCache.get} returns the first non-null/undefined value from the input caches in order for a given key.
31
+ * - {@link AsyncKeyedValueCache.load} returns a merged record where earlier caches' entries take precedence over later caches'.
32
+ * - Writes ({@link AsyncKeyedValueCache.set} / {@link AsyncKeyedValueCache.remove}) propagate to every input cache.
33
+ * - {@link AsyncKeyedValueCache.clear} clears every input cache.
34
+ *
35
+ * @param caches - Ordered tiers from highest-precedence (fastest, e.g. memory) to lowest-precedence (source-of-truth, e.g. disk). Reads honor this order; writes propagate in reverse.
36
+ * @returns A single {@link AsyncKeyedValueCache} layered across the provided tiers.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const layered = mergeAsyncKeyedValueCaches<number>([
41
+ * inMemoryAsyncKeyedValueCache(),
42
+ * diskBackedAsyncKeyedValueCache()
43
+ * ]);
44
+ * await layered.set('a', 1); // writes to disk first, then memory
45
+ * await layered.get('a'); // returns from memory if present
46
+ * ```
47
+ */
48
+ export declare function mergeAsyncKeyedValueCaches<T>(caches: ReadonlyArray<AsyncKeyedValueCache<T>>): AsyncKeyedValueCache<T>;
@@ -0,0 +1,4 @@
1
+ export * from './cache';
2
+ export * from './cache.memory';
3
+ export * from './cache.memoize';
4
+ export * from './cache.merge';
@@ -11,6 +11,11 @@ export type EmailAddressDomain = string;
11
11
  /**
12
12
  * Extracts unique domain names from a list of email addresses (case-insensitive).
13
13
  *
14
+ * @dbxUtil
15
+ * @dbxUtilCategory contact
16
+ * @dbxUtilTags email, domain, extract, unique, dedupe, case-insensitive
17
+ * @dbxUtilRelated read-domain-from-email-address, read-email-domain-from-url-or-email-address
18
+ *
14
19
  * @param addresses - Array of email addresses to extract domains from
15
20
  * @returns Array of unique lowercase domain strings
16
21
  */
@@ -18,6 +23,11 @@ export declare function readDomainsFromEmailAddresses(addresses: EmailAddress[])
18
23
  /**
19
24
  * Extracts the domain portion from a single email address.
20
25
  *
26
+ * @dbxUtil
27
+ * @dbxUtilCategory contact
28
+ * @dbxUtilTags email, domain, extract, parse, lowercase
29
+ * @dbxUtilRelated read-domains-from-email-addresses, read-email-domain-from-url-or-email-address
30
+ *
21
31
  * @param address - The email address to extract the domain from
22
32
  * @returns The lowercase domain string
23
33
  */
@@ -33,6 +43,11 @@ export declare function readDomainFromEmailAddress(address: EmailAddress): Email
33
43
  *
34
44
  * The "www." prefix is stripped from URL-style inputs since emails typically don't use it.
35
45
  *
46
+ * @dbxUtil
47
+ * @dbxUtilCategory contact
48
+ * @dbxUtilTags email, domain, url, extract, normalize, parse, www
49
+ * @dbxUtilRelated read-domain-from-email-address, read-domains-from-email-addresses
50
+ *
36
51
  * @param urlLikeInput - A URL, email address, or domain string
37
52
  * @returns The extracted domain
38
53
  */
@@ -32,6 +32,11 @@ export type EmailParticipantString = string;
32
32
  * Converts an EmailParticipant object to a formatted string representation.
33
33
  * The format is: "name<email>" or "<email>" if no name is provided.
34
34
  *
35
+ * @dbxUtil
36
+ * @dbxUtilCategory contact
37
+ * @dbxUtilTags email, participant, convert, format, serialize, name
38
+ * @dbxUtilRelated convert-email-participant-string-to-participant, coerce-to-email-participants
39
+ *
35
40
  * @param participant - The email participant to convert
36
41
  * @returns A formatted string representation of the participant
37
42
  */
@@ -40,6 +45,11 @@ export declare function convertParticipantToEmailParticipantString(participant:
40
45
  * Converts a formatted participant string into an EmailParticipant object.
41
46
  * Parses strings in the format "name<email>" or "<email>".
42
47
  *
48
+ * @dbxUtil
49
+ * @dbxUtilCategory contact
50
+ * @dbxUtilTags email, participant, parse, deserialize, name, address
51
+ * @dbxUtilRelated convert-participant-to-email-participant-string, coerce-to-email-participants
52
+ *
43
53
  * @param participantString - The string to parse
44
54
  * @returns An EmailParticipant object with the extracted name and email
45
55
  */
@@ -48,6 +58,11 @@ export declare function convertEmailParticipantStringToParticipant(participantSt
48
58
  * Combines an array of EmailParticipants with an array of email addresses.
49
59
  * Email addresses that don't already exist in the participants array are converted to EmailParticipant objects.
50
60
  *
61
+ * @dbxUtil
62
+ * @dbxUtilCategory contact
63
+ * @dbxUtilTags email, participant, merge, combine, dedupe, coerce, normalize
64
+ * @dbxUtilRelated convert-participant-to-email-participant-string, convert-email-participant-string-to-participant
65
+ *
51
66
  * @param options - Object containing participants and/or emails arrays
52
67
  * @param options.participants - Array of existing EmailParticipant objects
53
68
  * @param options.emails - Array of email addresses to include
@@ -18,6 +18,11 @@ export type DateOrUnixDateTimeSecondsNumber = Date | UnixDateTimeSecondsNumber;
18
18
  /**
19
19
  * Converts a Date object or unix timestamp number to a unix timestamp number.
20
20
  *
21
+ * @dbxUtil
22
+ * @dbxUtilCategory date
23
+ * @dbxUtilTags date, unix, seconds, timestamp, convert, normalize
24
+ * @dbxUtilRelated unix-date-time-seconds-number-from-date, date-from-date-or-time-seconds-number
25
+ *
21
26
  * @param input - Date object or unix timestamp number to convert
22
27
  * @returns Unix timestamp number if input is valid, null/undefined if input is null/undefined
23
28
  */
@@ -25,12 +30,22 @@ export declare function unixDateTimeSecondsNumberFromDateOrTimeNumber(input: May
25
30
  /**
26
31
  * Gets the current time as a unix timestamp number.
27
32
  *
33
+ * @dbxUtil
34
+ * @dbxUtilCategory date
35
+ * @dbxUtilTags date, unix, seconds, timestamp, now, current, time
36
+ * @dbxUtilRelated unix-date-time-seconds-number-from-date
37
+ *
28
38
  * @returns Current time as unix timestamp number
29
39
  */
30
40
  export declare function unixDateTimeSecondsNumberForNow(): UnixDateTimeSecondsNumber;
31
41
  /**
32
42
  * Converts a Date object to a unix timestamp number.
33
43
  *
44
+ * @dbxUtil
45
+ * @dbxUtilCategory date
46
+ * @dbxUtilTags date, unix, seconds, timestamp, convert, epoch
47
+ * @dbxUtilRelated unix-date-time-seconds-number-to-date, unix-date-time-seconds-number-for-now
48
+ *
34
49
  * @param date - Date object to convert
35
50
  * @returns Unix timestamp number if date is valid, null/undefined if date is null/undefined
36
51
  */
@@ -48,6 +63,11 @@ export declare function dateFromDateOrTimeSecondsNumber(input: Maybe<DateOrUnixD
48
63
  /**
49
64
  * Converts a unix timestamp number to a Date object.
50
65
  *
66
+ * @dbxUtil
67
+ * @dbxUtilCategory date
68
+ * @dbxUtilTags date, unix, seconds, timestamp, convert, parse
69
+ * @dbxUtilRelated unix-date-time-seconds-number-from-date, date-from-date-or-time-seconds-number
70
+ *
51
71
  * @param dateTimeNumber - Unix timestamp number to convert
52
72
  * @returns Date object if timestamp is valid, null/undefined if timestamp is null/undefined
53
73
  */
@@ -10,40 +10,53 @@ export interface Expires {
10
10
  expiresAt?: Maybe<Date>;
11
11
  }
12
12
  /**
13
- * Input configuration for the expirationDetails() function.
13
+ * Input configuration for the {@link expirationDetails}() function.
14
14
  *
15
- * The priority that the expiration calculation uses takes the following order:
16
- * 1. expires - An existing Expires object
17
- * 2. expiresAt - A specific date when something expires
18
- * 3. expiresFromDate + expiresIn - A base date plus a duration
15
+ * The expiration date is resolved from the first matching field in this order:
16
+ * 1. `expires.expiresAt` pull from an existing Expires object
17
+ * 2. `expiresAt` direct expiration date
18
+ * 3. `expiresFromDate + expiresIn` base date plus a duration (negative `expiresIn` shifts the date earlier, useful for buffers/clock skew)
19
+ *
20
+ * @example
21
+ * // Direct expiration date.
22
+ * expirationDetails({ expiresAt: tokenExpiry });
23
+ *
24
+ * // From an existing Expires object.
25
+ * expirationDetails({ expires: token });
26
+ *
27
+ * // Throttle / TTL: "next allowed run" is `lastRunAt + throttleMs`.
28
+ * expirationDetails({ expiresFromDate: lastRunAt, expiresIn: throttleMs });
29
+ *
30
+ * // Pre-emptive refresh: treat the token as expired `bufferMs` before its real expiration.
31
+ * expirationDetails({ expiresFromDate: token.expiresAt, expiresIn: -bufferMs, now: new Date(nowMs) });
19
32
  */
20
33
  export interface ExpirationDetailsInput<T extends Expires = Expires> extends Expires {
21
34
  /**
22
- * Existing expires instance to use.
23
- *
24
- * If provided/
35
+ * Existing expires instance to use. Highest priority — wins over `expiresAt` and `expiresFromDate`/`expiresIn`.
25
36
  */
26
37
  expires?: Maybe<T>;
27
38
  /**
28
- * Default current now time to use.
39
+ * Default current "now" time to use.
29
40
  *
30
- * If not set, functions will use the current time when they are called.
41
+ * If not set, functions will use the current time (`new Date()`) when they are called. Always overridable per-call via the `nowOverride` argument on `hasExpired()`/`getExpirationDate()`.
31
42
  */
32
43
  now?: Maybe<Date>;
33
44
  /**
34
- * The base date or time number to calculate expirations from.
45
+ * The base date or epoch milliseconds to calculate expirations from. Combined with `expiresIn` to produce the expiration date.
35
46
  *
36
- * If not defined, the expiresFromDate is considered to have never been run/set.
47
+ * If null/undefined and `expiresIn` is set, falls back to "now" unless `defaultExpiresFromDateToNow` is false.
37
48
  */
38
49
  expiresFromDate?: Maybe<DateOrUnixDateTimeMillisecondsNumber>;
39
50
  /**
40
- * If true, the "expiresFromDate" will default to the calculated now time when calculating the expiration.
51
+ * If true (default), a missing `expiresFromDate` is treated as "now" when computing `expiresFromDate + expiresIn`.
52
+ *
53
+ * Set to false when a missing base date should mean "never run" (e.g. throttle predicates that should not consider a never-run action throttled).
41
54
  *
42
55
  * Defaults to true.
43
56
  */
44
57
  defaultExpiresFromDateToNow?: Maybe<boolean>;
45
58
  /**
46
- * Time after "now" that expiration will occur.
59
+ * Offset added to `expiresFromDate` (or "now") to produce the expiration date. Negative values shift the expiration earlier, which is the canonical way to express a clock-skew/refresh buffer.
47
60
  */
48
61
  expiresIn?: Maybe<Milliseconds>;
49
62
  }
@@ -69,8 +82,20 @@ export interface ExpirationDetails<T extends Expires = Expires> {
69
82
  getExpirationDate(nowOverride?: Maybe<Date>): Maybe<Date>;
70
83
  }
71
84
  /**
72
- * Returns expiration details for the input configuration.
73
- * Creates an object that can determine when something expires based on various inputs.
85
+ * Returns an {@link ExpirationDetails} for the given input configuration.
86
+ *
87
+ * Use this when you need to ask whether something has expired or what its expiration date is. See {@link ExpirationDetailsInput} for how the expiration date is resolved (`expires` → `expiresAt` → `expiresFromDate + expiresIn`).
88
+ *
89
+ * Common patterns:
90
+ * - **Direct expiration**: `expirationDetails({ expiresAt }).hasExpired()`
91
+ * - **Wrap an existing object**: `expirationDetails({ expires: token }).hasExpired()`
92
+ * - **TTL / throttle**: `expirationDetails({ expiresFromDate: lastRunAt, expiresIn: throttleMs })` — see {@link isThrottled}
93
+ * - **Pre-emptive refresh**: `expirationDetails({ expiresFromDate: expiresAt, expiresIn: -bufferMs })` — treat as expired `bufferMs` before the real expiration, e.g. to refresh a token before it actually dies
94
+ *
95
+ * @dbxUtil
96
+ * @dbxUtilCategory date
97
+ * @dbxUtilTags expiration, expires, expiry, ttl, throttle, refresh, time-to-live
98
+ * @dbxUtilRelated is-expired, is-throttled, calculate-expiration-date, is-under-threshold, check-atleast-one-not-expired, check-any-have-expired
74
99
  *
75
100
  * @template T - The type of Expires object
76
101
  * @param input - Configuration for calculating expiration
@@ -81,10 +106,34 @@ export declare function expirationDetails<T extends Expires = Expires>(input: Ex
81
106
  * Convenience function for calculating and returning the expiration date given the input.
82
107
  * This is a shorthand for expirationDetails(input).getExpirationDate().
83
108
  *
109
+ * @dbxUtil
110
+ * @dbxUtilCategory date
111
+ * @dbxUtilTags expiration, expires, expiry, ttl, calculate, date
112
+ * @dbxUtilRelated expiration-details, is-expired
113
+ *
84
114
  * @param input - Input configuration used to calculate the expiration date
85
115
  * @returns The calculated expiration date, or null if no expiration is defined
86
116
  */
87
117
  export declare function calculateExpirationDate(input: ExpirationDetailsInput<Expires>): Maybe<Date>;
118
+ /**
119
+ * Convenience wrapper around {@link expirationDetails}().hasExpired() that treats null/undefined input or no expiration date as expired.
120
+ *
121
+ * @dbxUtil
122
+ * @dbxUtilCategory date
123
+ * @dbxUtilTags expiration, expires, expiry, expired, has-expired, is-expired, ttl
124
+ * @dbxUtilRelated expiration-details, is-throttled, calculate-expiration-date
125
+ *
126
+ * @param input - Expiration configuration. Null/undefined is treated as expired.
127
+ * @param now - Optional override for the current time. Defaults to the current time. Apply any buffer (e.g. for clock skew or pre-emptive refresh) by shifting this value forward.
128
+ * @returns True when the input is null/undefined or its expiration date has passed; otherwise false.
129
+ *
130
+ * @example
131
+ * isExpired(null); // true
132
+ * isExpired({ expiresAt: pastDate }); // true
133
+ * isExpired({ expiresAt: futureDate }); // false
134
+ * isExpired({ expiresAt: futureDate }, addMilliseconds(new Date(), 60_000)); // true (when within buffer)
135
+ */
136
+ export declare function isExpired<T extends Expires = Expires>(input: Maybe<ExpirationDetailsInput<T>>, now?: Maybe<Date>): boolean;
88
137
  /**
89
138
  * Returns true if the threshold has not passed since the next run time, compared to now.
90
139
  *
@@ -93,6 +142,11 @@ export declare function calculateExpirationDate(input: ExpirationDetailsInput<Ex
93
142
  * Example:
94
143
  * - Should send a notification at max every 2 days. The threshold is 2 days in milliseconds, and "nextRunAt" is the previously calculated date that was originally "now" + "threshold".
95
144
  *
145
+ * @dbxUtil
146
+ * @dbxUtilCategory date
147
+ * @dbxUtilTags threshold, throttle, ttl, time-window, rate-limit
148
+ * @dbxUtilRelated is-throttled, expiration-details
149
+ *
96
150
  * @param threshold The threshold time. Typically this is amount of time that was used to calculate the original "nextRunAt" time.
97
151
  * @param nextRunAt Time the next run will occur. If null/undefined, then this function will return false.
98
152
  * @param now Optional override for the current time. Defaults to the current time.
@@ -105,6 +159,11 @@ export declare function isUnderThreshold(threshold: Milliseconds, nextRunAt: May
105
159
  * Returns true if the throttle time has not passed since the last run time, compared to now.
106
160
  * This is useful for rate limiting operations (e.g., "only allow this action once every X milliseconds").
107
161
  *
162
+ * @dbxUtil
163
+ * @dbxUtilCategory date
164
+ * @dbxUtilTags throttle, throttled, rate-limit, debounce, ttl, expiration
165
+ * @dbxUtilRelated expiration-details, is-under-threshold, is-expired
166
+ *
108
167
  * @param throttleTime - Minimum time in milliseconds that must pass between operations
109
168
  * @param lastRunAt - Timestamp when the operation was last performed
110
169
  * @param now - Optional override for the current time (defaults to the current time)
@@ -117,6 +176,11 @@ export declare function isThrottled(throttleTime: Maybe<Milliseconds>, lastRunAt
117
176
  *
118
177
  * If the list is empty, returns false.
119
178
  *
179
+ * @dbxUtil
180
+ * @dbxUtilCategory date
181
+ * @dbxUtilTags expiration, valid, collection, any
182
+ * @dbxUtilRelated expiration-details, check-any-have-expired
183
+ *
120
184
  * @param details - Collection of ExpirationDetails to check
121
185
  * @returns True if at least one item has not expired, false otherwise
122
186
  */
@@ -127,6 +191,11 @@ export declare function checkAtleastOneNotExpired(details: ExpirationDetails<Exp
127
191
  *
128
192
  * If the list is empty, returns the value specified by defaultIfEmpty.
129
193
  *
194
+ * @dbxUtil
195
+ * @dbxUtilCategory date
196
+ * @dbxUtilTags expiration, refresh, collection, any
197
+ * @dbxUtilRelated expiration-details, check-atleast-one-not-expired
198
+ *
130
199
  * @param details - Collection of ExpirationDetails to check
131
200
  * @param defaultIfEmpty - Default value to return if the list is empty (defaults to true)
132
201
  * @returns True if any item has expired, or the defaultIfEmpty value for an empty list
@@ -4,3 +4,8 @@
4
4
  * Alias of MAP_IDENTITY, so `isMapIdentityFunction()` will return true for this function.
5
5
  */
6
6
  export { MAP_IDENTITY as passThrough } from '../value/map';
7
+ /**
8
+ * No-op function. Useful as a default callback or as a yargs command's `handler` for parent
9
+ * commands that only register subcommands.
10
+ */
11
+ export declare function noop(): void;
@@ -47,6 +47,11 @@ export type StringOrGetter = GetterOrValue<string>;
47
47
  /**
48
48
  * Returns true if the input value is a non-class function (i.e., likely a Getter).
49
49
  *
50
+ * @dbxUtil
51
+ * @dbxUtilCategory getter
52
+ * @dbxUtilTags getter, type-guard, function, callable, check
53
+ * @dbxUtilRelated as-getter, get-value-from-getter
54
+ *
50
55
  * @param value - The value to check
51
56
  * @returns True if the value is a non-class function
52
57
  */
@@ -54,6 +59,11 @@ export declare function isGetter<T = unknown>(value: unknown): value is Getter<T
54
59
  /**
55
60
  * If the input is a function, it is executed and the result returned. Otherwise, the value itself is returned.
56
61
  *
62
+ * @dbxUtil
63
+ * @dbxUtilCategory getter
64
+ * @dbxUtilTags getter, resolve, value, factory, normalize
65
+ * @dbxUtilRelated as-getter, is-getter
66
+ *
57
67
  * @param input - A value or a getter/factory function
58
68
  * @returns The resolved value
59
69
  */
@@ -65,6 +75,11 @@ export declare function getValueFromGetter<T extends GetterDistinctValue, A>(thi
65
75
  /**
66
76
  * Wraps the input as a Getter function. If it's already a function, returns it directly.
67
77
  *
78
+ * @dbxUtil
79
+ * @dbxUtilCategory getter
80
+ * @dbxUtilTags getter, factory, wrap, ensure, normalize
81
+ * @dbxUtilRelated get-value-from-getter, is-getter
82
+ *
68
83
  * @param input - A value or getter function
69
84
  * @returns A Getter function that returns the value
70
85
  */
@@ -76,6 +91,12 @@ export type ObjectCopyFactory<T> = Factory<T>;
76
91
  /**
77
92
  * Creates a factory that returns a shallow copy of the input value on each call.
78
93
  *
94
+ * @dbxUtil
95
+ * @dbxUtilCategory getter
96
+ * @dbxUtilKind factory
97
+ * @dbxUtilTags getter, factory, copy, clone, object
98
+ * @dbxUtilRelated as-object-copy-factory, copy-object
99
+ *
79
100
  * @param value - The object to copy
80
101
  * @param copyFunction - Optional custom copy function (defaults to copyObject)
81
102
  * @returns A factory that produces copies of the value
@@ -69,6 +69,11 @@ export type IndexedBatch<T> = T[] & Readonly<IndexRef>;
69
69
  * @param batchSize - Maximum number of items per batch.
70
70
  * @returns An array of {@link IndexedBatch} arrays.
71
71
  *
72
+ * @dbxUtil
73
+ * @dbxUtilCategory grouping
74
+ * @dbxUtilTags array, batch, chunk, split, group, partition, indexed
75
+ * @dbxUtilRelated batch-calc, item-count-for-batch-index
76
+ *
72
77
  * @example
73
78
  * ```ts
74
79
  * const result = batch(['a', 'b', 'c', 'd'], 2);
@@ -101,6 +106,11 @@ export interface BatchCalc extends BatchCount {
101
106
  /**
102
107
  * Calculates batch metrics (count, full batches, remainder) from a {@link BatchCount} configuration.
103
108
  *
109
+ * @dbxUtil
110
+ * @dbxUtilCategory grouping
111
+ * @dbxUtilTags batch, calculate, count, remainder, math
112
+ * @dbxUtilRelated batch, item-count-for-batch-index
113
+ *
104
114
  * @param input - The total items and items-per-batch configuration.
105
115
  * @returns A {@link BatchCalc} with computed batch counts and remainder.
106
116
  */
@@ -136,6 +146,11 @@ export declare function restoreOrderWithValues<T, K extends PrimativeKey = Prima
136
146
  * @param params.excludeNewItems - when true, values whose keys are not in `orderKeys` are omitted from the result; defaults to false
137
147
  * @returns The reordered values array.
138
148
  *
149
+ * @dbxUtil
150
+ * @dbxUtilCategory grouping
151
+ * @dbxUtilTags array, order, restore, sort, key, reorder, dedupe
152
+ * @dbxUtilRelated restore-order-with-values, group-values
153
+ *
139
154
  * @example
140
155
  * ```ts
141
156
  * const items = [{ key: 'a' }, { key: 'b' }, { key: 'c' }];
@@ -176,6 +191,11 @@ export declare function makeKeyPairs<T, K extends string | number = string | num
176
191
  /**
177
192
  * Separates values into included and excluded groups based on a decision function.
178
193
  *
194
+ * @dbxUtil
195
+ * @dbxUtilCategory grouping
196
+ * @dbxUtilTags array, separate, partition, split, filter, group
197
+ * @dbxUtilRelated group-values, pair-group-values
198
+ *
179
199
  * @param values - Values to separate.
180
200
  * @param checkInclusion - Returns `true` for values that should be included.
181
201
  * @returns A {@link SeparateResult} with included and excluded arrays.
@@ -184,6 +204,11 @@ export declare function separateValues<T>(values: T[], checkInclusion: DecisionF
184
204
  /**
185
205
  * Groups values by key into a plain object. Convenience wrapper around {@link makeValuesGroupMap} that returns a POJO instead of a Map.
186
206
  *
207
+ * @dbxUtil
208
+ * @dbxUtilCategory grouping
209
+ * @dbxUtilTags array, group, partition, key, by, object, dictionary
210
+ * @dbxUtilRelated make-values-group-map, separate-values, pair-group-values
211
+ *
187
212
  * @param values - Values to group.
188
213
  * @param groupKeyFn - Extracts the grouping key from each value.
189
214
  * @returns A plain object mapping each key to its array of values.
@@ -199,6 +224,11 @@ export declare function groupValues<T, K extends PrimativeKey = PrimativeKey>(va
199
224
  * @param groupKeyFn - Extracts the grouping key from each value.
200
225
  * @returns A Map from each key to its array of values.
201
226
  *
227
+ * @dbxUtil
228
+ * @dbxUtilCategory grouping
229
+ * @dbxUtilTags array, group, map, key, partition, by, dictionary
230
+ * @dbxUtilRelated group-values, separate-values, pair-group-values
231
+ *
202
232
  * @example
203
233
  * ```ts
204
234
  * const items = [{ type: 'a', v: 1 }, { type: 'b', v: 2 }, { type: 'a', v: 3 }];
package/src/lib/hash.d.ts CHANGED
@@ -21,6 +21,11 @@ export type HashDecodeMap<H extends string = string, V extends string = string>
21
21
  * @param hashFn - A function that takes a string and returns its hashed representation.
22
22
  * @returns An array of decoded strings. Values that cannot be decoded are filtered out.
23
23
  *
24
+ * @dbxUtil
25
+ * @dbxUtilCategory hash
26
+ * @dbxUtilTags hash, decode, lookup, reverse, salt
27
+ * @dbxUtilRelated make-hash-decode-map, decode-hashed-values-with-decode-map
28
+ *
24
29
  * @example
25
30
  * ```ts
26
31
  * const hashed = [hashFn('apple'), hashFn('banana')];
@@ -33,6 +38,11 @@ export declare function decodeHashedValues(hashedValues: string[], decodeValues:
33
38
  * Creates a `HashDecodeMap` from a list of potential original string values and a hash function.
34
39
  * The map's keys are the hashed versions of the `decodeValues`, and the values are the original `decodeValues`.
35
40
  *
41
+ * @dbxUtil
42
+ * @dbxUtilCategory hash
43
+ * @dbxUtilTags hash, decode, map, lookup, reverse, factory
44
+ * @dbxUtilRelated decode-hashed-values, decode-hashed-values-with-decode-map
45
+ *
36
46
  * @param decodeValues - An array of potential original string values.
37
47
  * @param hashFn - A function that takes a string and returns its hashed representation.
38
48
  * @returns A {@link HashDecodeMap} for decoding hashed values.
@@ -1,6 +1,7 @@
1
1
  export * from './array';
2
2
  export * from './assertion';
3
3
  export * from './auth';
4
+ export * from './cache';
4
5
  export * from './contact';
5
6
  export * from './error';
6
7
  export * from './file';
@@ -20,6 +20,11 @@ export declare function asIterable<T = unknown>(values: IterableOrValue<T>, trea
20
20
  *
21
21
  * By default treats strings as a non-iterable value, using the string as a single value.
22
22
  *
23
+ * @dbxUtil
24
+ * @dbxUtilCategory iterable
25
+ * @dbxUtilTags iterable, array, convert, normalize, ensure
26
+ * @dbxUtilRelated iterable-to-set, iterable-to-map, as-iterable
27
+ *
23
28
  * @param values - The value or iterable to convert
24
29
  * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
25
30
  * @returns An array containing the value(s)
@@ -30,6 +35,11 @@ export declare function iterableToArray<T = unknown>(values: IterableOrValue<T>,
30
35
  *
31
36
  * By default treats strings as a non-iterable value, using the string as a single value.
32
37
  *
38
+ * @dbxUtil
39
+ * @dbxUtilCategory iterable
40
+ * @dbxUtilTags iterable, set, convert, normalize, unique, dedupe
41
+ * @dbxUtilRelated iterable-to-array, iterable-to-map
42
+ *
33
43
  * @param values - The value or iterable to convert
34
44
  * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
35
45
  * @returns A Set containing the value(s)
@@ -47,6 +57,11 @@ export declare function iterableToMap<T, K extends PrimativeKey = PrimativeKey>(
47
57
  * Type guard that returns true if the input is an Iterable.
48
58
  * By default, strings are not treated as iterable.
49
59
  *
60
+ * @dbxUtil
61
+ * @dbxUtilCategory iterable
62
+ * @dbxUtilTags iterable, type-guard, check, symbol-iterator
63
+ * @dbxUtilRelated is-empty-iterable, as-iterable
64
+ *
50
65
  * @param values - The value to check
51
66
  * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
52
67
  * @returns True if the value is iterable
@@ -55,6 +70,11 @@ export declare function isIterable<T = unknown>(values: unknown, treatStringAsIt
55
70
  /**
56
71
  * Returns true if the iterable has no values.
57
72
  *
73
+ * @dbxUtil
74
+ * @dbxUtilCategory iterable
75
+ * @dbxUtilTags iterable, empty, check, length
76
+ * @dbxUtilRelated is-iterable, first-value-from-iterable
77
+ *
58
78
  * @param values - The iterable to check
59
79
  * @returns True if the iterable is empty
60
80
  */
@@ -12,6 +12,11 @@ export type IteratePageFn<T> = (values: T[]) => void | Promise<void>;
12
12
  * @param values - Array of values to iterate over.
13
13
  * @param useFn - Callback invoked for each value.
14
14
  *
15
+ * @dbxUtil
16
+ * @dbxUtilCategory iterate
17
+ * @dbxUtilTags iterate, async, sequential, each, await, for-each
18
+ * @dbxUtilRelated perform-async-tasks
19
+ *
15
20
  * @example
16
21
  * ```ts
17
22
  * await iterate([1, 2, 3], async (value) => {
@@ -20,6 +20,12 @@ export type IsInNumberBoundFunction = (number: number) => boolean;
20
20
  /**
21
21
  * Creates a function that checks whether a number falls within the specified inclusive bounds.
22
22
  *
23
+ * @dbxUtil
24
+ * @dbxUtilCategory number
25
+ * @dbxUtilKind factory
26
+ * @dbxUtilTags number, bound, range, between, check, inclusive, factory
27
+ * @dbxUtilRelated bound-number-function, bound-number, is-valid-number-bound
28
+ *
23
29
  * @param bounds - The min/max bounds to test against
24
30
  * @returns A function that returns `true` if the input number is within bounds
25
31
  * @throws Error if the bounds are invalid (min > max)
@@ -41,6 +47,12 @@ export type WrapNumberFunction<T extends number = number> = MapFunction<number,
41
47
  *
42
48
  * When `fencePosts` is true, wraps to the nearest "fence post" value, extending the wrap range by one in each direction.
43
49
  *
50
+ * @dbxUtil
51
+ * @dbxUtilCategory number
52
+ * @dbxUtilKind factory
53
+ * @dbxUtilTags number, wrap, modulo, modular, range, factory, circular
54
+ * @dbxUtilRelated bound-number-function, bound-number, is-in-number-bound-function
55
+ *
44
56
  * @param wrapNumberFunctionConfig - Configuration with min, max, and optional fence post behavior
45
57
  * @returns A function that wraps input numbers into the bounded range
46
58
  */
@@ -59,6 +71,12 @@ export type BoundNumberFunction<T extends number = number> = MapFunction<number,
59
71
  *
60
72
  * When `wrap` is true, uses modular wrapping. Otherwise, clamps values to the min/max range.
61
73
  *
74
+ * @dbxUtil
75
+ * @dbxUtilCategory number
76
+ * @dbxUtilKind factory
77
+ * @dbxUtilTags number, bound, clamp, wrap, range, factory, constrain
78
+ * @dbxUtilRelated bound-number, wrap-number-function, is-in-number-bound-function
79
+ *
62
80
  * @param boundNumberFunctionConfig - Configuration with min, max, and optional wrap behavior
63
81
  * @returns A function that bounds input numbers into the configured range
64
82
  */
@@ -66,6 +84,11 @@ export declare function boundNumberFunction<T extends number = number>(boundNumb
66
84
  /**
67
85
  * Clamps the input number between the min and max values (inclusive).
68
86
  *
87
+ * @dbxUtil
88
+ * @dbxUtilCategory number
89
+ * @dbxUtilTags number, clamp, bound, min, max, range, constrain
90
+ * @dbxUtilRelated bound-number-function, wrap-number-function, is-in-number-bound-function
91
+ *
69
92
  * @param input - Number to clamp
70
93
  * @param min - Minimum allowed value
71
94
  * @param max - Maximum allowed value