@vielzeug/toolkit 1.0.13 → 1.1.2

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 (141) hide show
  1. package/dist/array/{sortBy.cjs → arrange.cjs} +2 -2
  2. package/dist/array/arrange.cjs.map +1 -0
  3. package/dist/array/arrange.js +6 -0
  4. package/dist/array/arrange.js.map +1 -0
  5. package/dist/array/chunk.cjs.map +1 -1
  6. package/dist/array/chunk.js.map +1 -1
  7. package/dist/array/list.cjs +1 -1
  8. package/dist/array/list.cjs.map +1 -1
  9. package/dist/array/list.js +86 -53
  10. package/dist/array/list.js.map +1 -1
  11. package/dist/array/remoteList.cjs +2 -0
  12. package/dist/array/remoteList.cjs.map +1 -0
  13. package/dist/array/remoteList.js +123 -0
  14. package/dist/array/remoteList.js.map +1 -0
  15. package/dist/async/attempt.cjs.map +1 -0
  16. package/dist/async/attempt.js.map +1 -0
  17. package/dist/async/defer.cjs +2 -0
  18. package/dist/async/defer.cjs.map +1 -0
  19. package/dist/async/defer.js +10 -0
  20. package/dist/async/defer.js.map +1 -0
  21. package/dist/async/delay.cjs.map +1 -0
  22. package/dist/async/delay.js.map +1 -0
  23. package/dist/async/parallel.cjs +2 -0
  24. package/dist/async/parallel.cjs.map +1 -0
  25. package/dist/async/parallel.js +28 -0
  26. package/dist/async/parallel.js.map +1 -0
  27. package/dist/async/pool.cjs +2 -0
  28. package/dist/async/pool.cjs.map +1 -0
  29. package/dist/async/pool.js +22 -0
  30. package/dist/async/pool.js.map +1 -0
  31. package/dist/async/predict.cjs.map +1 -0
  32. package/dist/async/predict.js.map +1 -0
  33. package/dist/async/queue.cjs +2 -0
  34. package/dist/async/queue.cjs.map +1 -0
  35. package/dist/async/queue.js +57 -0
  36. package/dist/async/queue.js.map +1 -0
  37. package/dist/async/race.cjs +2 -0
  38. package/dist/async/race.cjs.map +1 -0
  39. package/dist/async/race.js +8 -0
  40. package/dist/async/race.js.map +1 -0
  41. package/dist/async/retry.cjs.map +1 -0
  42. package/dist/{function → async}/retry.js +4 -4
  43. package/dist/async/retry.js.map +1 -0
  44. package/dist/async/sleep.cjs +2 -0
  45. package/dist/async/sleep.cjs.map +1 -0
  46. package/dist/{function → async}/sleep.js +1 -1
  47. package/dist/async/sleep.js.map +1 -0
  48. package/dist/async/waitFor.cjs +2 -0
  49. package/dist/async/waitFor.cjs.map +1 -0
  50. package/dist/async/waitFor.js +37 -0
  51. package/dist/async/waitFor.js.map +1 -0
  52. package/dist/date/expires.cjs.map +1 -1
  53. package/dist/date/expires.js.map +1 -1
  54. package/dist/date/interval.cjs.map +1 -1
  55. package/dist/date/interval.js.map +1 -1
  56. package/dist/date/timeDiff.cjs.map +1 -1
  57. package/dist/date/timeDiff.js.map +1 -1
  58. package/dist/function/memo.cjs.map +1 -1
  59. package/dist/function/memo.js.map +1 -1
  60. package/dist/function/proxy.cjs.map +1 -1
  61. package/dist/function/proxy.js.map +1 -1
  62. package/dist/function/prune.cjs +2 -0
  63. package/dist/function/prune.cjs.map +1 -0
  64. package/dist/function/prune.js +30 -0
  65. package/dist/function/prune.js.map +1 -0
  66. package/dist/index.cjs +1 -1
  67. package/dist/index.d.ts +575 -51
  68. package/dist/index.js +242 -206
  69. package/dist/index.js.map +1 -1
  70. package/dist/logit/dist/logit.cjs +1 -1
  71. package/dist/logit/dist/logit.cjs.map +1 -1
  72. package/dist/logit/dist/logit.js +147 -64
  73. package/dist/logit/dist/logit.js.map +1 -1
  74. package/dist/math/abs.cjs +2 -0
  75. package/dist/math/abs.cjs.map +1 -0
  76. package/dist/math/abs.js +7 -0
  77. package/dist/math/abs.js.map +1 -0
  78. package/dist/math/add.cjs +2 -0
  79. package/dist/math/add.cjs.map +1 -0
  80. package/dist/math/add.js +9 -0
  81. package/dist/math/add.js.map +1 -0
  82. package/dist/math/allocate.cjs +2 -0
  83. package/dist/math/allocate.cjs.map +1 -0
  84. package/dist/math/allocate.js +29 -0
  85. package/dist/math/allocate.js.map +1 -0
  86. package/dist/math/distribute.cjs +2 -0
  87. package/dist/math/distribute.cjs.map +1 -0
  88. package/dist/math/distribute.js +18 -0
  89. package/dist/math/distribute.js.map +1 -0
  90. package/dist/math/divide.cjs +2 -0
  91. package/dist/math/divide.cjs.map +1 -0
  92. package/dist/math/divide.js +11 -0
  93. package/dist/math/divide.js.map +1 -0
  94. package/dist/math/multiply.cjs +2 -0
  95. package/dist/math/multiply.cjs.map +1 -0
  96. package/dist/math/multiply.js +9 -0
  97. package/dist/math/multiply.js.map +1 -0
  98. package/dist/math/subtract.cjs +2 -0
  99. package/dist/math/subtract.cjs.map +1 -0
  100. package/dist/math/subtract.js +9 -0
  101. package/dist/math/subtract.js.map +1 -0
  102. package/dist/money/currency.cjs +2 -0
  103. package/dist/money/currency.cjs.map +1 -0
  104. package/dist/money/currency.js +49 -0
  105. package/dist/money/currency.js.map +1 -0
  106. package/dist/money/exchange.cjs +2 -0
  107. package/dist/money/exchange.cjs.map +1 -0
  108. package/dist/money/exchange.js +13 -0
  109. package/dist/money/exchange.js.map +1 -0
  110. package/dist/object/cache.cjs +2 -0
  111. package/dist/object/cache.cjs.map +1 -0
  112. package/dist/object/cache.js +63 -0
  113. package/dist/object/cache.js.map +1 -0
  114. package/dist/object/merge.cjs.map +1 -1
  115. package/dist/object/merge.js.map +1 -1
  116. package/dist/object/parseJSON.cjs.map +1 -1
  117. package/dist/object/parseJSON.js.map +1 -1
  118. package/dist/object/path.cjs.map +1 -1
  119. package/dist/object/path.js.map +1 -1
  120. package/package.json +1 -1
  121. package/dist/array/sortBy.cjs.map +0 -1
  122. package/dist/array/sortBy.js +0 -6
  123. package/dist/array/sortBy.js.map +0 -1
  124. package/dist/function/attempt.cjs.map +0 -1
  125. package/dist/function/attempt.js.map +0 -1
  126. package/dist/function/delay.cjs.map +0 -1
  127. package/dist/function/delay.js.map +0 -1
  128. package/dist/function/predict.cjs.map +0 -1
  129. package/dist/function/predict.js.map +0 -1
  130. package/dist/function/retry.cjs.map +0 -1
  131. package/dist/function/retry.js.map +0 -1
  132. package/dist/function/sleep.cjs +0 -2
  133. package/dist/function/sleep.cjs.map +0 -1
  134. package/dist/function/sleep.js.map +0 -1
  135. /package/dist/{function → async}/attempt.cjs +0 -0
  136. /package/dist/{function → async}/attempt.js +0 -0
  137. /package/dist/{function → async}/delay.cjs +0 -0
  138. /package/dist/{function → async}/delay.js +0 -0
  139. /package/dist/{function → async}/predict.cjs +0 -0
  140. /package/dist/{function → async}/predict.js +0 -0
  141. /package/dist/{function → async}/retry.cjs +0 -0
