@vielzeug/toolkit 1.0.13 → 1.0.14
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.
- package/dist/array/{sortBy.cjs → arrange.cjs} +2 -2
- package/dist/array/arrange.cjs.map +1 -0
- package/dist/array/arrange.js +6 -0
- package/dist/array/arrange.js.map +1 -0
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/list.cjs +1 -1
- package/dist/array/list.cjs.map +1 -1
- package/dist/array/list.js +86 -53
- package/dist/array/list.js.map +1 -1
- package/dist/array/remoteList.cjs +2 -0
- package/dist/array/remoteList.cjs.map +1 -0
- package/dist/array/remoteList.js +123 -0
- package/dist/array/remoteList.js.map +1 -0
- package/dist/date/expires.cjs.map +1 -1
- package/dist/date/expires.js.map +1 -1
- package/dist/date/interval.cjs.map +1 -1
- package/dist/date/interval.js.map +1 -1
- package/dist/date/timeDiff.cjs.map +1 -1
- package/dist/date/timeDiff.js.map +1 -1
- package/dist/function/memo.cjs.map +1 -1
- package/dist/function/memo.js.map +1 -1
- package/dist/function/parallel.cjs +2 -0
- package/dist/function/parallel.cjs.map +1 -0
- package/dist/function/parallel.js +28 -0
- package/dist/function/parallel.js.map +1 -0
- package/dist/function/proxy.cjs.map +1 -1
- package/dist/function/proxy.js.map +1 -1
- package/dist/function/prune.cjs +2 -0
- package/dist/function/prune.cjs.map +1 -0
- package/dist/function/prune.js +30 -0
- package/dist/function/prune.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +400 -51
- package/dist/index.js +218 -194
- package/dist/index.js.map +1 -1
- package/dist/math/abs.cjs +2 -0
- package/dist/math/abs.cjs.map +1 -0
- package/dist/math/abs.js +7 -0
- package/dist/math/abs.js.map +1 -0
- package/dist/math/add.cjs +2 -0
- package/dist/math/add.cjs.map +1 -0
- package/dist/math/add.js +9 -0
- package/dist/math/add.js.map +1 -0
- package/dist/math/allocate.cjs +2 -0
- package/dist/math/allocate.cjs.map +1 -0
- package/dist/math/allocate.js +29 -0
- package/dist/math/allocate.js.map +1 -0
- package/dist/math/distribute.cjs +2 -0
- package/dist/math/distribute.cjs.map +1 -0
- package/dist/math/distribute.js +18 -0
- package/dist/math/distribute.js.map +1 -0
- package/dist/math/divide.cjs +2 -0
- package/dist/math/divide.cjs.map +1 -0
- package/dist/math/divide.js +11 -0
- package/dist/math/divide.js.map +1 -0
- package/dist/math/multiply.cjs +2 -0
- package/dist/math/multiply.cjs.map +1 -0
- package/dist/math/multiply.js +9 -0
- package/dist/math/multiply.js.map +1 -0
- package/dist/math/subtract.cjs +2 -0
- package/dist/math/subtract.cjs.map +1 -0
- package/dist/math/subtract.js +9 -0
- package/dist/math/subtract.js.map +1 -0
- package/dist/money/currency.cjs +2 -0
- package/dist/money/currency.cjs.map +1 -0
- package/dist/money/currency.js +49 -0
- package/dist/money/currency.js.map +1 -0
- package/dist/money/exchange.cjs +2 -0
- package/dist/money/exchange.cjs.map +1 -0
- package/dist/money/exchange.js +13 -0
- package/dist/money/exchange.js.map +1 -0
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.js.map +1 -1
- package/dist/object/parseJSON.cjs.map +1 -1
- package/dist/object/parseJSON.js.map +1 -1
- package/dist/object/path.cjs.map +1 -1
- package/dist/object/path.js.map +1 -1
- package/package.json +1 -1
- package/dist/array/sortBy.cjs.map +0 -1
- package/dist/array/sortBy.js +0 -6
- package/dist/array/sortBy.js.map +0 -1
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.
|
|
@@ -361,12 +444,6 @@ export declare function compose<T extends FnDynamic[]>(...fns: T): ComposeReturn
|
|
|
361
444
|
|
|
362
445
|
declare type ComposeReturn<T extends FnDynamic[]> = (...args: LastParameters<T>) => FirstReturnType<T> extends Promise<any> ? Promise<Awaited<FirstReturnType<T>>> : FirstReturnType<T>;
|
|
363
446
|
|
|
364
|
-
declare type Config<T> = {
|
|
365
|
-
filterFn?: Predicate<T>;
|
|
366
|
-
limit?: number;
|
|
367
|
-
sortFn?: (a: T, b: T) => number;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
447
|
/**
|
|
371
448
|
* Checks if a value is present in an array.
|
|
372
449
|
*
|
|
@@ -390,6 +467,36 @@ export declare namespace contains {
|
|
|
390
467
|
var fp: boolean;
|
|
391
468
|
}
|
|
392
469
|
|
|
470
|
+
/**
|
|
471
|
+
* Formats a monetary amount as a currency string with proper locale and symbol.
|
|
472
|
+
* Handles decimal places automatically based on currency.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* const money = { amount: 123456n, currency: 'USD' };
|
|
477
|
+
*
|
|
478
|
+
* currency(money); // '$1,234.56' (default en-US)
|
|
479
|
+
* currency(money, { locale: 'de-DE' }); // '1.234,56 $'
|
|
480
|
+
* currency(money, { style: 'code' }); // 'USD 1,234.56'
|
|
481
|
+
* currency(money, { style: 'name' }); // '1,234.56 US dollars'
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @param money - Money object to format
|
|
485
|
+
* @param options - Formatting options
|
|
486
|
+
* @returns Formatted currency string
|
|
487
|
+
*/
|
|
488
|
+
export declare function currency(money: Money, options?: CurrencyFormatOptions): string;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Options for currency formatting.
|
|
492
|
+
*/
|
|
493
|
+
export declare type CurrencyFormatOptions = {
|
|
494
|
+
locale?: string;
|
|
495
|
+
style?: 'symbol' | 'code' | 'name';
|
|
496
|
+
minimumFractionDigits?: number;
|
|
497
|
+
maximumFractionDigits?: number;
|
|
498
|
+
};
|
|
499
|
+
|
|
393
500
|
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
501
|
|
|
395
502
|
export declare function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;
|
|
@@ -447,6 +554,51 @@ export declare function delay<T extends Fn>(fn: T, delay?: number): Promise<any>
|
|
|
447
554
|
*/
|
|
448
555
|
export declare function diff<T extends Obj>(curr?: T, prev?: T, compareFn?: (a: unknown, b: unknown) => boolean): Partial<T>;
|
|
449
556
|
|
|
557
|
+
/**
|
|
558
|
+
* Distributes an amount evenly among N parties.
|
|
559
|
+
* Handles rounding to ensure the sum equals the original amount exactly.
|
|
560
|
+
* Useful for splitting bills, costs, or payments equally.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```ts
|
|
564
|
+
* // Split $100 among 3 people
|
|
565
|
+
* distribute(100, 3);
|
|
566
|
+
* // [34, 33, 33] - sum is exactly 100
|
|
567
|
+
*
|
|
568
|
+
* // Split with bigint (e.g., cents)
|
|
569
|
+
* distribute(10000n, 3);
|
|
570
|
+
* // [3334n, 3333n, 3333n] - sum is exactly 10000n
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
573
|
+
* @param amount - Total amount to distribute
|
|
574
|
+
* @param parts - Number of parts to divide into
|
|
575
|
+
* @returns Array of distributed amounts (a sum equals original amount)
|
|
576
|
+
* @throws {Error} If parts are less than 1
|
|
577
|
+
*/
|
|
578
|
+
export declare function distribute(amount: number, parts: number): number[];
|
|
579
|
+
|
|
580
|
+
export declare function distribute(amount: bigint, parts: number): bigint[];
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Divides a number by a divisor with precision handling for financial calculations.
|
|
584
|
+
* Supports both regular numbers and bigint for exact precision.
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* ```ts
|
|
588
|
+
* divide(20, 5); // 4
|
|
589
|
+
* divide(0.6, 3); // 0.2 (precision-safe)
|
|
590
|
+
* divide(500n, 5n); // 100n
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* @param a - Number to divide (dividend)
|
|
594
|
+
* @param b - Divisor
|
|
595
|
+
* @returns Quotient of a divided by b
|
|
596
|
+
* @throws {Error} If divisor is zero
|
|
597
|
+
*/
|
|
598
|
+
export declare function divide(a: number, b: number): number;
|
|
599
|
+
|
|
600
|
+
export declare function divide(a: bigint, b: bigint): bigint;
|
|
601
|
+
|
|
450
602
|
/**
|
|
451
603
|
* “Draw” a random item from an array.
|
|
452
604
|
*
|
|
@@ -505,6 +657,35 @@ export declare namespace every {
|
|
|
505
657
|
var fp: boolean;
|
|
506
658
|
}
|
|
507
659
|
|
|
660
|
+
/**
|
|
661
|
+
* Converts money from one currency to another using the provided exchange rate.
|
|
662
|
+
* Maintains precision by using bigint arithmetic.
|
|
663
|
+
*
|
|
664
|
+
* @example
|
|
665
|
+
* ```ts
|
|
666
|
+
* const usd = { amount: 100000n, currency: 'USD' }; // $1,000.00
|
|
667
|
+
* const rate = { from: 'USD', to: 'EUR', rate: 0.85 };
|
|
668
|
+
*
|
|
669
|
+
* exchange(usd, rate);
|
|
670
|
+
* // { amount: 85000n, currency: 'EUR' } // €850.00
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* @param money - Money to convert
|
|
674
|
+
* @param rate - Exchange rate information
|
|
675
|
+
* @returns Converted money in target currency
|
|
676
|
+
* @throws {Error} If source currency doesn't match rate.from
|
|
677
|
+
*/
|
|
678
|
+
export declare function exchange(money: Money, rate: ExchangeRate): Money;
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Exchange rate for currency conversion.
|
|
682
|
+
*/
|
|
683
|
+
export declare type ExchangeRate = {
|
|
684
|
+
from: string;
|
|
685
|
+
to: string;
|
|
686
|
+
rate: number;
|
|
687
|
+
};
|
|
688
|
+
|
|
508
689
|
export declare type Expires = 'EXPIRED' | 'SOON' | 'LATER' | 'NEVER' | 'UNKNOWN';
|
|
509
690
|
|
|
510
691
|
/**
|
|
@@ -1297,32 +1478,42 @@ declare type LastReturnType<T> = T extends [...any, infer Last extends FnDynamic
|
|
|
1297
1478
|
*/
|
|
1298
1479
|
export declare function le(a: unknown, b: unknown): boolean;
|
|
1299
1480
|
|
|
1300
|
-
export declare
|
|
1301
|
-
readonly current: T[];
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
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
|
-
};
|
|
1481
|
+
export declare type List<T, F, S> = {
|
|
1482
|
+
readonly current: readonly T[];
|
|
1483
|
+
readonly meta: Meta;
|
|
1484
|
+
subscribe(listener: () => void): () => void;
|
|
1485
|
+
goTo(page: number): void;
|
|
1316
1486
|
next(): void;
|
|
1317
|
-
page: number;
|
|
1318
|
-
readonly pages: T[][];
|
|
1319
1487
|
prev(): void;
|
|
1320
|
-
reset():
|
|
1321
|
-
search
|
|
1322
|
-
|
|
1323
|
-
|
|
1488
|
+
reset(): void;
|
|
1489
|
+
search(query: string, opts?: {
|
|
1490
|
+
immediate?: boolean;
|
|
1491
|
+
}): void;
|
|
1492
|
+
setData?(data: readonly T[]): void;
|
|
1493
|
+
setFilter(filter: F): void;
|
|
1494
|
+
setLimit(n: number): void;
|
|
1495
|
+
setSort(sort?: S): void;
|
|
1496
|
+
batch(mutator: (ctx: {
|
|
1497
|
+
setLimit(n: number): void;
|
|
1498
|
+
setFilter(f: F): void;
|
|
1499
|
+
setSort(s?: S): void;
|
|
1500
|
+
setQuery(q: string): void;
|
|
1501
|
+
setData?(d: readonly T[]): void;
|
|
1502
|
+
goTo(p: number): void;
|
|
1503
|
+
}) => void): void;
|
|
1324
1504
|
};
|
|
1325
1505
|
|
|
1506
|
+
export declare function list<T>(initialData: readonly T[], cfg?: LocalConfig<T>): List<T, Predicate<T>, Sorter<T>>;
|
|
1507
|
+
|
|
1508
|
+
declare type LocalConfig<T> = Readonly<{
|
|
1509
|
+
debounceMs?: number;
|
|
1510
|
+
filterFn?: Predicate<T>;
|
|
1511
|
+
limit?: number;
|
|
1512
|
+
searchFn?: (items: readonly T[], query: string, tone: number) => readonly T[];
|
|
1513
|
+
searchTone?: number;
|
|
1514
|
+
sortFn?: Sorter<T>;
|
|
1515
|
+
}>;
|
|
1516
|
+
|
|
1326
1517
|
/**
|
|
1327
1518
|
* Checks if the first argument is less than the second argument.
|
|
1328
1519
|
*
|
|
@@ -1456,6 +1647,18 @@ export declare function merge<T extends Obj[]>(strategy?: MergeStrategy, ...item
|
|
|
1456
1647
|
|
|
1457
1648
|
declare type MergeStrategy = 'deep' | 'shallow' | 'lastWins' | 'arrayConcat' | 'arrayReplace' | ((target: any, source: any) => any);
|
|
1458
1649
|
|
|
1650
|
+
export declare type Meta = Readonly<{
|
|
1651
|
+
end: number;
|
|
1652
|
+
isEmpty: boolean;
|
|
1653
|
+
isFirst: boolean;
|
|
1654
|
+
isLast: boolean;
|
|
1655
|
+
limit: number;
|
|
1656
|
+
page: number;
|
|
1657
|
+
pages: number;
|
|
1658
|
+
start: number;
|
|
1659
|
+
total: number;
|
|
1660
|
+
}>;
|
|
1661
|
+
|
|
1459
1662
|
/**
|
|
1460
1663
|
* Finds the minimum item in an array.
|
|
1461
1664
|
*
|
|
@@ -1479,6 +1682,34 @@ declare type MergeStrategy = 'deep' | 'shallow' | 'lastWins' | 'arrayConcat' | '
|
|
|
1479
1682
|
*/
|
|
1480
1683
|
export declare function min<T>(array: T[], callback?: (item: T) => string | number | Date): T | undefined;
|
|
1481
1684
|
|
|
1685
|
+
/**
|
|
1686
|
+
* Represents a monetary amount with currency.
|
|
1687
|
+
* Amount is stored as bigint (minor units/cents) for precision.
|
|
1688
|
+
*/
|
|
1689
|
+
export declare type Money = {
|
|
1690
|
+
readonly amount: bigint;
|
|
1691
|
+
readonly currency: string;
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
/**
|
|
1695
|
+
* Multiplies a number by a scalar with precision handling for financial calculations.
|
|
1696
|
+
* Supports both regular numbers and bigint for exact precision.
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* ```ts
|
|
1700
|
+
* multiply(10, 5); // 50
|
|
1701
|
+
* multiply(0.1, 3); // 0.3 (precision-safe)
|
|
1702
|
+
* multiply(100n, 5n); // 500n
|
|
1703
|
+
* ```
|
|
1704
|
+
*
|
|
1705
|
+
* @param a - Number to multiply
|
|
1706
|
+
* @param b - Multiplier
|
|
1707
|
+
* @returns Product of a and b
|
|
1708
|
+
*/
|
|
1709
|
+
export declare function multiply(a: number, b: number): number;
|
|
1710
|
+
|
|
1711
|
+
export declare function multiply(a: bigint, b: bigint): bigint;
|
|
1712
|
+
|
|
1482
1713
|
export declare type Obj = Record<string, any>;
|
|
1483
1714
|
|
|
1484
1715
|
/**
|
|
@@ -1504,6 +1735,37 @@ export declare const once: <T extends Fn>(fn: T) => T & {
|
|
|
1504
1735
|
reset: () => void;
|
|
1505
1736
|
};
|
|
1506
1737
|
|
|
1738
|
+
/**
|
|
1739
|
+
* Processes an array with an async callback with controlled parallelism.
|
|
1740
|
+
* Similar to Promise.all, but limits how many items are processed concurrently.
|
|
1741
|
+
* Returns an ordered array of results.
|
|
1742
|
+
*
|
|
1743
|
+
* @example
|
|
1744
|
+
* ```ts
|
|
1745
|
+
* // Process 3 items at a time
|
|
1746
|
+
* const results = await parallel(3, [1, 2, 3, 4, 5], async (n) => {
|
|
1747
|
+
* await delay(100);
|
|
1748
|
+
* return n * 2;
|
|
1749
|
+
* });
|
|
1750
|
+
* // [2, 4, 6, 8, 10]
|
|
1751
|
+
*
|
|
1752
|
+
* // With abort signal
|
|
1753
|
+
* const controller = new AbortController();
|
|
1754
|
+
* const results = await parallel(2, items, async (item) => {
|
|
1755
|
+
* return processItem(item);
|
|
1756
|
+
* }, controller.signal);
|
|
1757
|
+
* ```
|
|
1758
|
+
*
|
|
1759
|
+
* @param limit - Maximum number of concurrent operations (must be >= 1)
|
|
1760
|
+
* @param array - Array of items to process
|
|
1761
|
+
* @param callback - Async function to process each item
|
|
1762
|
+
* @param signal - Optional AbortSignal to cancel processing
|
|
1763
|
+
* @returns Promise resolving to an ordered array of results
|
|
1764
|
+
* @throws {Error} If limit is less than 1
|
|
1765
|
+
* @throws {DOMException} If aborted via signal
|
|
1766
|
+
*/
|
|
1767
|
+
export declare function parallel<T, R>(limit: number, array: T[], callback: (item: T, index: number, array: T[]) => Promise<R>, signal?: AbortSignal): Promise<R[]>;
|
|
1768
|
+
|
|
1507
1769
|
/**
|
|
1508
1770
|
* Parses a JSON string and returns the resulting object.
|
|
1509
1771
|
*
|
|
@@ -1527,12 +1789,12 @@ export declare const once: <T extends Fn>(fn: T) => T & {
|
|
|
1527
1789
|
*/
|
|
1528
1790
|
export declare function parseJSON<T extends JSONValue>(json: unknown, options?: ParseJSONOptions<T>): T | undefined;
|
|
1529
1791
|
|
|
1530
|
-
declare
|
|
1792
|
+
declare type ParseJSONOptions<T> = {
|
|
1531
1793
|
defaultValue?: T;
|
|
1532
1794
|
reviver?: (key: string, value: any) => any;
|
|
1533
1795
|
validator?: (value: any) => boolean;
|
|
1534
1796
|
silent?: boolean;
|
|
1535
|
-
}
|
|
1797
|
+
};
|
|
1536
1798
|
|
|
1537
1799
|
/**
|
|
1538
1800
|
* Converts a string to Pascal case.
|
|
@@ -1636,7 +1898,7 @@ export declare function pipe<T extends FnDynamic[]>(...fns: T): PipeReturn<T>;
|
|
|
1636
1898
|
|
|
1637
1899
|
declare type PipeReturn<T extends FnDynamic[]> = (...args: FirstParameters<T>) => LastReturnType<T> extends Promise<any> ? Promise<Awaited<LastReturnType<T>>> : LastReturnType<T>;
|
|
1638
1900
|
|
|
1639
|
-
export declare type Predicate<T> = (value: T, index: number, array: T[]) => boolean
|
|
1901
|
+
export declare type Predicate<T> = (value: T, index: number, array: readonly T[]) => boolean;
|
|
1640
1902
|
|
|
1641
1903
|
/**
|
|
1642
1904
|
* Creates a Promise that can be aborted using an AbortController.
|
|
@@ -1693,6 +1955,27 @@ declare type ProxyOptions<T> = {
|
|
|
1693
1955
|
watch?: (keyof T)[];
|
|
1694
1956
|
};
|
|
1695
1957
|
|
|
1958
|
+
/**
|
|
1959
|
+
* Removes all nullable and empty values from strings, arrays, or objects.
|
|
1960
|
+
*
|
|
1961
|
+
* - For strings: Removes leading/trailing whitespace and returns undefined if empty
|
|
1962
|
+
* - For arrays: Recursively removes null, undefined, empty strings, and empty objects/arrays
|
|
1963
|
+
* - For objects: Recursively removes properties with null, undefined, empty strings, and empty objects/arrays
|
|
1964
|
+
*
|
|
1965
|
+
* @example
|
|
1966
|
+
* ```ts
|
|
1967
|
+
* prune(' hello '); // 'hello'
|
|
1968
|
+
* prune(' '); // undefined
|
|
1969
|
+
* prune([1, null, '', 2, undefined, 3]); // [1, 2, 3]
|
|
1970
|
+
* prune({ a: 1, b: null, c: '', d: 2 }); // { a: 1, d: 2 }
|
|
1971
|
+
* prune({ a: { b: null, c: '' }, d: 1 }); // { d: 1 }
|
|
1972
|
+
* ```
|
|
1973
|
+
*
|
|
1974
|
+
* @param value - The value to prune (can be string, array, object, or any other type)
|
|
1975
|
+
* @returns The pruned value, or undefined if the result would be empty
|
|
1976
|
+
*/
|
|
1977
|
+
export declare function prune<T>(value: T): T | undefined;
|
|
1978
|
+
|
|
1696
1979
|
/**
|
|
1697
1980
|
* Generates a random integer between two values, inclusive.
|
|
1698
1981
|
*
|
|
@@ -1777,6 +2060,72 @@ export declare namespace reduce {
|
|
|
1777
2060
|
var fn: boolean;
|
|
1778
2061
|
}
|
|
1779
2062
|
|
|
2063
|
+
declare type RemoteConfig<T, F, S> = Readonly<{
|
|
2064
|
+
debounceMs?: number;
|
|
2065
|
+
fetch: (q: RemoteQuery<F, S>) => Promise<RemoteResult<T>>;
|
|
2066
|
+
initialFilter?: F;
|
|
2067
|
+
initialSort?: S;
|
|
2068
|
+
limit?: number;
|
|
2069
|
+
}>;
|
|
2070
|
+
|
|
2071
|
+
export declare type RemoteList<T, F, S> = {
|
|
2072
|
+
readonly current: readonly T[];
|
|
2073
|
+
readonly meta: RemoteMeta;
|
|
2074
|
+
subscribe(listener: () => void): () => void;
|
|
2075
|
+
goTo(page: number): Promise<void>;
|
|
2076
|
+
invalidate?(): void;
|
|
2077
|
+
next(): Promise<void>;
|
|
2078
|
+
prev(): Promise<void>;
|
|
2079
|
+
refresh(): Promise<void>;
|
|
2080
|
+
reset(): Promise<void>;
|
|
2081
|
+
search(query: string, opts?: {
|
|
2082
|
+
immediate?: boolean;
|
|
2083
|
+
}): Promise<void>;
|
|
2084
|
+
setFilter(filter: F): Promise<void>;
|
|
2085
|
+
setLimit(n: number): Promise<void>;
|
|
2086
|
+
setSort(sort?: S): Promise<void>;
|
|
2087
|
+
batch(mutator: (ctx: {
|
|
2088
|
+
setLimit(n: number): void;
|
|
2089
|
+
setFilter(f: F): void;
|
|
2090
|
+
setSort(s?: S): void;
|
|
2091
|
+
setQuery(q: string): void;
|
|
2092
|
+
setData?(d: readonly T[]): void;
|
|
2093
|
+
goTo(p: number): void;
|
|
2094
|
+
}) => void): Promise<void>;
|
|
2095
|
+
};
|
|
2096
|
+
|
|
2097
|
+
export declare function remoteList<T, F = Record<string, unknown>, S = {
|
|
2098
|
+
key?: string;
|
|
2099
|
+
dir?: 'asc' | 'desc';
|
|
2100
|
+
}>(cfg: RemoteConfig<T, F, S>): RemoteList<T, F, S>;
|
|
2101
|
+
|
|
2102
|
+
export declare type RemoteMeta = Readonly<{
|
|
2103
|
+
end: number;
|
|
2104
|
+
error: string | null;
|
|
2105
|
+
isEmpty: boolean;
|
|
2106
|
+
isFirst: boolean;
|
|
2107
|
+
isLast: boolean;
|
|
2108
|
+
limit: number;
|
|
2109
|
+
loading: boolean;
|
|
2110
|
+
page: number;
|
|
2111
|
+
pages: number;
|
|
2112
|
+
start: number;
|
|
2113
|
+
total: number;
|
|
2114
|
+
}>;
|
|
2115
|
+
|
|
2116
|
+
declare type RemoteQuery<F, S> = Readonly<{
|
|
2117
|
+
filter?: F;
|
|
2118
|
+
limit: number;
|
|
2119
|
+
page: number;
|
|
2120
|
+
search?: string;
|
|
2121
|
+
sort?: S;
|
|
2122
|
+
}>;
|
|
2123
|
+
|
|
2124
|
+
declare type RemoteResult<T> = Readonly<{
|
|
2125
|
+
items: readonly T[];
|
|
2126
|
+
total: number;
|
|
2127
|
+
}>;
|
|
2128
|
+
|
|
1780
2129
|
declare type RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;
|
|
1781
2130
|
|
|
1782
2131
|
export declare type Result<C extends FnDynamic> = C extends FnAsync ? Promise<Awaited<ReturnType<C>>> : ReturnType<C>;
|
|
@@ -2036,26 +2385,7 @@ export declare const sort: {
|
|
|
2036
2385
|
fp: boolean;
|
|
2037
2386
|
};
|
|
2038
2387
|
|
|
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[];
|
|
2388
|
+
export declare type Sorter<T> = (a: T, b: T) => number;
|
|
2059
2389
|
|
|
2060
2390
|
/**
|
|
2061
2391
|
* Replaces the first element in an array that satisfies the provided predicate function with a new value.
|
|
@@ -2079,6 +2409,25 @@ export declare namespace substitute {
|
|
|
2079
2409
|
var fn: boolean;
|
|
2080
2410
|
}
|
|
2081
2411
|
|
|
2412
|
+
/**
|
|
2413
|
+
* Subtracts one number from another with precision handling for financial calculations.
|
|
2414
|
+
* Supports both regular numbers and bigint for exact precision.
|
|
2415
|
+
*
|
|
2416
|
+
* @example
|
|
2417
|
+
* ```ts
|
|
2418
|
+
* subtract(20, 10); // 10
|
|
2419
|
+
* subtract(0.3, 0.1); // 0.2 (precision-safe)
|
|
2420
|
+
* subtract(300n, 100n); // 200n
|
|
2421
|
+
* ```
|
|
2422
|
+
*
|
|
2423
|
+
* @param a - Number to subtract from
|
|
2424
|
+
* @param b - Number to subtract
|
|
2425
|
+
* @returns Difference of a and b
|
|
2426
|
+
*/
|
|
2427
|
+
export declare function subtract(a: number, b: number): number;
|
|
2428
|
+
|
|
2429
|
+
export declare function subtract(a: bigint, b: bigint): bigint;
|
|
2430
|
+
|
|
2082
2431
|
/**
|
|
2083
2432
|
* Sum numbers in an array or numbers mapped by a callback function.
|
|
2084
2433
|
*
|