| [a762898] | 1 | /**
|
|---|
| 2 | * Creates a function that transforms the arguments of the provided function `func`.
|
|---|
| 3 | * The transformed arguments are passed to `func` such that the arguments starting from a specified index
|
|---|
| 4 | * are grouped into an array, while the previous arguments are passed as individual elements.
|
|---|
| 5 | *
|
|---|
| 6 | * @template F - The type of the function being transformed.
|
|---|
| 7 | * @param {F} func - The function whose arguments are to be transformed.
|
|---|
| 8 | * @param {number} [startIndex=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
|
|---|
| 9 | * Defaults to `func.length - 1`, grouping all arguments after the last parameter.
|
|---|
| 10 | * @returns {(...args: any[]) => ReturnType<F>} A new function that, when called, returns the result of calling `func` with the transformed arguments.
|
|---|
| 11 | *
|
|---|
| 12 | * The transformed arguments are:
|
|---|
| 13 | * - The first `start` arguments as individual elements.
|
|---|
| 14 | * - The remaining arguments from index `start` onward grouped into an array.
|
|---|
| 15 | * @example
|
|---|
| 16 | * function fn(a, b, c) {
|
|---|
| 17 | * return [a, b, c];
|
|---|
| 18 | * }
|
|---|
| 19 | *
|
|---|
| 20 | * // Using default start index (func.length - 1, which is 2 in this case)
|
|---|
| 21 | * const transformedFn = rest(fn);
|
|---|
| 22 | * console.log(transformedFn(1, 2, 3, 4)); // [1, 2, [3, 4]]
|
|---|
| 23 | *
|
|---|
| 24 | * // Using start index 1
|
|---|
| 25 | * const transformedFnWithStart = rest(fn, 1);
|
|---|
| 26 | * console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]]
|
|---|
| 27 | *
|
|---|
| 28 | * // With fewer arguments than the start index
|
|---|
| 29 | * console.log(transformedFn(1)); // [1, undefined, []]
|
|---|
| 30 | */
|
|---|
| 31 | declare function rest<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
|
|---|
| 32 |
|
|---|
| 33 | export { rest };
|
|---|