package/dist/index.d.ts CHANGED
@@ -1,3 +1,40 @@
1
+ /**
2
+ * Returns the absolute value of a number.
3
+ * Supports both regular numbers and bigint.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * abs(-5); // 5
8
+ * abs(3); // 3
9
+ * abs(-100n); // 100n
10
+ * ```
11
+ *
12
+ * @param value - The number or bigint to get absolute value of
13
+ * @returns Absolute value
14
+ */
15
+ export declare function abs(value: number): number;
16
+
17
+ export declare function abs(value: bigint): bigint;
18
+
19
+ /**
20
+ * Adds two numbers with precision handling for financial calculations.
21
+ * Supports both regular numbers and bigint for exact precision.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * add(10, 20); // 30
26
+ * add(0.1, 0.2); // 0.3 (precision-safe)
27
+ * add(100n, 200n); // 300n
28
+ * ```
29
+ *
30
+ * @param a - First number or bigint
31
+ * @param b - Second number or bigint
32
+ * @returns Sum of a and b
33
+ */
34
+ export declare function add(a: number, b: number): number;
35
+
36
+ export declare function add(a: bigint, b: bigint): bigint;
37
+
1
38
  /**
2
39
  * Aggregates an array of objects into an object based on a key generated by a selector function.
3
40
  *
@@ -20,6 +57,31 @@ export declare namespace aggregate {
20
57
  var fp: boolean;
21
58
  }
22
59
 
60
+ /**
61
+ * Distributes an amount proportionally according to given ratios.
62
+ * Handles rounding to ensure the sum equals the original amount exactly.
63
+ * Critical for financial operations like splitting payments to avoid rounding errors.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * // Split $100 in ratio 1:2:3
68
+ * allocate(100, [1, 2, 3]);
69
+ * // [17, 33, 50] - sum is exactly 100
70
+ *
71
+ * // Split with bigint (e.g., cents)
72
+ * allocate(10000n, [1, 1, 1]);
73
+ * // [3334n, 3333n, 3333n] - sum is exactly 10000n
74
+ * ```
75
+ *
76
+ * @param amount - Total amount to allocate
77
+ * @param ratios - Array of ratios for distribution
78
+ * @returns Array of allocated amounts (sum equals original amount)
79
+ * @throws {Error} If ratios array is empty or contains negative values
80
+ */
81
+ export declare function allocate(amount: number, ratios: number[]): number[];
82
+
83
+ export declare function allocate(amount: bigint, ratios: number[]): bigint[];
84
+
23
85
  /**
24
86
  * Either adds or removes an item from an array, based on whether it already exists in the array.
25
87
  *
@@ -54,6 +116,27 @@ export declare namespace alternate {
54
116
 
55
117
  export declare type ArgType = 'array' | 'boolean' | 'date' | 'error' | 'function' | 'map' | 'nan' | 'null' | 'number' | 'object' | 'promise' | 'regexp' | 'set' | 'string' | 'symbol' | 'weakmap' | 'weakset' | 'undefined';
56
118
 
119
+ /**
120
+ * Arranges (sorts) an array of objects based on multiple selectors.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * const data = [
125
+ * { name: 'Alice', age: 30 },
126
+ * { name: 'Bob', age: 25 },
127
+ * { name: 'Charlie', age: 35 },
128
+ * { name: 'Alice', age: 25 },
129
+ * { name: 'Bob', age: 30 },
130
+ * { name: 'Charlie', age: 30 },
131
+ * ].arrange(data, { name: 'asc', age: 'desc' }); // [ { name: 'Alice', age: 30 }, { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Charlie', age: 30 } ]
132
+ * ```
133
+ *
134
+ * @param array - The array to sort.
135
+ * @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.
136
+ * @returns A new sorted array.
137
+ */
138
+ export declare const arrange: <T>(array: T[], selectors: Partial<Record<keyof T, "asc" | "desc">>) => T[];
139
+
57
140
  /**
58
141
  * Asserts that the condition is true. If the condition is false, it throws an error
59
142
  * with the provided message or logs a warning in soft mode.
@@ -177,6 +260,35 @@ export declare function average<T>(array: T[], callback?: (item: T) => number |
177
260
  */
