@ls-stack/utils 3.39.0 → 3.41.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 (162) hide show
  1. package/dist/arrayUtils.d.cts +70 -57
  2. package/dist/arrayUtils.d.ts +70 -57
  3. package/dist/assertions.d.cts +128 -117
  4. package/dist/assertions.d.ts +128 -117
  5. package/dist/asyncQueue.cjs +117 -112
  6. package/dist/asyncQueue.d.cts +217 -215
  7. package/dist/asyncQueue.d.ts +217 -215
  8. package/dist/asyncQueue.js +117 -112
  9. package/dist/awaitDebounce.d.cts +26 -23
  10. package/dist/awaitDebounce.d.ts +26 -23
  11. package/dist/cache.cjs +2 -1
  12. package/dist/cache.d.cts +15 -9
  13. package/dist/cache.d.ts +15 -9
  14. package/dist/cache.js +2 -1
  15. package/dist/{chunk-GHAQOUA6.js → chunk-23KPGKDT.js} +22 -1
  16. package/dist/{chunk-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
  17. package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
  18. package/dist/chunk-DTE2QMWE.js +48 -0
  19. package/dist/concurrentCalls.d.cts +8 -4
  20. package/dist/concurrentCalls.d.ts +8 -4
  21. package/dist/concurrentCalls.js +1 -1
  22. package/dist/consoleFmt.cjs +1 -0
  23. package/dist/consoleFmt.d.cts +6 -0
  24. package/dist/consoleFmt.d.ts +6 -0
  25. package/dist/consoleFmt.js +1 -0
  26. package/dist/debounce.d.cts +12 -20
  27. package/dist/debounce.d.ts +12 -20
  28. package/dist/dedent.d.cts +31 -31
  29. package/dist/dedent.d.ts +31 -31
  30. package/dist/deepEqual.d.cts +10 -9
  31. package/dist/deepEqual.d.ts +10 -9
  32. package/dist/filterObjectOrArrayKeys.d.cts +44 -19
  33. package/dist/filterObjectOrArrayKeys.d.ts +44 -19
  34. package/dist/getAutoIncrementId.d.cts +25 -23
  35. package/dist/getAutoIncrementId.d.ts +25 -23
  36. package/dist/getCompositeKey.d.cts +2 -1
  37. package/dist/getCompositeKey.d.ts +2 -1
  38. package/dist/getValueStableKey.d.cts +4 -3
  39. package/dist/getValueStableKey.d.ts +4 -3
  40. package/dist/mutationUtils.d.cts +2 -2
  41. package/dist/mutationUtils.d.ts +2 -2
  42. package/dist/objUtils.cjs +51 -2
  43. package/dist/objUtils.d.cts +8 -3
  44. package/dist/objUtils.d.ts +8 -3
  45. package/dist/objUtils.js +11 -3
  46. package/dist/parallelAsyncCalls.cjs +2 -1
  47. package/dist/parallelAsyncCalls.d.cts +5 -4
  48. package/dist/parallelAsyncCalls.d.ts +5 -4
  49. package/dist/parallelAsyncCalls.js +2 -1
  50. package/dist/retryOnError.d.cts +23 -20
  51. package/dist/retryOnError.d.ts +23 -20
  52. package/dist/runShellCmd.d.cts +40 -40
  53. package/dist/runShellCmd.d.ts +40 -40
  54. package/dist/safeJson.d.cts +6 -2
  55. package/dist/safeJson.d.ts +6 -2
  56. package/dist/saferTyping.d.cts +21 -14
  57. package/dist/saferTyping.d.ts +21 -14
  58. package/dist/shallowEqual.d.cts +1 -1
  59. package/dist/shallowEqual.d.ts +1 -1
  60. package/dist/stringUtils.cjs +2 -2
  61. package/dist/stringUtils.d.cts +6 -7
  62. package/dist/stringUtils.d.ts +6 -7
  63. package/dist/stringUtils.js +1 -1
  64. package/dist/testUtils.cjs +11 -9
  65. package/dist/testUtils.d.cts +32 -14
  66. package/dist/testUtils.d.ts +32 -14
  67. package/dist/testUtils.js +4 -3
  68. package/dist/throttle.d.cts +57 -48
  69. package/dist/throttle.d.ts +57 -48
  70. package/dist/timers.d.cts +68 -63
  71. package/dist/timers.d.ts +68 -63
  72. package/dist/tsResult.d.cts +7 -6
  73. package/dist/tsResult.d.ts +7 -6
  74. package/dist/typeGuards.d.cts +65 -64
  75. package/dist/typeGuards.d.ts +65 -64
  76. package/dist/typeUtils.d.cts +18 -4
  77. package/dist/typeUtils.d.ts +18 -4
  78. package/dist/typedStrings.d.cts +68 -57
  79. package/dist/typedStrings.d.ts +68 -57
  80. package/dist/typingFnUtils.d.cts +12 -6
  81. package/dist/typingFnUtils.d.ts +12 -6
  82. package/dist/typingFnUtils.js +12 -35
  83. package/dist/typingTestUtils.cjs +7 -1
  84. package/dist/typingTestUtils.d.cts +52 -11
  85. package/dist/typingTestUtils.d.ts +52 -11
  86. package/dist/typingTestUtils.js +7 -1
  87. package/dist/typingUtils.d.cts +4 -1
  88. package/dist/typingUtils.d.ts +4 -1
  89. package/dist/yamlStringify.cjs +11 -9
  90. package/dist/yamlStringify.js +2 -2
  91. package/package.json +6 -2
  92. package/docs/README.md +0 -72
  93. package/docs/_media/modules.md +0 -58
  94. package/docs/arrayUtils/-internal-.md +0 -179
  95. package/docs/arrayUtils/README.md +0 -550
  96. package/docs/assertions/-internal-.md +0 -63
  97. package/docs/assertions/README.md +0 -565
  98. package/docs/asyncQueue/-internal-.md +0 -297
  99. package/docs/asyncQueue/README.md +0 -1485
  100. package/docs/awaitDebounce.md +0 -66
  101. package/docs/cache/-internal-.md +0 -168
  102. package/docs/cache/README.md +0 -360
  103. package/docs/castValues.md +0 -47
  104. package/docs/concurrentCalls/-internal-.md +0 -490
  105. package/docs/concurrentCalls/README.md +0 -299
  106. package/docs/consoleFmt.md +0 -91
  107. package/docs/conversions.md +0 -27
  108. package/docs/createThrottleController/-internal-.md +0 -73
  109. package/docs/createThrottleController/README.md +0 -31
  110. package/docs/debounce.md +0 -188
  111. package/docs/dedent/-internal-.md +0 -17
  112. package/docs/dedent/README.md +0 -204
  113. package/docs/deepEqual.md +0 -94
  114. package/docs/enhancedMap.md +0 -358
  115. package/docs/exhaustiveMatch/-internal-.md +0 -39
  116. package/docs/exhaustiveMatch/README.md +0 -146
  117. package/docs/filterObjectOrArrayKeys.md +0 -109
  118. package/docs/getAutoIncrementId.md +0 -93
  119. package/docs/getCompositeKey.md +0 -39
  120. package/docs/getValueStableKey.md +0 -57
  121. package/docs/hash.md +0 -31
  122. package/docs/interpolate/-internal-.md +0 -61
  123. package/docs/interpolate/README.md +0 -62
  124. package/docs/keepPrevIfUnchanged.md +0 -43
  125. package/docs/levenshtein.md +0 -93
  126. package/docs/main.md +0 -21
  127. package/docs/mathUtils.md +0 -137
  128. package/docs/modules.md +0 -58
  129. package/docs/mutationUtils.md +0 -44
  130. package/docs/objUtils.md +0 -237
  131. package/docs/parallelAsyncCalls/-internal-.md +0 -347
  132. package/docs/parallelAsyncCalls/README.md +0 -45
  133. package/docs/promiseUtils/-internal-.md +0 -69
  134. package/docs/promiseUtils/README.md +0 -31
  135. package/docs/retryOnError/-internal-.md +0 -111
  136. package/docs/retryOnError/README.md +0 -168
  137. package/docs/runShellCmd/-internal-.md +0 -111
  138. package/docs/runShellCmd/README.md +0 -201
  139. package/docs/safeJson.md +0 -51
  140. package/docs/saferTyping.md +0 -228
  141. package/docs/serializeXML.md +0 -100
  142. package/docs/shallowEqual.md +0 -33
  143. package/docs/sleep.md +0 -27
  144. package/docs/stringUtils/-internal-.md +0 -17
  145. package/docs/stringUtils/README.md +0 -270
  146. package/docs/testUtils.md +0 -382
  147. package/docs/throttle/-internal-.md +0 -47
  148. package/docs/throttle/README.md +0 -178
  149. package/docs/time.md +0 -274
  150. package/docs/timers.md +0 -256
  151. package/docs/tsResult/-internal-.md +0 -327
  152. package/docs/tsResult/README.md +0 -702
  153. package/docs/typeGuards.md +0 -399
  154. package/docs/typeUtils/-internal-.md +0 -99
  155. package/docs/typeUtils/README.md +0 -195
  156. package/docs/typeUtils.typesTest.md +0 -7
  157. package/docs/typedStrings.md +0 -458
  158. package/docs/typingFnUtils/-internal-.md +0 -43
  159. package/docs/typingFnUtils/README.md +0 -317
  160. package/docs/typingTestUtils.md +0 -172
  161. package/docs/typingUtils.md +0 -135
  162. package/docs/yamlStringify.md +0 -83
@@ -27,22 +27,23 @@ var AsyncQueue = class _AsyncQueue {
27
27
  /**
28
28
  * Event emitter for tracking task lifecycle
29
29
  *
30
- * @example Listening to Events
31
- * ```typescript
32
- * const queue = createAsyncQueue<string>();
30
+ * @example
31
+ * Listening to Events
32
+ * ```typescript
33
+ * const queue = createAsyncQueue<string>();
33
34
  *
34
- * queue.events.on('start', (event) => {
35
+ * queue.events.on('start', (event) => {
35
36
  * console.log('Task started:', event.payload.meta);
36
- * });
37
+ * });
37
38
  *
38
- * queue.events.on('complete', (event) => {
39
+ * queue.events.on('complete', (event) => {
39
40
  * console.log('Task completed:', event.payload.value);
40
- * });
41
+ * });
41
42
  *
42
- * queue.events.on('error', (event) => {
43
+ * queue.events.on('error', (event) => {
43
44
  * console.error('Task failed:', event.payload.error);
44
- * });
45
- * ```
45
+ * });
46
+ * ```
46
47
  */
47
48
  events = evtmitter();
48
49
  #signal;
@@ -156,32 +157,33 @@ var AsyncQueue = class _AsyncQueue {
156
157
  /**
157
158
  * Add a task that returns a Result to the queue
158
159
  *
159
- * Use this method when your task function already returns a Result type.
160
- * For functions that throw errors or return plain values, use `resultifyAdd` instead.
160
+ * Use this method when your task function already returns a Result type. For
161
+ * functions that throw errors or return plain values, use `resultifyAdd`
162
+ * instead.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const queue = createAsyncQueue<string>();
167
+ *
168
+ * const result = await queue.add(async () => {
169
+ * try {
170
+ * const data = await fetchData();
171
+ * return Result.ok(data);
172
+ * } catch (error) {
173
+ * return Result.err(error);
174
+ * }
175
+ * });
176
+ *
177
+ * if (result.ok) {
178
+ * console.log('Success:', result.value);
179
+ * } else {
180
+ * console.log('Error:', result.error);
181
+ * }
182
+ * ```;
161
183
  *
162
184
  * @param fn - Task function that returns a Result
163
185
  * @param options - Optional configuration for this task
164
186
  * @returns Promise that resolves with the task result
165
- *
166
- * @example
167
- * ```typescript
168
- * const queue = createAsyncQueue<string>();
169
- *
170
- * const result = await queue.add(async () => {
171
- * try {
172
- * const data = await fetchData();
173
- * return Result.ok(data);
174
- * } catch (error) {
175
- * return Result.err(error);
176
- * }
177
- * });
178
- *
179
- * if (result.ok) {
180
- * console.log('Success:', result.value);
181
- * } else {
182
- * console.log('Error:', result.error);
183
- * }
184
- * ```
185
187
  */
186
188
  async add(fn, options) {
187
189
  if (this.#signal?.aborted) {
@@ -225,37 +227,39 @@ var AsyncQueue = class _AsyncQueue {
225
227
  * This is the most commonly used method. It automatically wraps your function
226
228
  * to handle errors and convert them to Result types.
227
229
  *
228
- * @param fn - Task function that returns a value or throws
229
- * @param options - Optional configuration for this task
230
- * @returns Promise that resolves with the task result wrapped in Result
231
- *
232
- * @example Basic Usage
233
- * ```typescript
234
- * const queue = createAsyncQueue<string>();
230
+ * @example
231
+ * Basic Usage
232
+ * ```typescript
233
+ * const queue = createAsyncQueue<string>();
235
234
  *
236
- * queue.resultifyAdd(async () => {
235
+ * queue.resultifyAdd(async () => {
237
236
  * const response = await fetch('/api/data');
238
237
  * return response.json();
239
- * }).then(result => {
238
+ * }).then(result => {
240
239
  * if (result.ok) {
241
- * console.log('Data:', result.value);
240
+ * console.log('Data:', result.value);
242
241
  * } else {
243
- * console.error('Failed:', result.error);
242
+ * console.error('Failed:', result.error);
244
243
  * }
245
- * });
246
- * ```
244
+ * });
245
+ * ```
247
246
  *
248
- * @example With Callbacks
249
- * ```typescript
250
- * queue.resultifyAdd(
247
+ * @example
248
+ * With Callbacks
249
+ * ```typescript
250
+ * queue.resultifyAdd(
251
251
  * async () => processData(),
252
252
  * {
253
- * onComplete: (data) => console.log('Processed:', data),
254
- * onError: (error) => console.error('Failed:', error),
255
- * timeout: 5000
253
+ * onComplete: (data) => console.log('Processed:', data),
254
+ * onError: (error) => console.error('Failed:', error),
255
+ * timeout: 5000
256
256
  * }
257
- * );
258
- * ```
257
+ * );
258
+ * ```
259
+ *
260
+ * @param fn - Task function that returns a value or throws
261
+ * @param options - Optional configuration for this task
262
+ * @returns Promise that resolves with the task result wrapped in Result
259
263
  */
260
264
  resultifyAdd(fn, options) {
261
265
  return this.add(
@@ -400,29 +404,32 @@ var AsyncQueue = class _AsyncQueue {
400
404
  this.#resolveIdleWaiters();
401
405
  }
402
406
  /**
403
- * Wait for the queue to become idle (no pending tasks, no queued tasks, and no rate-limit timers)
407
+ * Wait for the queue to become idle (no pending tasks, no queued tasks, and
408
+ * no rate-limit timers)
404
409
  *
405
410
  * This method resolves when:
411
+ *
406
412
  * - All tasks have completed (success or failure)
407
413
  * - The queue is stopped due to error (stopOnError), even with remaining tasks
408
- * - There are no queued tasks, no running tasks, and no pending rate-limit timers
409
- *
410
- * @returns Promise that resolves when the queue is idle
414
+ * - There are no queued tasks, no running tasks, and no pending rate-limit
415
+ * timers
411
416
  *
412
417
  * @example
413
- * ```typescript
414
- * const queue = createAsyncQueue<string>();
418
+ * ```typescript
419
+ * const queue = createAsyncQueue<string>();
415
420
  *
416
- * // Add multiple tasks
417
- * for (let i = 0; i < 10; i++) {
421
+ * // Add multiple tasks
422
+ * for (let i = 0; i < 10; i++) {
418
423
  * queue.resultifyAdd(async () => `task ${i}`);
419
- * }
424
+ * }
425
+ *
426
+ * // Wait for all tasks to complete
427
+ * await queue.onIdle();
420
428
  *
421
- * // Wait for all tasks to complete
422
- * await queue.onIdle();
429
+ * console.log(`Completed: ${queue.completed}, Failed: ${queue.failed}`);
430
+ * ```
423
431
  *
424
- * console.log(`Completed: ${queue.completed}, Failed: ${queue.failed}`);
425
- * ```
432
+ * @returns Promise that resolves when the queue is idle
426
433
  */
427
434
  async onIdle() {
428
435
  if (this.#stopped || this.#pending === 0 && this.#size === 0 && this.#rateLimitTimeouts.size === 0) {
@@ -453,24 +460,24 @@ var AsyncQueue = class _AsyncQueue {
453
460
  /**
454
461
  * Clear all queued tasks (does not affect currently running tasks)
455
462
  *
456
- * This removes all tasks waiting in the queue but allows currently
457
- * executing tasks to complete normally.
463
+ * This removes all tasks waiting in the queue but allows currently executing
464
+ * tasks to complete normally.
458
465
  *
459
466
  * @example
460
- * ```typescript
461
- * const queue = createAsyncQueue({ concurrency: 1 });
467
+ * ```typescript
468
+ * const queue = createAsyncQueue({ concurrency: 1 });
462
469
  *
463
- * // Add multiple tasks
464
- * queue.resultifyAdd(async () => longRunningTask()); // Will start immediately
465
- * queue.resultifyAdd(async () => task2()); // Queued
466
- * queue.resultifyAdd(async () => task3()); // Queued
470
+ * // Add multiple tasks
471
+ * queue.resultifyAdd(async () => longRunningTask()); // Will start immediately
472
+ * queue.resultifyAdd(async () => task2()); // Queued
473
+ * queue.resultifyAdd(async () => task3()); // Queued
467
474
  *
468
- * // Clear remaining queued tasks
469
- * queue.clear();
475
+ * // Clear remaining queued tasks
476
+ * queue.clear();
470
477
  *
471
- * // Only the first task will complete
472
- * await queue.onIdle();
473
- * ```
478
+ * // Only the first task will complete
479
+ * await queue.onIdle();
480
+ * ```;
474
481
  */
475
482
  clear() {
476
483
  this.#queue = [];
@@ -504,17 +511,17 @@ var AsyncQueue = class _AsyncQueue {
504
511
  * Manually start processing tasks (only needed if autoStart: false)
505
512
  *
506
513
  * @example
507
- * ```typescript
508
- * const queue = createAsyncQueue({ autoStart: false });
514
+ * ```typescript
515
+ * const queue = createAsyncQueue({ autoStart: false });
509
516
  *
510
- * // Add tasks without starting processing
511
- * queue.resultifyAdd(async () => 'task1');
512
- * queue.resultifyAdd(async () => 'task2');
517
+ * // Add tasks without starting processing
518
+ * queue.resultifyAdd(async () => 'task1');
519
+ * queue.resultifyAdd(async () => 'task2');
513
520
  *
514
- * // Start processing when ready
515
- * queue.start();
516
- * await queue.onIdle();
517
- * ```
521
+ * // Start processing when ready
522
+ * queue.start();
523
+ * await queue.onIdle();
524
+ * ```;
518
525
  */
519
526
  start() {
520
527
  if (this.#stopped) {
@@ -527,26 +534,24 @@ var AsyncQueue = class _AsyncQueue {
527
534
  * Pause processing new tasks (currently running tasks continue)
528
535
  *
529
536
  * @example
530
- * ```typescript
531
- * const queue = createAsyncQueue();
537
+ * ```typescript
538
+ * const queue = createAsyncQueue();
532
539
  *
533
- * // Start some tasks
534
- * queue.resultifyAdd(async () => longRunningTask1());
535
- * queue.resultifyAdd(async () => longRunningTask2());
540
+ * // Start some tasks
541
+ * queue.resultifyAdd(async () => longRunningTask1());
542
+ * queue.resultifyAdd(async () => longRunningTask2());
536
543
  *
537
- * // Pause before more tasks are picked up
538
- * queue.pause();
544
+ * // Pause before more tasks are picked up
545
+ * queue.pause();
539
546
  *
540
- * // Later, resume processing
541
- * queue.resume();
542
- * ```
547
+ * // Later, resume processing
548
+ * queue.resume();
549
+ * ```;
543
550
  */
544
551
  pause() {
545
552
  this.#paused = true;
546
553
  }
547
- /**
548
- * Resume processing tasks after pause
549
- */
554
+ /** Resume processing tasks after pause */
550
555
  resume() {
551
556
  this.#paused = false;
552
557
  if (this.#started && !this.#stopped) {
@@ -556,27 +561,27 @@ var AsyncQueue = class _AsyncQueue {
556
561
  /**
557
562
  * Reset the queue after being stopped, allowing new tasks to be processed
558
563
  *
559
- * This clears the stopped state and error reason, and resumes processing
560
- * any remaining queued tasks if autoStart was enabled.
564
+ * This clears the stopped state and error reason, and resumes processing any
565
+ * remaining queued tasks if autoStart was enabled.
561
566
  *
562
567
  * @example
563
- * ```typescript
564
- * const queue = createAsyncQueue({ stopOnError: true });
568
+ * ```typescript
569
+ * const queue = createAsyncQueue({ stopOnError: true });
565
570
  *
566
- * // Add tasks that will cause the queue to stop
567
- * queue.resultifyAdd(async () => { throw new Error('fail'); });
568
- * queue.resultifyAdd(async () => 'remaining task');
571
+ * // Add tasks that will cause the queue to stop
572
+ * queue.resultifyAdd(async () => { throw new Error('fail'); });
573
+ * queue.resultifyAdd(async () => 'remaining task');
569
574
  *
570
- * await queue.onIdle();
575
+ * await queue.onIdle();
571
576
  *
572
- * if (queue.isStopped) {
577
+ * if (queue.isStopped) {
573
578
  * console.log(`Queue stopped, ${queue.size} tasks remaining`);
574
579
  *
575
580
  * // Reset and process remaining tasks
576
581
  * queue.reset();
577
582
  * await queue.onIdle();
578
- * }
579
- * ```
583
+ * }
584
+ * ```
580
585
  */
581
586
  reset() {
582
587
  this.#stopped = false;
@@ -1,34 +1,37 @@
1
1
  import { __LEGIT_ANY__ } from './saferTyping.cjs';
2
2
 
3
3
  /**
4
- * Creates an awaitable debounce mechanism that allows you to debounce async operations.
5
- * When called multiple times with the same `callId`, only the last call will resolve with 'continue',
6
- * while all previous calls resolve with 'skip'.
4
+ * Creates an awaitable debounce mechanism that allows you to debounce async
5
+ * operations. When called multiple times with the same `callId`, only the last
6
+ * call will resolve with 'continue', while all previous calls resolve with
7
+ * 'skip'.
7
8
  *
8
- * This is useful for debouncing API calls, search operations, or any async work where you want
9
- * to ensure only the most recent request is processed.
10
- *
11
- * @param options - Configuration object
12
- * @param options.callId - Unique identifier for the debounce group. Calls with the same ID are debounced together
13
- * @param options.debounce - Debounce delay in milliseconds
14
- * @returns Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
9
+ * This is useful for debouncing API calls, search operations, or any async work
10
+ * where you want to ensure only the most recent request is processed.
15
11
  *
16
12
  * @example
17
- * ```ts
18
- * async function searchUsers(query: string) {
19
- * const result = await awaitDebounce({ callId: 'search', debounce: 300 });
20
- * if (result === 'skip') return; // This search was superseded
13
+ * ```ts
14
+ * async function searchUsers(query: string) {
15
+ * const result = await awaitDebounce({ callId: 'search', debounce: 300 });
16
+ * if (result === 'skip') return; // This search was superseded
21
17
  *
22
- * // Only the most recent search will reach here
23
- * const users = await fetchUsers(query);
24
- * updateUI(users);
25
- * }
18
+ * // Only the most recent search will reach here
19
+ * const users = await fetchUsers(query);
20
+ * updateUI(users);
21
+ * }
26
22
  *
27
- * // Called rapidly - only the last call will execute
28
- * searchUsers('a');
29
- * searchUsers('ab');
30
- * searchUsers('abc'); // Only this one will continue
31
- * ```
23
+ * // Called rapidly - only the last call will execute
24
+ * searchUsers('a');
25
+ * searchUsers('ab');
26
+ * searchUsers('abc'); // Only this one will continue
27
+ * ```;
28
+ *
29
+ * @param options - Configuration object
30
+ * @param options.callId - Unique identifier for the debounce group. Calls with
31
+ * the same ID are debounced together
32
+ * @param options.debounce - Debounce delay in milliseconds
33
+ * @returns Promise that resolves to 'continue' if this call should proceed, or
34
+ * 'skip' if it was superseded
32
35
  */
33
36
  declare function awaitDebounce({ callId: _callId, debounce, }: {
34
37
  callId: __LEGIT_ANY__;
@@ -1,34 +1,37 @@
1
1
  import { __LEGIT_ANY__ } from './saferTyping.js';
2
2
 
3
3
  /**
4
- * Creates an awaitable debounce mechanism that allows you to debounce async operations.
5
- * When called multiple times with the same `callId`, only the last call will resolve with 'continue',
6
- * while all previous calls resolve with 'skip'.
4
+ * Creates an awaitable debounce mechanism that allows you to debounce async
5
+ * operations. When called multiple times with the same `callId`, only the last
6
+ * call will resolve with 'continue', while all previous calls resolve with
7
+ * 'skip'.
7
8
  *
8
- * This is useful for debouncing API calls, search operations, or any async work where you want
9
- * to ensure only the most recent request is processed.
10
- *
11
- * @param options - Configuration object
12
- * @param options.callId - Unique identifier for the debounce group. Calls with the same ID are debounced together
13
- * @param options.debounce - Debounce delay in milliseconds
14
- * @returns Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
9
+ * This is useful for debouncing API calls, search operations, or any async work
10
+ * where you want to ensure only the most recent request is processed.
15
11
  *
16
12
  * @example
17
- * ```ts
18
- * async function searchUsers(query: string) {
19
- * const result = await awaitDebounce({ callId: 'search', debounce: 300 });
20
- * if (result === 'skip') return; // This search was superseded
13
+ * ```ts
14
+ * async function searchUsers(query: string) {
15
+ * const result = await awaitDebounce({ callId: 'search', debounce: 300 });
16
+ * if (result === 'skip') return; // This search was superseded
21
17
  *
22
- * // Only the most recent search will reach here
23
- * const users = await fetchUsers(query);
24
- * updateUI(users);
25
- * }
18
+ * // Only the most recent search will reach here
19
+ * const users = await fetchUsers(query);
20
+ * updateUI(users);
21
+ * }
26
22
  *
27
- * // Called rapidly - only the last call will execute
28
- * searchUsers('a');
29
- * searchUsers('ab');
30
- * searchUsers('abc'); // Only this one will continue
31
- * ```
23
+ * // Called rapidly - only the last call will execute
24
+ * searchUsers('a');
25
+ * searchUsers('ab');
26
+ * searchUsers('abc'); // Only this one will continue
27
+ * ```;
28
+ *
29
+ * @param options - Configuration object
30
+ * @param options.callId - Unique identifier for the debounce group. Calls with
31
+ * the same ID are debounced together
32
+ * @param options.debounce - Debounce delay in milliseconds
33
+ * @returns Promise that resolves to 'continue' if this call should proceed, or
34
+ * 'skip' if it was superseded
32
35
  */
33
36
  declare function awaitDebounce({ callId: _callId, debounce, }: {
34
37
  callId: __LEGIT_ANY__;
package/dist/cache.cjs CHANGED
@@ -78,7 +78,8 @@ var WithExpiration = class {
78
78
  expiration;
79
79
  /**
80
80
  * @param value - The value to store in the cache.
81
- * @param expiration - The expiration time of the value in seconds or a duration object.
81
+ * @param expiration - The expiration time of the value in seconds or a
82
+ * duration object.
82
83
  */
83
84
  constructor(value, expiration) {
84
85
  this.value = value;
package/dist/cache.d.cts CHANGED
@@ -6,15 +6,15 @@ declare function cachedGetter<T>(getter: () => T): {
6
6
  type Options = {
7
7
  /**
8
8
  * The maximum number of items in the cache.
9
+ *
9
10
  * @default 1000
10
11
  */
11
12
  maxCacheSize?: number;
12
- /**
13
- * The maximum age of items in the cache.
14
- */
13
+ /** The maximum age of items in the cache. */
15
14
  maxItemAge?: DurationObj;
16
15
  /**
17
16
  * The throttle for checking expired items in milliseconds.
17
+ *
18
18
  * @default
19
19
  * 10_000
20
20
  */
@@ -29,25 +29,31 @@ declare class WithExpiration<T> {
29
29
  expiration: number;
30
30
  /**
31
31
  * @param value - The value to store in the cache.
32
- * @param expiration - The expiration time of the value in seconds or a duration object.
32
+ * @param expiration - The expiration time of the value in seconds or a
33
+ * duration object.
33
34
  */
34
35
  constructor(value: T, expiration: DurationObj);
35
36
  }
36
37
  type Utils<T> = {
37
38
  skipCaching: (value: T) => SkipCaching<T>;
38
39
  /**
39
- * Create a new WithExpiration object with the given value and expiration time.
40
+ * Create a new WithExpiration object with the given value and expiration
41
+ * time.
42
+ *
40
43
  * @param value - The value to store in the cache.
41
- * @param expiration - The expiration time of the value in seconds or a duration object.
44
+ * @param expiration - The expiration time of the value in seconds or a
45
+ * duration object.
42
46
  */
43
47
  withExpiration: (value: T, expiration: DurationObj) => WithExpiration<T>;
44
48
  };
45
49
  type GetOptions<T> = {
46
50
  /**
47
- * A function that determines whether a value should be rejected from being cached.
48
- * If the function returns true, the value will be returned but not cached.
51
+ * A function that determines whether a value should be rejected from being
52
+ * cached. If the function returns true, the value will be returned but not
53
+ * cached.
54
+ *
49
55
  * @param value The value to check
50
- * @returns true if the value should be rejected, false otherwise
56
+ * @returns True if the value should be rejected, false otherwise
51
57
  */
52
58
  skipCachingWhen?: (value: T) => boolean;
53
59
  };
package/dist/cache.d.ts CHANGED
@@ -6,15 +6,15 @@ declare function cachedGetter<T>(getter: () => T): {
6
6
  type Options = {
7
7
  /**
8
8
  * The maximum number of items in the cache.
9
+ *
9
10
  * @default 1000
10
11
  */
11
12
  maxCacheSize?: number;
12
- /**
13
- * The maximum age of items in the cache.
14
- */
13
+ /** The maximum age of items in the cache. */
15
14
  maxItemAge?: DurationObj;
16
15
  /**
17
16
  * The throttle for checking expired items in milliseconds.
17
+ *
18
18
  * @default
19
19
  * 10_000
20
20
  */
@@ -29,25 +29,31 @@ declare class WithExpiration<T> {
29
29
  expiration: number;
30
30
  /**
31
31
  * @param value - The value to store in the cache.
32
- * @param expiration - The expiration time of the value in seconds or a duration object.
32
+ * @param expiration - The expiration time of the value in seconds or a
33
+ * duration object.
33
34
  */
34
35
  constructor(value: T, expiration: DurationObj);
35
36
  }
36
37
  type Utils<T> = {
37
38
  skipCaching: (value: T) => SkipCaching<T>;
38
39
  /**
39
- * Create a new WithExpiration object with the given value and expiration time.
40
+ * Create a new WithExpiration object with the given value and expiration
41
+ * time.
42
+ *
40
43
  * @param value - The value to store in the cache.
41
- * @param expiration - The expiration time of the value in seconds or a duration object.
44
+ * @param expiration - The expiration time of the value in seconds or a
45
+ * duration object.
42
46
  */
43
47
  withExpiration: (value: T, expiration: DurationObj) => WithExpiration<T>;
44
48
  };
45
49
  type GetOptions<T> = {
46
50
  /**
47
- * A function that determines whether a value should be rejected from being cached.
48
- * If the function returns true, the value will be returned but not cached.
51
+ * A function that determines whether a value should be rejected from being
52
+ * cached. If the function returns true, the value will be returned but not
53
+ * cached.
54
+ *
49
55
  * @param value The value to check
50
- * @returns true if the value should be rejected, false otherwise
56
+ * @returns True if the value should be rejected, false otherwise
51
57
  */
52
58
  skipCachingWhen?: (value: T) => boolean;
53
59
  };
package/dist/cache.js CHANGED
@@ -29,7 +29,8 @@ var WithExpiration = class {
29
29
  expiration;
30
30
  /**
31
31
  * @param value - The value to store in the cache.
32
- * @param expiration - The expiration time of the value in seconds or a duration object.
32
+ * @param expiration - The expiration time of the value in seconds or a
33
+ * duration object.
33
34
  */
34
35
  constructor(value, expiration) {
35
36
  this.value = value;
@@ -1,3 +1,10 @@
1
+ import {
2
+ typedObjectEntries
3
+ } from "./chunk-DTE2QMWE.js";
4
+ import {
5
+ sortBy
6
+ } from "./chunk-27AL66CH.js";
7
+
1
8
  // src/objUtils.ts
2
9
  function objectTypedEntries(obj) {
3
10
  return Object.entries(obj);
@@ -38,6 +45,18 @@ function rejectObjUndefinedValues(obj) {
38
45
  }
39
46
  return result;
40
47
  }
48
+ function filterObjectKeys(obj, predicate) {
49
+ return Object.fromEntries(
50
+ Object.entries(obj).filter(
51
+ ([key, value]) => predicate(key, value)
52
+ )
53
+ );
54
+ }
55
+ function sortObjectKeys(obj, sortByFn, options) {
56
+ return Object.fromEntries(
57
+ sortBy(typedObjectEntries(obj), sortByFn, options)
58
+ );
59
+ }
41
60
 
42
61
  export {
43
62
  objectTypedEntries,
@@ -46,5 +65,7 @@ export {
46
65
  mapObjectToObject,
47
66
  omit,
48
67
  looseGetObjectProperty,
49
- rejectObjUndefinedValues
68
+ rejectObjUndefinedValues,
69
+ filterObjectKeys,
70
+ sortObjectKeys
50
71
  };