@vielzeug/toolkit 1.0.12 → 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 +1 -1
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.js +15 -12
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/group.cjs +1 -1
- package/dist/array/group.cjs.map +1 -1
- package/dist/array/group.js +9 -9
- package/dist/array/group.js.map +1 -1
- package/dist/array/list.cjs +1 -1
- package/dist/array/list.cjs.map +1 -1
- package/dist/array/list.js +87 -50
- package/dist/array/list.js.map +1 -1
- package/dist/array/pick.cjs.map +1 -1
- package/dist/array/pick.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 +1 -1
- package/dist/date/timeDiff.cjs.map +1 -1
- package/dist/date/timeDiff.js +10 -12
- package/dist/date/timeDiff.js.map +1 -1
- package/dist/function/curry.cjs +1 -1
- package/dist/function/curry.cjs.map +1 -1
- package/dist/function/curry.js +3 -3
- package/dist/function/curry.js.map +1 -1
- package/dist/function/debounce.cjs +1 -1
- package/dist/function/debounce.cjs.map +1 -1
- package/dist/function/debounce.js +22 -5
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/memo.cjs +1 -1
- package/dist/function/memo.cjs.map +1 -1
- package/dist/function/memo.js +14 -13
- 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/function/retry.cjs +1 -1
- package/dist/function/retry.cjs.map +1 -1
- package/dist/function/retry.js +13 -13
- package/dist/function/retry.js.map +1 -1
- package/dist/function/sleep.cjs +1 -1
- package/dist/function/sleep.cjs.map +1 -1
- package/dist/function/sleep.js +8 -3
- package/dist/function/sleep.js.map +1 -1
- package/dist/function/throttle.cjs +1 -1
- package/dist/function/throttle.cjs.map +1 -1
- package/dist/function/throttle.js +33 -6
- package/dist/function/throttle.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +455 -95
- 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/average.cjs +1 -1
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.js +18 -12
- package/dist/math/average.js.map +1 -1
- 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/median.cjs.map +1 -1
- package/dist/math/median.js.map +1 -1
- 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/range.cjs +1 -1
- package/dist/math/range.cjs.map +1 -1
- package/dist/math/range.js +14 -6
- package/dist/math/range.js.map +1 -1
- 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/math/sum.cjs +1 -1
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.js +11 -18
- package/dist/math/sum.js.map +1 -1
- 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/clone.cjs +1 -1
- package/dist/object/clone.cjs.map +1 -1
- package/dist/object/clone.js +13 -3
- package/dist/object/clone.js.map +1 -1
- package/dist/object/merge.cjs +1 -1
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.js +11 -15
- 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/dist/object/seek.cjs +1 -1
- package/dist/object/seek.cjs.map +1 -1
- package/dist/object/seek.js +8 -6
- package/dist/object/seek.js.map +1 -1
- package/dist/random/uuid.cjs +1 -1
- package/dist/random/uuid.cjs.map +1 -1
- package/dist/random/uuid.js +6 -3
- package/dist/random/uuid.js.map +1 -1
- package/dist/string/camelCase.cjs +1 -1
- package/dist/string/camelCase.cjs.map +1 -1
- package/dist/string/camelCase.js +3 -3
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/similarity.cjs +1 -1
- package/dist/string/similarity.cjs.map +1 -1
- package/dist/string/similarity.js +24 -21
- package/dist/string/similarity.js.map +1 -1
- package/dist/string/truncate.cjs +1 -1
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.js +14 -5
- package/dist/string/truncate.js.map +1 -1
- package/dist/typed/is.cjs +1 -1
- package/dist/typed/is.cjs.map +1 -1
- package/dist/typed/is.js +30 -31
- package/dist/typed/is.js.map +1 -1
- package/dist/typed/isEmpty.cjs +1 -1
- package/dist/typed/isEmpty.cjs.map +1 -1
- package/dist/typed/isEmpty.js +6 -6
- package/dist/typed/isEmpty.js.map +1 -1
- package/dist/typed/isEqual.cjs +1 -1
- package/dist/typed/isEqual.cjs.map +1 -1
- package/dist/typed/isEqual.js +22 -17
- package/dist/typed/isEqual.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.
|
|
@@ -264,6 +347,8 @@ export declare function clamp(n: number, min: number, max: number): number;
|
|
|
264
347
|
* @param item - The data to clone.
|
|
265
348
|
*
|
|
266
349
|
* @returns A deep copy of the provided data.
|
|
350
|
+
*
|
|
351
|
+
* @throws {Error} If the item cannot be cloned.
|
|
267
352
|
*/
|
|
268
353
|
export declare function clone<T>(item: T): T;
|
|
269
354
|
|
|
@@ -359,12 +444,6 @@ export declare function compose<T extends FnDynamic[]>(...fns: T): ComposeReturn
|
|
|
359
444
|
|
|
360
445
|
declare type ComposeReturn<T extends FnDynamic[]> = (...args: LastParameters<T>) => FirstReturnType<T> extends Promise<any> ? Promise<Awaited<FirstReturnType<T>>> : FirstReturnType<T>;
|
|
361
446
|
|
|
362
|
-
declare type Config<T> = {
|
|
363
|
-
filterFn?: Predicate<T>;
|
|
364
|
-
limit?: number;
|
|
365
|
-
sortFn?: (a: T, b: T) => number;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
447
|
/**
|
|
369
448
|
* Checks if a value is present in an array.
|
|
370
449
|
*
|
|
@@ -388,42 +467,53 @@ export declare namespace contains {
|
|
|
388
467
|
var fp: boolean;
|
|
389
468
|
}
|
|
390
469
|
|
|
391
|
-
declare type CurriedFunction<Params extends any[], R> = Params extends [infer A, ...infer Rest] ? (arg: A) => CurriedFunction<Rest, R> : R;
|
|
392
|
-
|
|
393
470
|
/**
|
|
394
|
-
*
|
|
471
|
+
* Formats a monetary amount as a currency string with proper locale and symbol.
|
|
472
|
+
* Handles decimal places automatically based on currency.
|
|
395
473
|
*
|
|
396
474
|
* @example
|
|
397
475
|
* ```ts
|
|
398
|
-
* const
|
|
399
|
-
* const curriedAdd = curry(add);
|
|
400
|
-
* curriedAdd(1)(2) // 3;
|
|
401
|
-
* ```
|
|
476
|
+
* const money = { amount: 123456n, currency: 'USD' };
|
|
402
477
|
*
|
|
403
|
-
*
|
|
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
|
+
* ```
|
|
404
483
|
*
|
|
405
|
-
* @
|
|
484
|
+
* @param money - Money object to format
|
|
485
|
+
* @param options - Formatting options
|
|
486
|
+
* @returns Formatted currency string
|
|
406
487
|
*/
|
|
407
|
-
export declare
|
|
488
|
+
export declare function currency(money: Money, options?: CurrencyFormatOptions): string;
|
|
408
489
|
|
|
409
490
|
/**
|
|
410
|
-
*
|
|
411
|
-
* a specified wait time has elapsed since the last invocation.
|
|
412
|
-
*
|
|
413
|
-
* @example
|
|
414
|
-
* ```ts
|
|
415
|
-
* const debouncedLog = debounce(console.log, 1000);
|
|
416
|
-
*
|
|
417
|
-
* debouncedLog('Hello'); // Will log after 1 second if not called again
|
|
418
|
-
* debouncedLog('World'); // Resets the timer, will log 'World' after 1 second
|
|
419
|
-
* ```
|
|
420
|
-
*
|
|
421
|
-
* @param fn - The function to debounce.
|
|
422
|
-
* @param [delay=300] - - The number of milliseconds to delay invoking the function.
|
|
423
|
-
*
|
|
424
|
-
* @returns - A debounced function
|
|
491
|
+
* Options for currency formatting.
|
|
425
492
|
*/
|
|
426
|
-
export declare
|
|
493
|
+
export declare type CurrencyFormatOptions = {
|
|
494
|
+
locale?: string;
|
|
495
|
+
style?: 'symbol' | 'code' | 'name';
|
|
496
|
+
minimumFractionDigits?: number;
|
|
497
|
+
maximumFractionDigits?: number;
|
|
498
|
+
};
|
|
499
|
+
|
|
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;
|
|
501
|
+
|
|
502
|
+
export declare function curry<T extends (...args: any[]) => any>(fn: T): Curried<Parameters<T>, ReturnType<T>>;
|
|
503
|
+
|
|
504
|
+
export declare function curry<T extends (...args: any[]) => any, N extends number>(fn: T, arity: N): Curried<Take<N, Parameters<T>>, ReturnType<T>>;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Debounce a function (trailing). Use `flush` to invoke immediately,
|
|
508
|
+
* `cancel` to clear, and `pending` to check if an invocation is scheduled.
|
|
509
|
+
*/
|
|
510
|
+
export declare function debounce<T extends Fn>(fn: T, delay?: number): Debounced<T>;
|
|
511
|
+
|
|
512
|
+
export declare type Debounced<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {
|
|
513
|
+
cancel(): void;
|
|
514
|
+
flush(): ReturnType<T> | undefined;
|
|
515
|
+
pending(): boolean;
|
|
516
|
+
};
|
|
427
517
|
|
|
428
518
|
declare type DeepMerge<T, U> = T extends Obj ? U extends Obj ? {
|
|
429
519
|
[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;
|
|
@@ -464,6 +554,51 @@ export declare function delay<T extends Fn>(fn: T, delay?: number): Promise<any>
|
|
|
464
554
|
*/
|
|
465
555
|
export declare function diff<T extends Obj>(curr?: T, prev?: T, compareFn?: (a: unknown, b: unknown) => boolean): Partial<T>;
|
|
466
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
|
+
|
|
467
602
|
/**
|
|
468
603
|
* “Draw” a random item from an array.
|
|
469
604
|
*
|
|
@@ -522,6 +657,35 @@ export declare namespace every {
|
|
|
522
657
|
var fp: boolean;
|
|
523
658
|
}
|
|
524
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
|
+
|
|
525
689
|
export declare type Expires = 'EXPIRED' | 'SOON' | 'LATER' | 'NEVER' | 'UNKNOWN';
|
|
526
690
|
|
|
527
691
|
/**
|
|
@@ -718,7 +882,7 @@ export declare function ge(a: unknown, b: unknown): boolean;
|
|
|
718
882
|
*
|
|
719
883
|
* @throws {TypeError} If the provided array is not an array.
|
|
720
884
|
*/
|
|
721
|
-
export declare function group<T,
|
|
885
|
+
export declare function group<T, _K extends keyof T, R extends string | number | symbol>(array: T[], selector: Selector<T>): Record<R, T[]>;
|
|
722
886
|
|
|
723
887
|
export declare namespace group {
|
|
724
888
|
var fp: boolean;
|
|
@@ -1314,32 +1478,42 @@ declare type LastReturnType<T> = T extends [...any, infer Last extends FnDynamic
|
|
|
1314
1478
|
*/
|
|
1315
1479
|
export declare function le(a: unknown, b: unknown): boolean;
|
|
1316
1480
|
|
|
1317
|
-
export declare
|
|
1318
|
-
readonly current: T[];
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
readonly meta: {
|
|
1323
|
-
end: number;
|
|
1324
|
-
isEmpty: boolean;
|
|
1325
|
-
isFirst: boolean;
|
|
1326
|
-
isLast: boolean;
|
|
1327
|
-
limit: number;
|
|
1328
|
-
page: number;
|
|
1329
|
-
pages: number;
|
|
1330
|
-
start: number;
|
|
1331
|
-
total: number;
|
|
1332
|
-
};
|
|
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;
|
|
1333
1486
|
next(): void;
|
|
1334
|
-
page: number;
|
|
1335
|
-
readonly pages: T[][];
|
|
1336
1487
|
prev(): void;
|
|
1337
|
-
reset():
|
|
1338
|
-
search
|
|
1339
|
-
|
|
1340
|
-
|
|
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;
|
|
1341
1504
|
};
|
|
1342
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
|
+
|
|
1343
1517
|
/**
|
|
1344
1518
|
* Checks if the first argument is less than the second argument.
|
|
1345
1519
|
*
|
|
@@ -1438,14 +1612,16 @@ export declare function median<T>(arr: T[], callback?: (item: T) => number | Dat
|
|
|
1438
1612
|
* @param options - Memoization options.
|
|
1439
1613
|
* @param [options.ttl] - (optional) time-to-live (TTL) for cache expiration (in milliseconds).
|
|
1440
1614
|
* @param [options.maxSize] - (optional) maximum cache size (LRU eviction).
|
|
1615
|
+
* @param [options.resolver] - (optional) custom function to resolve the cache key.
|
|
1441
1616
|
*
|
|
1442
1617
|
* @returns A new function that memorizes the input function.
|
|
1443
1618
|
*/
|
|
1444
|
-
export declare function memo<T extends Fn>(fn: T, { ttl, maxSize }?: MemoizeOptions): (...args: Parameters<T>) => ReturnType<T>;
|
|
1619
|
+
export declare function memo<T extends Fn>(fn: T, { ttl, maxSize, resolver }?: MemoizeOptions<T>): (...args: Parameters<T>) => ReturnType<T>;
|
|
1445
1620
|
|
|
1446
|
-
declare type MemoizeOptions = {
|
|
1621
|
+
declare type MemoizeOptions<T extends Fn> = {
|
|
1447
1622
|
ttl?: number;
|
|
1448
1623
|
maxSize?: number;
|
|
1624
|
+
resolver?: (...args: Parameters<T>) => string;
|
|
1449
1625
|
};
|
|
1450
1626
|
|
|
1451
1627
|
declare type Merge<T extends Obj[]> = T extends [infer First, ...infer Rest] ? First extends Obj ? Rest extends Obj[] ? DeepMerge<First, Merge<Rest>> : First : Obj : Obj;
|
|
@@ -1471,6 +1647,18 @@ export declare function merge<T extends Obj[]>(strategy?: MergeStrategy, ...item
|
|
|
1471
1647
|
|
|
1472
1648
|
declare type MergeStrategy = 'deep' | 'shallow' | 'lastWins' | 'arrayConcat' | 'arrayReplace' | ((target: any, source: any) => any);
|
|
1473
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
|
+
|
|
1474
1662
|
/**
|
|
1475
1663
|
* Finds the minimum item in an array.
|
|
1476
1664
|
*
|
|
@@ -1494,6 +1682,34 @@ declare type MergeStrategy = 'deep' | 'shallow' | 'lastWins' | 'arrayConcat' | '
|
|
|
1494
1682
|
*/
|
|
1495
1683
|
export declare function min<T>(array: T[], callback?: (item: T) => string | number | Date): T | undefined;
|
|
1496
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
|
+
|
|
1497
1713
|
export declare type Obj = Record<string, any>;
|
|
1498
1714
|
|
|
1499
1715
|
/**
|
|
@@ -1519,6 +1735,37 @@ export declare const once: <T extends Fn>(fn: T) => T & {
|
|
|
1519
1735
|
reset: () => void;
|
|
1520
1736
|
};
|
|
1521
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
|
+
|
|
1522
1769
|
/**
|
|
1523
1770
|
* Parses a JSON string and returns the resulting object.
|
|
1524
1771
|
*
|
|
@@ -1542,12 +1789,12 @@ export declare const once: <T extends Fn>(fn: T) => T & {
|
|
|
1542
1789
|
*/
|
|
1543
1790
|
export declare function parseJSON<T extends JSONValue>(json: unknown, options?: ParseJSONOptions<T>): T | undefined;
|
|
1544
1791
|
|
|
1545
|
-
declare
|
|
1792
|
+
declare type ParseJSONOptions<T> = {
|
|
1546
1793
|
defaultValue?: T;
|
|
1547
1794
|
reviver?: (key: string, value: any) => any;
|
|
1548
1795
|
validator?: (value: any) => boolean;
|
|
1549
1796
|
silent?: boolean;
|
|
1550
|
-
}
|
|
1797
|
+
};
|
|
1551
1798
|
|
|
1552
1799
|
/**
|
|
1553
1800
|
* Converts a string to Pascal case.
|
|
@@ -1615,7 +1862,7 @@ declare type PathValue<T, P extends string> = P extends `${infer Key}.${infer Re
|
|
|
1615
1862
|
*
|
|
1616
1863
|
* @throws {TypeError} If the first argument is not an array.
|
|
1617
1864
|
*/
|
|
1618
|
-
export declare function pick<T, R
|
|
1865
|
+
export declare function pick<T, R = T>(array: T[], callback: (item: T, index: number, array: T[]) => R, predicate?: (item: T, index: number, array: T[]) => boolean): R | undefined;
|
|
1619
1866
|
|
|
1620
1867
|
export declare namespace pick {
|
|
1621
1868
|
var fp: boolean;
|
|
@@ -1651,7 +1898,7 @@ export declare function pipe<T extends FnDynamic[]>(...fns: T): PipeReturn<T>;
|
|
|
1651
1898
|
|
|
1652
1899
|
declare type PipeReturn<T extends FnDynamic[]> = (...args: FirstParameters<T>) => LastReturnType<T> extends Promise<any> ? Promise<Awaited<LastReturnType<T>>> : LastReturnType<T>;
|
|
1653
1900
|
|
|
1654
|
-
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;
|
|
1655
1902
|
|
|
1656
1903
|
/**
|
|
1657
1904
|
* Creates a Promise that can be aborted using an AbortController.
|
|
@@ -1708,6 +1955,27 @@ declare type ProxyOptions<T> = {
|
|
|
1708
1955
|
watch?: (keyof T)[];
|
|
1709
1956
|
};
|
|
1710
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
|
+
|
|
1711
1979
|
/**
|
|
1712
1980
|
* Generates a random integer between two values, inclusive.
|
|
1713
1981
|
*
|
|
@@ -1739,6 +2007,9 @@ export declare function random(min: number, max: number): number;
|
|
|
1739
2007
|
* @param step - The value to increment or decrement by.
|
|
1740
2008
|
*
|
|
1741
2009
|
* @returns The range of numbers.
|
|
2010
|
+
*
|
|
2011
|
+
* @throws {TypeError} If start, stop, or step are not finite numbers.
|
|
2012
|
+
* @throws {Error} If step is 0 or if range exceeds maximum size.
|
|
1742
2013
|
*/
|
|
1743
2014
|
export declare function range(start: number, stop: number, step: number): number[];
|
|
1744
2015
|
|
|
@@ -1789,6 +2060,72 @@ export declare namespace reduce {
|
|
|
1789
2060
|
var fn: boolean;
|
|
1790
2061
|
}
|
|
1791
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
|
+
|
|
1792
2129
|
declare type RemoveFirstParameter<T extends Fn> = T extends (first: any, ...rest: infer R) => any ? R : never;
|
|
1793
2130
|
|
|
1794
2131
|
export declare type Result<C extends FnDynamic> = C extends FnAsync ? Promise<Awaited<ReturnType<C>>> : ReturnType<C>;
|
|
@@ -1817,7 +2154,7 @@ export declare type ResultArray<C extends FnDynamic> = C extends FnAsync ? Promi
|
|
|
1817
2154
|
export declare function retry<T>(fn: () => Promise<T>, { times, delay, backoff, signal, }?: {
|
|
1818
2155
|
times?: number;
|
|
1819
2156
|
delay?: number;
|
|
1820
|
-
backoff?: number;
|
|
2157
|
+
backoff?: number | ((attempt: number, delay: number) => number);
|
|
1821
2158
|
signal?: AbortSignal;
|
|
1822
2159
|
}): Promise<T>;
|
|
1823
2160
|
|
|
@@ -1984,6 +2321,8 @@ export declare function similarity(str1: unknown, str2: unknown): number;
|
|
|
1984
2321
|
* @param timeout - The number of milliseconds to wait before resolving the Promise.
|
|
1985
2322
|
*
|
|
1986
2323
|
* @returns A Promise that resolves after the specified time.
|
|
2324
|
+
*
|
|
2325
|
+
* @throws {TypeError} If timeout is not a non-negative number.
|
|
1987
2326
|
*/
|
|
1988
2327
|
export declare function sleep(timeout: number): Promise<void>;
|
|
1989
2328
|
|
|
@@ -2046,26 +2385,7 @@ export declare const sort: {
|
|
|
2046
2385
|
fp: boolean;
|
|
2047
2386
|
};
|
|
2048
2387
|
|
|
2049
|
-
|
|
2050
|
-
* Sorts an array of objects based on multiple selectors.
|
|
2051
|
-
*
|
|
2052
|
-
* @example
|
|
2053
|
-
* ```ts
|
|
2054
|
-
* const data = [
|
|
2055
|
-
* { name: 'Alice', age: 30 },
|
|
2056
|
-
* { name: 'Bob', age: 25 },
|
|
2057
|
-
* { name: 'Charlie', age: 35 },
|
|
2058
|
-
* { name: 'Alice', age: 25 },
|
|
2059
|
-
* { name: 'Bob', age: 30 },
|
|
2060
|
-
* { name: 'Charlie', age: 30 },
|
|
2061
|
-
* ].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 } ]
|
|
2062
|
-
* ```
|
|
2063
|
-
*
|
|
2064
|
-
* @param array - The array to sort.
|
|
2065
|
-
* @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.
|
|
2066
|
-
* @returns A new sorted array.
|
|
2067
|
-
*/
|
|
2068
|
-
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;
|
|
2069
2389
|
|
|
2070
2390
|
/**
|
|
2071
2391
|
* Replaces the first element in an array that satisfies the provided predicate function with a new value.
|
|
@@ -2089,6 +2409,25 @@ export declare namespace substitute {
|
|
|
2089
2409
|
var fn: boolean;
|
|
2090
2410
|
}
|
|
2091
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
|
+
|
|
2092
2431
|
/**
|
|
2093
2432
|
* Sum numbers in an array or numbers mapped by a callback function.
|
|
2094
2433
|
*
|
|
@@ -2097,7 +2436,6 @@ export declare namespace substitute {
|
|
|
2097
2436
|
* sum([1, 2, 3]) // 6
|
|
2098
2437
|
* sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6
|
|
2099
2438
|
* sum(['apple', 'banana', 'cherry']) // TypeError
|
|
2100
|
-
* sum([new Date('2023-01-01'), new Date('2022-01-01')]) // 467308800000
|
|
2101
2439
|
* ```
|
|
2102
2440
|
*
|
|
2103
2441
|
* @param array - The array to sum.
|
|
@@ -2105,29 +2443,49 @@ export declare namespace substitute {
|
|
|
2105
2443
|
*
|
|
2106
2444
|
* @returns The sum of the numbers in the array or the sum of the mapped values.
|
|
2107
2445
|
*/
|
|
2108
|
-
export declare function sum<T>(array: T[], callback?: (item: T) => number
|
|
2446
|
+
export declare function sum<T>(array: T[], callback?: (item: T) => number): number | undefined;
|
|
2109
2447
|
|
|
2110
2448
|
declare type SyncCallback<R, T> = (prev: R, curr: T, index: number, array: T[]) => R;
|
|
2111
2449
|
|
|
2450
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: - */
|
|
2112
2451
|
/**
|
|
2113
|
-
*
|
|
2452
|
+
* Curries a function, allowing it to be called with partial arguments.
|
|
2114
2453
|
*
|
|
2115
2454
|
* @example
|
|
2116
2455
|
* ```ts
|
|
2117
|
-
* const
|
|
2118
|
-
* const
|
|
2119
|
-
*
|
|
2120
|
-
* throttledLog(); // logs 'Hello, world!' immediately
|
|
2121
|
-
* throttledLog(); // does nothing because less than 1 second has passed since the last invocation
|
|
2122
|
-
* setTimeout(throttledLog, 1000); // logs 'Hello, world!' after 1 second
|
|
2456
|
+
* const add = (a: number, b: number) => a + b;
|
|
2457
|
+
* const curriedAdd = curry(add);
|
|
2458
|
+
* curriedAdd(1)(2) // 3;
|
|
2123
2459
|
* ```
|
|
2124
2460
|
*
|
|
2125
|
-
* @param fn - The function to
|
|
2126
|
-
* @param
|
|
2461
|
+
* @param fn - The function to curry.
|
|
2462
|
+
* @param arity - The number of arguments the function expects. Defaults to the function's length.
|
|
2463
|
+
*
|
|
2464
|
+
* @returns A curried version of the function.
|
|
2465
|
+
*/
|
|
2466
|
+
declare type Take<N extends number, T extends readonly unknown[], Acc extends readonly unknown[] = []> = Acc['length'] extends N ? Acc : T extends readonly [infer H, ...infer R] ? Take<N, R, readonly [...Acc, H]> : Acc;
|
|
2467
|
+
|
|
2468
|
+
/**
|
|
2469
|
+
* Throttles a function. By default, leading and trailing are both true (lodash-like behavior).
|
|
2470
|
+
* The function is invoked at the leading edge and trailing edge of the throttle period.
|
|
2127
2471
|
*
|
|
2128
|
-
*
|
|
2472
|
+
* Example:
|
|
2473
|
+
* const fn = () => ...
|
|
2474
|
+
* const t = throttle(fn, 700);
|
|
2475
|
+
* const leadingOnly = throttle(fn, 700, { trailing: false });
|
|
2129
2476
|
*/
|
|
2130
|
-
export declare function throttle<T extends Fn>(fn: T, delay?: number):
|
|
2477
|
+
export declare function throttle<T extends Fn>(fn: T, delay?: number, options?: ThrottleOptions): Throttled<T>;
|
|
2478
|
+
|
|
2479
|
+
export declare type Throttled<T extends Fn> = ((this: ThisParameterType<T>, ...args: Parameters<T>) => void) & {
|
|
2480
|
+
cancel(): void;
|
|
2481
|
+
flush(): ReturnType<T> | undefined;
|
|
2482
|
+
pending(): boolean;
|
|
2483
|
+
};
|
|
2484
|
+
|
|
2485
|
+
export declare type ThrottleOptions = {
|
|
2486
|
+
leading?: boolean;
|
|
2487
|
+
trailing?: boolean;
|
|
2488
|
+
};
|
|
2131
2489
|
|
|
2132
2490
|
/**
|
|
2133
2491
|
* Calculates the remaining time until a target date.
|
|
@@ -2178,6 +2536,8 @@ export declare type TimeUnit = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MIN
|
|
|
2178
2536
|
* @param ellipsis - The characters to end the truncated string with.
|
|
2179
2537
|
*
|
|
2180
2538
|
* @returns The truncated string.
|
|
2539
|
+
*
|
|
2540
|
+
* @throws {TypeError} If str is not a string or limit is not a positive number.
|
|
2181
2541
|
*/
|
|
2182
2542
|
export declare function truncate(str: string, limit?: number, completeWords?: boolean, ellipsis?: string): string;
|
|
2183
2543
|
|