178
261
  export declare function boil<T>(array: readonly T[], callback: (a: T, b: T) => T): T | undefined;
179
262
 
263
+ /**
264
+ * Creates a generic key-value cache with automatic garbage collection and observer support.
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * const myCache = cache<string>();
269
+ * myCache.set(['user', 1], 'John Doe');
270
+ * const value = myCache.get(['user', 1]); // 'John Doe'
271
+ * myCache.scheduleGc(['user', 1], 5000); // Auto-delete after 5s
272
+ * ```
273
+ *
274
+ * @template T - The type of values stored in the cache.
275
+ *
276
+ * @returns A cache instance with get, set, delete, clear, and GC methods.
277
+ */
278
+ export declare function cache<T>(): {
279
+ clear: () => void;
280
+ delete: (key: readonly unknown[]) => boolean;
281
+ get: (key: readonly unknown[]) => T | undefined;
282
+ getMeta: (key: readonly unknown[]) => Record<string, unknown> | undefined;
283
+ getMetaByHash: (keyHash: string) => Record<string, unknown> | undefined;
284
+ hash: (key: readonly unknown[]) => string;
285
+ listMetaHashes: () => string[];
286
+ scheduleGc: (key: readonly unknown[], delayMs: number) => void;
287
+ set: (key: readonly unknown[], value: T) => void;
288
+ setMeta: (key: readonly unknown[], meta: Record<string, unknown>) => void;
289
+ size: () => number;
290
+ };
291
+
180
292
  /** biome-ignore-all lint/suspicious/noExplicitAny: - */
181
293
  export declare type Callback<T = any, R = any> = (value: T, index: number, array: T[]) => R;
182
294
 
@@ -361,12 +473,6 @@ export declare function compose<T extends FnDynamic[]>(...fns: T): ComposeReturn
361
473
 
362
474
  declare type ComposeReturn<T extends FnDynamic[]> = (...args: LastParameters<T>) => FirstReturnType<T> extends Promise<any> ? Promise<Awaited<FirstReturnType<T>>> : FirstReturnType<T>;
363
475
 
364
- declare type Config<T> = {
365
- filterFn?: Predicate<T>;
366
- limit?: number;
367
- sortFn?: (a: T, b: T) => number;
368
- };
369
-
370
476
  /**
371
477
  * Checks if a value is present in an array.
372
478
  *
@@ -390,6 +496,36 @@ export declare namespace contains {
390
496
  var fp: boolean;
391
497
  }
392
498
 
499
+ /**
500
+ * Formats a monetary amount as a currency string with proper locale and symbol.
501
+ * Handles decimal places automatically based on currency.
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * const money = { amount: 123456n, currency: 'USD' };
506
+ *
507
+ * currency(money); // '$1,234.56' (default en-US)
508
+ * currency(money, { locale: 'de-DE' }); // '1.234,56 $'
509
+ * currency(money, { style: 'code' }); // 'USD 1,234.56'
510
+ * currency(money, { style: 'name' }); // '1,234.56 US dollars'
511
+ * ```
512
+ *
513
+ * @param money - Money object to format
514
+ * @param options - Formatting options
515
+ * @returns Formatted currency string
516
+ */
517
+ export declare function currency(money: Money, options?: CurrencyFormatOptions): string;
518
+
519
+ /**
520
+ * Options for currency formatting.
521
+ */
522
+ export declare type CurrencyFormatOptions = {
523
+ locale?: string;
524
+ style?: 'symbol' | 'code' | 'name';
525
+ minimumFractionDigits?: number;
526
+ maximumFractionDigits?: number;
527
+ };
528
+
393
529
  export declare type Curried<P extends readonly unknown[], R> = P extends readonly [] ? () => R : <A extends readonly [unknown, ...(readonly unknown[])]>(...args: A) => P extends readonly [...A, ...infer Rest] ? (Rest extends readonly [] ? R : Curried<Rest, R>) : never;
