@ls-stack/utils 3.40.0 → 3.42.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 (159) 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-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
  16. package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
  17. package/dist/chunk-GMJTLFM6.js +60 -0
  18. package/dist/{chunk-GHAQOUA6.js → chunk-Y45CE75W.js} +22 -1
  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/debounce.d.cts +12 -20
  23. package/dist/debounce.d.ts +12 -20
  24. package/dist/dedent.d.cts +31 -31
  25. package/dist/dedent.d.ts +31 -31
  26. package/dist/deepEqual.d.cts +10 -9
  27. package/dist/deepEqual.d.ts +10 -9
  28. package/dist/filterObjectOrArrayKeys.d.cts +44 -19
  29. package/dist/filterObjectOrArrayKeys.d.ts +44 -19
  30. package/dist/getAutoIncrementId.d.cts +25 -23
  31. package/dist/getAutoIncrementId.d.ts +25 -23
  32. package/dist/getCompositeKey.d.cts +2 -1
  33. package/dist/getCompositeKey.d.ts +2 -1
  34. package/dist/getValueStableKey.d.cts +4 -3
  35. package/dist/getValueStableKey.d.ts +4 -3
  36. package/dist/mutationUtils.d.cts +2 -2
  37. package/dist/mutationUtils.d.ts +2 -2
  38. package/dist/objUtils.cjs +51 -2
  39. package/dist/objUtils.d.cts +8 -3
  40. package/dist/objUtils.d.ts +8 -3
  41. package/dist/objUtils.js +11 -3
  42. package/dist/parallelAsyncCalls.cjs +2 -1
  43. package/dist/parallelAsyncCalls.d.cts +5 -4
  44. package/dist/parallelAsyncCalls.d.ts +5 -4
  45. package/dist/parallelAsyncCalls.js +2 -1
  46. package/dist/retryOnError.d.cts +23 -20
  47. package/dist/retryOnError.d.ts +23 -20
  48. package/dist/runShellCmd.d.cts +40 -40
  49. package/dist/runShellCmd.d.ts +40 -40
  50. package/dist/safeJson.d.cts +6 -2
  51. package/dist/safeJson.d.ts +6 -2
  52. package/dist/saferTyping.d.cts +21 -14
  53. package/dist/saferTyping.d.ts +21 -14
  54. package/dist/shallowEqual.d.cts +1 -1
  55. package/dist/shallowEqual.d.ts +1 -1
  56. package/dist/stringUtils.cjs +2 -2
  57. package/dist/stringUtils.d.cts +6 -7
  58. package/dist/stringUtils.d.ts +6 -7
  59. package/dist/stringUtils.js +1 -1
  60. package/dist/testUtils.cjs +11 -9
  61. package/dist/testUtils.d.cts +32 -14
  62. package/dist/testUtils.d.ts +32 -14
  63. package/dist/testUtils.js +4 -3
  64. package/dist/throttle.d.cts +57 -48
  65. package/dist/throttle.d.ts +57 -48
  66. package/dist/timers.d.cts +68 -63
  67. package/dist/timers.d.ts +68 -63
  68. package/dist/tsResult.d.cts +7 -6
  69. package/dist/tsResult.d.ts +7 -6
  70. package/dist/typeGuards.d.cts +65 -64
  71. package/dist/typeGuards.d.ts +65 -64
  72. package/dist/typeUtils.d.cts +18 -4
  73. package/dist/typeUtils.d.ts +18 -4
  74. package/dist/typedStrings.d.cts +68 -57
  75. package/dist/typedStrings.d.ts +68 -57
  76. package/dist/typingFnUtils.cjs +15 -0
  77. package/dist/typingFnUtils.d.cts +34 -7
  78. package/dist/typingFnUtils.d.ts +34 -7
  79. package/dist/typingFnUtils.js +18 -35
  80. package/dist/typingTestUtils.cjs +7 -1
  81. package/dist/typingTestUtils.d.cts +52 -11
  82. package/dist/typingTestUtils.d.ts +52 -11
  83. package/dist/typingTestUtils.js +7 -1
  84. package/dist/typingUtils.d.cts +4 -1
  85. package/dist/typingUtils.d.ts +4 -1
  86. package/dist/yamlStringify.cjs +11 -9
  87. package/dist/yamlStringify.js +2 -2
  88. package/package.json +5 -1
  89. package/docs/README.md +0 -72
  90. package/docs/_media/modules.md +0 -58
  91. package/docs/arrayUtils/-internal-.md +0 -179
  92. package/docs/arrayUtils/README.md +0 -550
  93. package/docs/assertions/-internal-.md +0 -63
  94. package/docs/assertions/README.md +0 -565
  95. package/docs/asyncQueue/-internal-.md +0 -297
  96. package/docs/asyncQueue/README.md +0 -1485
  97. package/docs/awaitDebounce.md +0 -66
  98. package/docs/cache/-internal-.md +0 -168
  99. package/docs/cache/README.md +0 -360
  100. package/docs/castValues.md +0 -47
  101. package/docs/concurrentCalls/-internal-.md +0 -490
  102. package/docs/concurrentCalls/README.md +0 -299
  103. package/docs/consoleFmt.md +0 -115
  104. package/docs/conversions.md +0 -27
  105. package/docs/createThrottleController/-internal-.md +0 -73
  106. package/docs/createThrottleController/README.md +0 -31
  107. package/docs/debounce.md +0 -188
  108. package/docs/dedent/-internal-.md +0 -17
  109. package/docs/dedent/README.md +0 -204
  110. package/docs/deepEqual.md +0 -94
  111. package/docs/enhancedMap.md +0 -358
  112. package/docs/exhaustiveMatch/-internal-.md +0 -39
  113. package/docs/exhaustiveMatch/README.md +0 -146
  114. package/docs/filterObjectOrArrayKeys.md +0 -109
  115. package/docs/getAutoIncrementId.md +0 -93
  116. package/docs/getCompositeKey.md +0 -39
  117. package/docs/getValueStableKey.md +0 -57
  118. package/docs/hash.md +0 -31
  119. package/docs/interpolate/-internal-.md +0 -61
  120. package/docs/interpolate/README.md +0 -62
  121. package/docs/keepPrevIfUnchanged.md +0 -43
  122. package/docs/levenshtein.md +0 -93
  123. package/docs/main.md +0 -21
  124. package/docs/mathUtils.md +0 -137
  125. package/docs/modules.md +0 -58
  126. package/docs/mutationUtils.md +0 -44
  127. package/docs/objUtils.md +0 -237
  128. package/docs/parallelAsyncCalls/-internal-.md +0 -347
  129. package/docs/parallelAsyncCalls/README.md +0 -45
  130. package/docs/promiseUtils/-internal-.md +0 -69
  131. package/docs/promiseUtils/README.md +0 -31
  132. package/docs/retryOnError/-internal-.md +0 -111
  133. package/docs/retryOnError/README.md +0 -168
  134. package/docs/runShellCmd/-internal-.md +0 -111
  135. package/docs/runShellCmd/README.md +0 -201
  136. package/docs/safeJson.md +0 -51
  137. package/docs/saferTyping.md +0 -228
  138. package/docs/serializeXML.md +0 -100
  139. package/docs/shallowEqual.md +0 -33
  140. package/docs/sleep.md +0 -27
  141. package/docs/stringUtils/-internal-.md +0 -17
  142. package/docs/stringUtils/README.md +0 -270
  143. package/docs/testUtils.md +0 -382
  144. package/docs/throttle/-internal-.md +0 -47
  145. package/docs/throttle/README.md +0 -178
  146. package/docs/time.md +0 -274
  147. package/docs/timers.md +0 -256
  148. package/docs/tsResult/-internal-.md +0 -327
  149. package/docs/tsResult/README.md +0 -702
  150. package/docs/typeGuards.md +0 -399
  151. package/docs/typeUtils/-internal-.md +0 -99
  152. package/docs/typeUtils/README.md +0 -195
  153. package/docs/typeUtils.typesTest.md +0 -7
  154. package/docs/typedStrings.md +0 -458
  155. package/docs/typingFnUtils/-internal-.md +0 -43
  156. package/docs/typingFnUtils/README.md +0 -317
  157. package/docs/typingTestUtils.md +0 -172
  158. package/docs/typingUtils.md +0 -135
  159. package/docs/yamlStringify.md +0 -83