394
530
 
395
531
  export declare function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;
@@ -412,6 +548,29 @@ declare type DeepMerge<T, U> = T extends Obj ? U extends Obj ? {
412
548
  [K in keyof T | keyof U]: K extends keyof T ? K extends keyof U ? DeepMerge<T[K], U[K]> : T[K] : K extends keyof U ? U[K] : never;
413
549
  } : U : U;
414
550
 
551
+ /**
552
+ * Creates a deferred promise with resolve and reject methods exposed.
553
+ * Useful for creating promises that are resolved/rejected externally.
554
+ *
555
+ * @example
556
+ * ```ts
557
+ * const deferred = defer<string>();
558
+ *
559
+ * setTimeout(() => {
560
+ * deferred.resolve('Done!');
561
+ * }, 1000);
562
+ *
563
+ * const result = await deferred.promise; // 'Done!'
564
+ * ```
565
+ *
566
+ * @returns Object with promise and resolve/reject methods
567
+ */
568
+ export declare function defer<T = void>(): {
569
+ promise: Promise<T>;
570
+ resolve: (value: T | PromiseLike<T>) => void;
571
+ reject: (reason?: unknown) => void;
572
+ };
573
+
415
574
  /**
416
575
  * Delays the execution of a function by a specified amount of time.
417
576
  *
@@ -447,6 +606,51 @@ export declare function delay<T extends Fn>(fn: T, delay?: number): Promise<any>
447
606
  */
448
607
  export declare function diff<T extends Obj>(curr?: T, prev?: T, compareFn?: (a: unknown, b: unknown) => boolean): Partial<T>;
449
608
 
609
+ /**
610
+ * Distributes an amount evenly among N parties.
611
+ * Handles rounding to ensure the sum equals the original amount exactly.
612
+ * Useful for splitting bills, costs, or payments equally.
613
+ *
614
+ * @example
615
+ * ```ts
616
+ * // Split $100 among 3 people
617
+ * distribute(100, 3);
618
+ * // [34, 33, 33] - sum is exactly 100
619
+ *
620
+ * // Split with bigint (e.g., cents)
621
+ * distribute(10000n, 3);
622
+ * // [3334n, 3333n, 3333n] - sum is exactly 10000n
623
+ * ```
624
+ *
625
+ * @param amount - Total amount to distribute
626
+ * @param parts - Number of parts to divide into
627
+ * @returns Array of distributed amounts (a sum equals original amount)
628
+ * @throws {Error} If parts are less than 1
629
+ */
630
+ export declare function distribute(amount: number, parts: number): number[];
631
+
632
+ export declare function distribute(amount: bigint, parts: number): bigint[];
633
+
634
+ /**
635
+ * Divides a number by a divisor with precision handling for financial calculations.
636
+ * Supports both regular numbers and bigint for exact precision.
637
+ *
638
+ * @example
639
+ * ```ts
640
+ * divide(20, 5); // 4
641
+ * divide(0.6, 3); // 0.2 (precision-safe)
642
+ * divide(500n, 5n); // 100n
643
+ * ```
644
+ *
645
+ * @param a - Number to divide (dividend)
646
+ * @param b - Divisor
647
+ * @returns Quotient of a divided by b
648
+ * @throws {Error} If divisor is zero
649
+ */
650
+ export declare function divide(a: number, b: number): number;
651
+
652
+ export declare function divide(a: bigint, b: bigint): bigint;
653
+
450
654
  /**
451
655
  * “Draw” a random item from an array.
452
656
  *
@@ -505,6 +709,35 @@ export declare namespace every {
505
709
  var fp: boolean;
506
710
  }
507
711
 
712
+ /**
713
+ * Converts money from one currency to another using the provided exchange rate.
714
+ * Maintains precision by using bigint arithmetic.
715
+ *
716
+ * @example
717
+ * ```ts
718
+ * const usd = { amount: 100000n, currency: 'USD' }; // $1,000.00
719
+ * const rate = { from: 'USD', to: 'EUR', rate: 0.85 };
720
+ *
721
+ * exchange(usd, rate);
722
+ * // { amount: 85000n, currency: 'EUR' } // €850.00
723
+ * ```
724
+ *
725
+ * @param money - Money to convert
726
+ * @param rate - Exchange rate information
727
+ * @returns Converted money in target currency
728
+ * @throws {Error} If source currency doesn't match rate.from
729
+ */
730
+ export declare function exchange(money: Money, rate: ExchangeRate): Money;
731
+
732
+ /**
733
+ * Exchange rate for currency conversion.
734
+ */
735
+ export declare type ExchangeRate = {
736
+ from: string;
737
+ to: string;
738
+ rate: number;
739
+ };
740
+
508
741
  export declare type Expires = 'EXPIRED' | 'SOON' | 'LATER' | 'NEVER' | 'UNKNOWN';