@@ -67,22 +67,23 @@ var AsyncQueue = class _AsyncQueue {
67
67
  /**
68
68
  * Event emitter for tracking task lifecycle
69
69
  *
70
- * @example Listening to Events
71
- * ```typescript
72
- * const queue = createAsyncQueue<string>();
70
+ * @example
71
+ * Listening to Events
72
+ * ```typescript
73
+ * const queue = createAsyncQueue<string>();
73
74
  *
74
- * queue.events.on('start', (event) => {
75
+ * queue.events.on('start', (event) => {
75
76
  * console.log('Task started:', event.payload.meta);
76
- * });
77
+ * });
77
78
  *
78
- * queue.events.on('complete', (event) => {
79
+ * queue.events.on('complete', (event) => {
79
80
  * console.log('Task completed:', event.payload.value);
80
- * });
81
+ * });
81
82
  *
82
- * queue.events.on('error', (event) => {
83
+ * queue.events.on('error', (event) => {
83
84
  * console.error('Task failed:', event.payload.error);
84
- * });
85
- * ```
85
+ * });
86
+ * ```
86
87
  */
87
88
  events = (0, import_evtmitter.evtmitter)();
88
89
  #signal;
@@ -196,32 +197,33 @@ var AsyncQueue = class _AsyncQueue {
196
197
  /**
197
198
  * Add a task that returns a Result to the queue
198
199
  *
199
- * Use this method when your task function already returns a Result type.
200
- * For functions that throw errors or return plain values, use `resultifyAdd` instead.
200
+ * Use this method when your task function already returns a Result type. For
201
+ * functions that throw errors or return plain values, use `resultifyAdd`
202
+ * instead.
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const queue = createAsyncQueue<string>();
207
+ *
208
+ * const result = await queue.add(async () => {
209
+ * try {
210
+ * const data = await fetchData();
211
+ * return Result.ok(data);
212
+ * } catch (error) {
213
+ * return Result.err(error);
214
+ * }
215
+ * });
216
+ *
217
+ * if (result.ok) {
218
+ * console.log('Success:', result.value);
219
+ * } else {
220
+ * console.log('Error:', result.error);
221
+ * }
222
+ * ```;
201
223
  *
202
224
  * @param fn - Task function that returns a Result
203
225
  * @param options - Optional configuration for this task
204
226
  * @returns Promise that resolves with the task result
205
- *
206
- * @example
207
- * ```typescript
208
- * const queue = createAsyncQueue<string>();
209
- *
210
- * const result = await queue.add(async () => {
211
- * try {
212
- * const data = await fetchData();
213
- * return Result.ok(data);
214
- * } catch (error) {
215
- * return Result.err(error);
216
- * }
217
- * });
218
- *
219
- * if (result.ok) {
220
- * console.log('Success:', result.value);
221
- * } else {
222
- * console.log('Error:', result.error);
223
- * }
224
- * ```
225
227
  */
226
228
  async add(fn, options) {
227
229
  if (this.#signal?.aborted) {
@@ -265,37 +267,39 @@ var AsyncQueue = class _AsyncQueue {
265
267
  * This is the most commonly used method. It automatically wraps your function
266
268
  * to handle errors and convert them to Result types.
267
269
  *
268
- * @param fn - Task function that returns a value or throws
269
- * @param options - Optional configuration for this task
270
- * @returns Promise that resolves with the task result wrapped in Result
271
- *
272
- * @example Basic Usage
273
- * ```typescript
274
- * const queue = createAsyncQueue<string>();
270
+ * @example
271
+ * Basic Usage
272
+ * ```typescript
273
+ * const queue = createAsyncQueue<string>();
275
274
  *
276
- * queue.resultifyAdd(async () => {
275
+ * queue.resultifyAdd(async () => {
277
276
  * const response = await fetch('/api/data');
278
277
  * return response.json();
279
- * }).then(result => {
278
+ * }).then(result => {
280
279
  * if (result.ok) {
281
- * console.log('Data:', result.value);
280
+ * console.log('Data:', result.value);
282
281
  * } else {
283
- * console.error('Failed:', result.error);
282
+ * console.error('Failed:', result.error);
284
283
  * }
285
- * });
286
- * ```
284
+ * });
285
+ * ```
287
286
  *
288
- * @example With Callbacks
289
- * ```typescript
290
- * queue.resultifyAdd(
287
+ * @example
288
+ * With Callbacks
289
+ * ```typescript
290
+ * queue.resultifyAdd(
291
291
  * async () => processData(),
292
292
  * {
293
- * onComplete: (data) => console.log('Processed:', data),
294
- * onError: (error) => console.error('Failed:', error),
295
- * timeout: 5000
293
+ * onComplete: (data) => console.log('Processed:', data),
294
+ * onError: (error) => console.error('Failed:', error),
295
+ * timeout: 5000
296
296
  * }
297
- * );
298
- * ```
297
+ * );
298
+ * ```
299
+ *
300
+ * @param fn - Task function that returns a value or throws
301
+ * @param options - Optional configuration for this task
302
+ * @returns Promise that resolves with the task result wrapped in Result
299
303
  */
300
304
  resultifyAdd(fn, options) {
301
305
  return this.add(
@@ -440,29 +444,32 @@ var AsyncQueue = class _AsyncQueue {
440
444
  this.#resolveIdleWaiters();
441
445
  }
442
446
  /**
443
- * Wait for the queue to become idle (no pending tasks, no queued tasks, and no rate-limit timers)
447
+ * Wait for the queue to become idle (no pending tasks, no queued tasks, and
448
+ * no rate-limit timers)
444
449
  *
445
450
  * This method resolves when:
451
+ *
446
452
  * - All tasks have completed (success or failure)
447
453
  * - The queue is stopped due to error (stopOnError), even with remaining tasks
448
- * - There are no queued tasks, no running tasks, and no pending rate-limit timers
449
- *
450
- * @returns Promise that resolves when the queue is idle
454
+ * - There are no queued tasks, no running tasks, and no pending rate-limit
455
+ * timers
451
456
  *
452
457
  * @example
453
- * ```typescript
454
- * const queue = createAsyncQueue<string>();
458
+ * ```typescript
459
+ * const queue = createAsyncQueue<string>();
455
460
  *
456
- * // Add multiple tasks
457
- * for (let i = 0; i < 10; i++) {
461
+ * // Add multiple tasks
462
+ * for (let i = 0; i < 10; i++) {
458
463
  * queue.resultifyAdd(async () => `task ${i}`);
459
- * }
464
+ * }
465
+ *
466
+ * // Wait for all tasks to complete
467
+ * await queue.onIdle();
460
468
  *
461
- * // Wait for all tasks to complete
462
- * await queue.onIdle();
469
+ * console.log(`Completed: ${queue.completed}, Failed: ${queue.failed}`);
470
+ * ```
463
471
  *
464
- * console.log(`Completed: ${queue.completed}, Failed: ${queue.failed}`);
465
- * ```
472
+ * @returns Promise that resolves when the queue is idle
466
473
  */
467
474
  async onIdle() {
468
475
  if (this.#stopped || this.#pending === 0 && this.#size === 0 && this.#rateLimitTimeouts.size === 0) {
@@ -493,24 +500,24 @@ var AsyncQueue = class _AsyncQueue {
493
500
  /**
494
501
  * Clear all queued tasks (does not affect currently running tasks)
495
502
  *
496
- * This removes all tasks waiting in the queue but allows currently
497
- * executing tasks to complete normally.
503
+ * This removes all tasks waiting in the queue but allows currently executing
504
+ * tasks to complete normally.
498
505
  *
499
506
  * @example
500
- * ```typescript
501
- * const queue = createAsyncQueue({ concurrency: 1 });
507
+ * ```typescript
508
+ * const queue = createAsyncQueue({ concurrency: 1 });
502
509
  *
503
- * // Add multiple tasks
504
- * queue.resultifyAdd(async () => longRunningTask()); // Will start immediately
505
- * queue.resultifyAdd(async () => task2()); // Queued
506
- * queue.resultifyAdd(async () => task3()); // Queued
510
+ * // Add multiple tasks
511
+ * queue.resultifyAdd(async () => longRunningTask()); // Will start immediately
512
+ * queue.resultifyAdd(async () => task2()); // Queued
513
+ * queue.resultifyAdd(async () => task3()); // Queued
507
514
  *
508
- * // Clear remaining queued tasks
509
- * queue.clear();
515
+ * // Clear remaining queued tasks
516
+ * queue.clear();
510
517
  *
511
- * // Only the first task will complete
512
- * await queue.onIdle();
513
- * ```
518
+ * // Only the first task will complete
519
+ * await queue.onIdle();
520
+ * ```;
514
521
  */
515
522
  clear() {
516
523
  this.#queue = [];
@@ -544,17 +551,17 @@ var AsyncQueue = class _AsyncQueue {
544
551
  * Manually start processing tasks (only needed if autoStart: false)
545
552
  *
546
553
  * @example
547
- * ```typescript
548
- * const queue = createAsyncQueue({ autoStart: false });
554
+ * ```typescript
555
+ * const queue = createAsyncQueue({ autoStart: false });
549
556
  *
550
- * // Add tasks without starting processing
551
- * queue.resultifyAdd(async () => 'task1');
552
- * queue.resultifyAdd(async () => 'task2');
557
+ * // Add tasks without starting processing
558
+ * queue.resultifyAdd(async () => 'task1');
559
+ * queue.resultifyAdd(async () => 'task2');
553
560
  *
554
- * // Start processing when ready
555
- * queue.start();
556
- * await queue.onIdle();
557
- * ```
561
+ * // Start processing when ready
562
+ * queue.start();
563
+ * await queue.onIdle();
564
+ * ```;
558
565
  */
559
566
  start() {
560
567
  if (this.#stopped) {
@@ -567,26 +574,24 @@ var AsyncQueue = class _AsyncQueue {
567
574
  * Pause processing new tasks (currently running tasks continue)
568
575
  *
569
576
  * @example
570
- * ```typescript
571
- * const queue = createAsyncQueue();
577
+ * ```typescript
578
+ * const queue = createAsyncQueue();
572
579
  *
573
- * // Start some tasks
574
- * queue.resultifyAdd(async () => longRunningTask1());
575
- * queue.resultifyAdd(async () => longRunningTask2());
580
+ * // Start some tasks
581
+ * queue.resultifyAdd(async () => longRunningTask1());
582
+ * queue.resultifyAdd(async () => longRunningTask2());
576
583
  *
577
- * // Pause before more tasks are picked up
578
- * queue.pause();
584
+ * // Pause before more tasks are picked up
585
+ * queue.pause();
579
586
  *
580
- * // Later, resume processing
581
- * queue.resume();
582
- * ```
587
+ * // Later, resume processing
588
+ * queue.resume();
589
+ * ```;
583
590
  */
584
591
  pause() {
585
592
  this.#paused = true;
586
593
  }
587
- /**
588
- * Resume processing tasks after pause
589
- */
594
+ /** Resume processing tasks after pause */
590
595
  resume() {
591
596
  this.#paused = false;
592
597
  if (this.#started && !this.#stopped) {
@@ -596,27 +601,27 @@ var AsyncQueue = class _AsyncQueue {
596
601
  /**
597
602
  * Reset the queue after being stopped, allowing new tasks to be processed
598
603
  *
599
- * This clears the stopped state and error reason, and resumes processing
600
- * any remaining queued tasks if autoStart was enabled.
604
+ * This clears the stopped state and error reason, and resumes processing any
605
+ * remaining queued tasks if autoStart was enabled.
601
606
  *
602
607
  * @example
603
- * ```typescript
604
- * const queue = createAsyncQueue({ stopOnError: true });
608
+ * ```typescript
609
+ * const queue = createAsyncQueue({ stopOnError: true });
605
610
  *
606
- * // Add tasks that will cause the queue to stop
607
- * queue.resultifyAdd(async () => { throw new Error('fail'); });
608
- * queue.resultifyAdd(async () => 'remaining task');
611
+ * // Add tasks that will cause the queue to stop
612
+ * queue.resultifyAdd(async () => { throw new Error('fail'); });
613
+ * queue.resultifyAdd(async () => 'remaining task');
609
614
  *
610
- * await queue.onIdle();
615
+ * await queue.onIdle();
611
616
  *
612
- * if (queue.isStopped) {
617
+ * if (queue.isStopped) {
613
618
  * console.log(`Queue stopped, ${queue.size} tasks remaining`);
614
619
  *
615
620
  * // Reset and process remaining tasks
616
621
  * queue.reset();
617
622
  * await queue.onIdle();
618
- * }
619
- * ```
623
+ * }
624
+ * ```
620
625
  */
621
626
  reset() {
622
627
  this.#stopped = false;