509
742
 
510
743
  /**
@@ -1297,32 +1530,42 @@ declare type LastReturnType<T> = T extends [...any, infer Last extends FnDynamic
1297
1530
  */
1298
1531
  export declare function le(a: unknown, b: unknown): boolean;
1299
1532
 
1300
- export declare function list<T>(initialData: T[], config?: Config<T>): {
1301
- readonly current: T[];
1302
- data: T[];
1303
- filter(predicate: (item: T) => boolean): T[];
1304
- limit: number;
1305
- readonly meta: {
1306
- end: number;
1307
- isEmpty: boolean;
1308
- isFirst: boolean;
1309
- isLast: boolean;
1310
- limit: number;
1311
- page: number;
1312
- pages: number;
1313
- start: number;
1314
- total: number;
1315
- };
1533
+ export declare type List<T, F, S> = {
1534
+ readonly current: readonly T[];
1535
+ readonly meta: Meta;
1536
+ subscribe(listener: () => void): () => void;
1537
+ goTo(page: number): void;
1316
1538
  next(): void;
1317
- page: number;
1318
- readonly pages: T[][];
1319
1539
  prev(): void;
1320
- reset(): T[];
1321
- search: Debounced<(str: string) => T[]>;
1322
- sort(fn?: (a: T, b: T) => number): T[];
1323
- [Symbol.iterator](): Generator<T[], void, unknown>;
1540
+ reset(): void;
1541
+ search(query: string, opts?: {
1542
+ immediate?: boolean;
1543
+ }): void;
1544
+ setData?(data: readonly T[]): void;
1545
+ setFilter(filter: F): void;
1546
+ setLimit(n: number): void;
1547
+ setSort(sort?: S): void;
1548
+ batch(mutator: (ctx: {
1549
+ setLimit(n: number): void;
1550
+ setFilter(f: F): void;
1551
+ setSort(s?: S): void;
1552
+ setQuery(q: string): void;
1553
+ setData?(d: readonly T[]): void;
1554
+ goTo(p: number): void;
1555
+ }) => void): void;
1324
1556
  };
1325
1557
 
1558
+ export declare function list<T>(initialData: readonly T[], cfg?: LocalConfig<T>): List<T, Predicate<T>, Sorter<T>>;
1559
+
1560
+ declare type LocalConfig<T> = Readonly<{
1561
+ debounceMs?: number;
1562
+ filterFn?: Predicate<T>;
1563
+ limit?: number;
1564
+ searchFn?: (items: readonly T[], query: string, tone: number) => readonly T[];
1565
+ searchTone?: number;
1566
+ sortFn?: Sorter<T>;
1567
+ }>;
1568
+
1326
1569
  /**
1327
1570
  * Checks if the first argument is less than the second argument.
1328
1571
  *
@@ -1456,6 +1699,18 @@ export declare function merge<T extends Obj[]>(strategy?: MergeStrategy, ...item
1456
1699
 
1457
1700
  declare type MergeStrategy = 'deep' | 'shallow' | 'lastWins' | 'arrayConcat' | 'arrayReplace' | ((target: any, source: any) => any);
1458
1701
 
1702
+ export declare type Meta = Readonly<{
1703
+ end: number;
1704
+ isEmpty: boolean;
1705
+ isFirst: boolean;
1706
+ isLast: boolean;
1707
+ limit: number;
1708
+ page: number;
1709
+ pages: number;
1710
+ start: number;
1711
+ total: number;
1712
+ }>;
1713
+
1459
1714
  /**
1460
1715
  * Finds the minimum item in an array.
1461
1716
  *
@@ -1479,6 +1734,34 @@ declare type MergeStrategy = 'deep' | 'shallow' | 'lastWins' | 'arrayConcat' | '
1479
1734
  */
1480
1735
  export declare function min<T>(array: T[], callback?: (item: T) => string | number | Date): T | undefined;
1481
1736
 
1737
+ /**
1738
+ * Represents a monetary amount with currency.
1739
+ * Amount is stored as bigint (minor units/cents) for precision.
1740
+ */
1741
+ export declare type Money = {
1742
+ readonly amount: bigint;
1743
+ readonly currency: string;
1744
+ };
1745
+
1746
+ /**
1747
+ * Multiplies a number by a scalar with precision handling for financial calculations.
1748
+ * Supports both regular numbers and bigint for exact precision.
1749
+ *
1750
+ * @example
1751
+ * ```ts
1752
+ * multiply(10, 5); // 50
1753
+ * multiply(0.1, 3); // 0.3 (precision-safe)
1754
+ * multiply(100n, 5n); // 500n
1755
+ * ```
1756
+ *
1757
+ * @param a - Number to multiply
1758
+ * @param b - Multiplier
1759
+ * @returns Product of a and b
1760
+ */
1761
+ export declare function multiply(a: number, b: number): number;
1762
+
1763
+ export declare function multiply(a: bigint, b: bigint): bigint;
1764
+
1482
1765
  export declare type Obj = Record<string, any>;
1483
1766
 
1484
1767
  /**
@@ -1504,6 +1787,37 @@ export declare const once: <T extends Fn>(fn: T) => T & {
1504
1787
  reset: () => void;
1505
1788
  };
1506
1789
 
1790
+ /**
1791
+ * Processes an array with an async callback with controlled parallelism.
1792
+ * Similar to Promise.all, but limits how many items are processed concurrently.
1793
+ * Returns an ordered array of results.
1794
+ *
1795
+ * @example
1796
+ * ```ts
1797
+ * // Process 3 items at a time
1798
+ * const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {
1799
+ * await delay(100);
1800
+ * return n * 2;
1801
+ * });
1802
+ * // [2, 4, 6, 8, 10]
1803
+ *
1804
+ * // With abort signal
1805
+ * const controller = new AbortController();
1806
+ * const results = await parallel(2, items, async (item) => {
1807
+ * return processItem(item);
1808
+ * }, controller.signal);
1809
+ * ```
1810
+ *
1811
+ * @param limit - Maximum number of concurrent operations (must be >= 1)
1812
+ * @param array - Array of items to process
1813
+ * @param callback - Async function to process each item
1814
+ * @param signal - Optional AbortSignal to cancel processing
1815
+ * @returns Promise resolving to an ordered array of results
1816
+ * @throws {Error} If limit is less than 1
1817
+ * @throws {DOMException} If aborted via signal
1818
+ */
1819
+ export declare function parallel<T, R>(limit: number, array: T[], callback: (item: T, index: number, array: T[]) => Promise<R>, signal?: AbortSignal): Promise<R[]>;
1820
+
1507
1821
  /**
1508
1822
  * Parses a JSON string and returns the resulting object.
1509
1823
  *
@@ -1527,12 +1841,12 @@ export declare const once: <T extends Fn>(fn: T) => T & {
1527
1841
  */
1528
1842
  export declare function parseJSON<T extends JSONValue>(json: unknown, options?: ParseJSONOptions<T>): T | undefined;
1529
1843
 
1530
- declare interface ParseJSONOptions<T> {
1844
+ declare type ParseJSONOptions<T> = {
1531
1845
  defaultValue?: T;
1532
1846
  reviver?: (key: string, value: any) => any;
1533
1847
  validator?: (value: any) => boolean;
1534
1848
  silent?: boolean;
1535
- }
1849
+ };
1536
1850
 
1537
1851
  /**
1538
1852
  * Converts a string to Pascal case.
@@ -1636,7 +1950,28 @@ export declare function pipe<T extends FnDynamic[]>(...fns: T): PipeReturn<T>;
1636
1950
 
1637
1951
  declare type PipeReturn<T extends FnDynamic[]> = (...args: FirstParameters<T>) => LastReturnType<T> extends Promise<any> ? Promise<Awaited<LastReturnType<T>>> : LastReturnType<T>;
1638
1952
 
1639
- export declare type Predicate<T> = (value: T, index: number, array: T[]) => boolean | boolean[];
1953
+ /**
1954
+ * Creates a promise pool that limits the number of concurrent promises.
1955
+ * Useful for rate limiting API calls or controlling resource usage.
1956
+ *
1957
+ * @example
1958
+ * ```ts
1959
+ * const requestPool = pool(3);
1960
+ *
1961
+ * const results = await Promise.all([
1962
+ * requestPool(() => fetch('/api/1')),
1963
+ * requestPool(() => fetch('/api/2')),
1964
+ * requestPool(() => fetch('/api/3')),
1965
+ * requestPool(() => fetch('/api/4')), // Will wait for one of the above to finish
1966
+ * ]);
1967
+ * ```
1968
+ *
1969
+ * @param limit - Maximum number of concurrent promises
1970
+ * @returns Function that accepts a promise-returning function and executes it when a slot is available
1971
+ */
1972
+ export declare function pool(limit: number): <T>(fn: () => Promise<T>) => Promise<T>;
1973
+
1974
+ export declare type Predicate<T> = (value: T, index: number, array: readonly T[]) => boolean;
1640
1975
 
1641
1976
  /**
1642
1977
  * Creates a Promise that can be aborted using an AbortController.
@@ -1693,6 +2028,95 @@ declare type ProxyOptions<T> = {
1693
2028
  watch?: (keyof T)[];
1694
2029
  };
1695
2030
 
2031
+ /**
2032
+ * Removes all nullable and empty values from strings, arrays, or objects.
2033
+ *
2034
+ * - For strings: Removes leading/trailing whitespace and returns undefined if empty
2035
+ * - For arrays: Recursively removes null, undefined, empty strings, and empty objects/arrays
2036
+ * - For objects: Recursively removes properties with null, undefined, empty strings, and empty objects/arrays
2037
+ *
2038
+ * @example
2039
+ * ```ts
2040
+ * prune(' hello '); // 'hello'
2041
+ * prune(' '); // undefined
2042
+ * prune([1, null, '', 2, undefined, 3]); // [1, 2, 3]
2043
+ * prune({ a: 1, b: null, c: '', d: 2 }); // { a: 1, d: 2 }
2044
+ * prune({ a: { b: null, c: '' }, d: 1 }); // { d: 1 }
2045
+ * ```
2046
+ *
2047
+ * @param value - The value to prune (can be string, array, object, or any other type)
2048
+ * @returns The pruned value, or undefined if the result would be empty
2049
+ */
2050
+ export declare function prune<T>(value: T): T | undefined;
2051
+
2052
+ /**
2053
+ * Creates a promise queue that processes promises sequentially with optional concurrency limit.
2054
+ *
2055
+ * @example
2056
+ * ```ts
2057
+ * const requestQueue = queue({ concurrency: 2 });
2058
+ *
2059
+ * requestQueue.add(() => fetch('/api/1'));
2060
+ * requestQueue.add(() => fetch('/api/2'));
2061
+ * requestQueue.add(() => fetch('/api/3'));
2062
+ *
2063
+ * await requestQueue.onIdle(); // Wait for all tasks to complete
2064
+ * ```
2065
+ *
2066
+ * @param options - Queue configuration
2067
+ * @param options.concurrency - Maximum number of concurrent promises (default: 1)
2068
+ * @returns Queue instance with add, onIdle, and clear methods
2069
+ */
2070
+ export declare function queue(options?: {
2071
+ concurrency?: number;
2072
+ }): {
2073
+ /**
2074
+ * Adds a promise-returning function to the queue
2075
+ */
2076
+ add: <T>(fn: () => Promise<T>) => Promise<T>;
2077
+ /**
2078
+ * Clears all pending tasks from the queue
2079
+ */
2080
+ clear: () => void;
2081
+ /**
2082
+ * Returns a promise that resolves when the queue becomes idle
2083
+ */
2084
+ onIdle: () => Promise<void>;
2085
+ /**
2086
+ * Returns the number of currently active promises
2087
+ */
2088
+ readonly pending: number;
2089
+ /**
2090
+ * Returns the current size of the queue
2091
+ */
2092
+ readonly size: number;
2093
+ };
2094
+
2095
+ /**
2096
+ * Race multiple promises but with a guaranteed minimum delay.
2097
+ * Useful for showing loading states for at least a minimum duration.
2098
+ *
2099
+ * @example
2100
+ * ```ts
2101
+ * // Show loading spinner for at least 500ms
2102
+ * const result = await race(
2103
+ * fetchData(),
2104
+ * 500
2105
+ * );
2106
+ *
2107
+ * // With multiple promises
2108
+ * const result = await race(
2109
+ * [fetch('/api/1'), fetch('/api/2')],
2110
+ * 1000
2111
+ * );
2112
+ * ```
2113
+ *
2114
+ * @param promises - Single promise or array of promises to race
2115
+ * @param minDelay - Minimum delay in milliseconds before resolving
2116
+ * @returns Promise that resolves with the first result after the minimum delay
2117
+ */
2118
+ export declare function race<T>(promises: Promise<T> | Promise<T>[], minDelay: number): Promise<T>;
2119
+
1696
2120
  /**
1697
2121
  * Generates a random integer between two values, inclusive.
1698
2122
  *
@@ -1777,6 +2201,72 @@ export declare namespace reduce {
1777
2201
  var fn: boolean;
1778
2202
  }
1779
2203
 
2204
+ declare type RemoteConfig<T, F, S> = Readonly<{
2205
+ debounceMs?: number;
2206
+ fetch: (q: RemoteQuery<F, S>) => Promise<RemoteResult<T>>;
2207
+ initialFilter?: F;
2208
+ initialSort?: S;
2209
+ limit?: number;
2210
+ }>;
2211
+
2212
+ export declare type RemoteList<T, F, S> = {
2213
+ readonly current: readonly T[];
2214
+ readonly meta: RemoteMeta;
2215
+ subscribe(listener: () => void): () => void;
2216
+ goTo(page: number): Promise<void>;
2217
+ invalidate?(): void;
2218
+ next(): Promise<void>;
2219
+ prev(): Promise<void>;
2220
+ refresh(): Promise<void>;
2221
+ reset(): Promise<void>;
2222
+ search(query: string, opts?: {
2223
+ immediate?: boolean;
2224
+ }): Promise<void>;
2225
+ setFilter(filter: F): Promise<void>;
2226
+ setLimit(n: number): Promise<void>;
2227
+ setSort(sort?: S): Promise<void>;
2228
+ batch(mutator: (ctx: {
2229
+ setLimit(n: number): void;
2230
+ setFilter(f: F): void;
2231
+ setSort(s?: S): void;
2232
+ setQuery(q: string): void;
2233
+ setData?(d: readonly T[]): void;
2234
+ goTo(p: number): void;
2235
+ }) => void): Promise<void>;
2236
+ };
2237
+
2238
+ export declare function remoteList<T, F = Record<string, unknown>, S = {
2239
+ key?: string;
2240
+ dir?: 'asc' | 'desc';
2241
+ }>(cfg: RemoteConfig<T, F, S>): RemoteList<T, F, S>;
2242
+
2243
+ export declare type RemoteMeta = Readonly<{
2244
+ end: number;
2245
+ error: string | null;
2246
+ isEmpty: boolean;
2247
+ isFirst: boolean;
2248
+ isLast: boolean;
2249
+ limit: number;
2250
+ loading: boolean;
2251
+ page: number;
2252
+ pages: number;
2253
+ start: number;
2254
+ total: number;
2255
+ }>;
2256
+
2257
+ declare type RemoteQuery<F, S> = Readonly<{
2258
+ filter?: F;
2259
+ limit: number;
2260
+ page: number;
2261
+ search?: string;
2262
+ sort?: S;
2263
+ }>;
2264
+
2265
+ declare type RemoteResult<T> = Readonly<{
2266
+ items: readonly T[];
2267
+ total: number;
2268
+ }>;
2269
+
1780
2270
  declare type RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;
1781
2271
 
1782
2272
  export declare type Result<C extends FnDynamic> = C extends FnAsync ? Promise<Awaited<ReturnType<C>>> : ReturnType<C>;
@@ -2036,26 +2526,7 @@ export declare const sort: {
2036
2526
  fp: boolean;
2037
2527
  };
2038
2528
 
2039
- /**
2040
- * Sorts an array of objects based on multiple selectors.
2041
- *
2042
- * @example
2043
- * ```ts
2044
- * const data = [
2045
- * { name: 'Alice', age: 30 },
2046
- * { name: 'Bob', age: 25 },
2047
- * { name: 'Charlie', age: 35 },
2048
- * { name: 'Alice', age: 25 },
2049
- * { name: 'Bob', age: 30 },
2050
- * { name: 'Charlie', age: 30 },
2051
- * ].sortBy(data, { name: 'asc', age: 'desc' }); // [ { name: 'Alice', age: 30 }, { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Charlie', age: 30 } ]
2052
- * ```
2053
- *
2054
- * @param array - The array to sort.
2055
- * @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.
2056
- * @returns A new sorted array.
2057
- */
2058
- export declare const sortBy: <T>(array: T[], selectors: Partial<Record<keyof T, "asc" | "desc">>) => T[];
2529
+ export declare type Sorter<T> = (a: T, b: T) => number;
2059
2530
 
2060
2531
  /**
2061
2532
  * Replaces the first element in an array that satisfies the provided predicate function with a new value.
@@ -2079,6 +2550,25 @@ export declare namespace substitute {
2079
2550
  var fn: boolean;
2080
2551
  }
2081
2552
 
2553
+ /**
2554
+ * Subtracts one number from another with precision handling for financial calculations.
2555
+ * Supports both regular numbers and bigint for exact precision.
2556
+ *
2557
+ * @example
2558
+ * ```ts
2559
+ * subtract(20, 10); // 10
2560
+ * subtract(0.3, 0.1); // 0.2 (precision-safe)
2561
+ * subtract(300n, 100n); // 200n
2562
+ * ```
2563
+ *
2564
+ * @param a - Number to subtract from
2565
+ * @param b - Number to subtract
2566
+ * @returns Difference of a and b
2567
+ */
2568
+ export declare function subtract(a: number, b: number): number;
2569
+
2570
+ export declare function subtract(a: bigint, b: bigint): bigint;
2571
+
2082
2572
  /**
2083
2573
  * Sum numbers in an array or numbers mapped by a callback function.
2084
2574
  *
@@ -2272,6 +2762,40 @@ export declare function uuid(): string;
2272
2762
  */
2273
2763
  export declare function values<T extends Obj, K extends keyof T>(item: T): T[K][];
2274
2764
 
2765
+ /**
2766
+ * Waits for a condition to become true by polling.
2767
+ * Useful for waiting for DOM elements, API states, or other conditions.
2768
+ *
2769
+ * @example
2770
+ * ```ts
2771
+ * // Wait for an element to appear
2772
+ * await waitFor(() => document.querySelector('#myElement') !== null);
2773
+ *
2774
+ * // Wait for API to be ready
2775
+ * await waitFor(
2776
+ * async () => {
2777
+ * const res = await fetch('/api/health');
2778
+ * return res.ok;
2779
+ * },
2780
+ * { timeout: 30000, interval: 1000 }
2781
+ * );
2782
+ * ```
2783
+ *
2784
+ * @param condition - Function that returns true when condition is met
2785
+ * @param options - Configuration options
2786
+ * @param options.timeout - Maximum time to wait in ms (default: 5000)
2787
+ * @param options.interval - Polling interval in ms (default: 100)
2788
+ * @param options.signal - AbortSignal to cancel waiting
2789
+ * @returns Promise that resolves when condition becomes true
2790
+ * @throws {Error} If timeout is reached
2791
+ * @throws {DOMException} If aborted via signal
2792
+ */
2793
+ export declare function waitFor(condition: () => boolean | Promise<boolean>, options?: {
2794
+ timeout?: number;
2795
+ interval?: number;
2796
+ signal?: AbortSignal;
2797
+ }): Promise<void>;
2798
+
2275
2799
  /**
2276
2800
  * Creates a function that runs the provided callback in a web worker with specified dependencies.
2277
2801
  *