es-toolkit 1.39.10-dev.1598 → 1.39.10-dev.1600

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.
@@ -3,11 +3,11 @@
3
3
  * If the function throws an error, it catches the error and returns it.
4
4
  * If the caught error is not an instance of Error, it wraps it in a new Error.
5
5
  *
6
- * @param {F} func - The function to be executed.
7
- * @param {...Parameters<F>} args - The arguments to pass to the function.
8
- * @returns {ReturnType<F> | Error} The return value of the function if successful, or an Error if an exception is thrown.
6
+ * @param {(...args: any[]) => R} func - The function to be executed.
7
+ * @param {...any[]} args - The arguments to pass to the function.
8
+ * @returns {R | Error} The return value of the function if successful, or an Error if an exception is thrown.
9
9
  *
10
- * @template F - The type of the function being attempted.
10
+ * @template R - The type of the function return value.
11
11
  *
12
12
  * @example
13
13
  * // Example 1: Successful execution
@@ -3,11 +3,11 @@
3
3
  * If the function throws an error, it catches the error and returns it.
4
4
  * If the caught error is not an instance of Error, it wraps it in a new Error.
5
5
  *
6
- * @param {F} func - The function to be executed.
7
- * @param {...Parameters<F>} args - The arguments to pass to the function.
8
- * @returns {ReturnType<F> | Error} The return value of the function if successful, or an Error if an exception is thrown.
6
+ * @param {(...args: any[]) => R} func - The function to be executed.
7
+ * @param {...any[]} args - The arguments to pass to the function.
8
+ * @returns {R | Error} The return value of the function if successful, or an Error if an exception is thrown.
9
9
  *
10
- * @template F - The type of the function being attempted.
10
+ * @template R - The type of the function return value.
11
11
  *
12
12
  * @example
13
13
  * // Example 1: Successful execution
@@ -5,11 +5,10 @@
5
5
  *
6
6
  * Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
7
7
  *
8
- * @template F - The type of the function to bind.
9
- * @param {F} func - The function to bind.
10
- * @param {unknown} thisObj - The `this` binding of `func`.
8
+ * @param {(...args: any[]) => any} func - The function to bind.
9
+ * @param {any} thisObj - The `this` binding of `func`.
11
10
  * @param {...any} partialArgs - The arguments to be partially applied.
12
- * @returns {F} - Returns the new bound function.
11
+ * @returns {(...args: any[]) => any} - Returns the new bound function.
13
12
  *
14
13
  * @example
15
14
  * function greet(greeting, punctuation) {
@@ -5,11 +5,10 @@
5
5
  *
6
6
  * Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
7
7
  *
8
- * @template F - The type of the function to bind.
9
- * @param {F} func - The function to bind.
10
- * @param {unknown} thisObj - The `this` binding of `func`.
8
+ * @param {(...args: any[]) => any} func - The function to bind.
9
+ * @param {any} thisObj - The `this` binding of `func`.
11
10
  * @param {...any} partialArgs - The arguments to be partially applied.
12
- * @returns {F} - Returns the new bound function.
11
+ * @returns {(...args: any[]) => any} - Returns the new bound function.
13
12
  *
14
13
  * @example
15
14
  * function greet(greeting, punctuation) {
@@ -12,15 +12,13 @@ import { Many } from '../_internal/Many.mjs';
12
12
  * If a transform is nullish, the identity function is used instead.
13
13
  * Only transforms arguments up to the number of transform functions provided.
14
14
  *
15
- * @template F - The type of the function to wrap
16
- * @template T - The type of the transform functions array
17
- * @param {F} func - The function to wrap
18
- * @param {T} transforms - The functions to transform arguments. Each transform can be:
15
+ * @param {(...args: any[]) => any} func - The function to wrap
16
+ * @param {Array<Many<(...args: any[]) => any>>} transforms - The functions to transform arguments. Each transform can be:
19
17
  * - A function that accepts and returns a value
20
18
  * - A string to get a property value (e.g. 'name' gets the name property)
21
19
  * - An object to check if arguments match its properties
22
20
  * - An array of [property, value] to check property matches
23
- * @returns {(...args: any[]) => ReturnType<F>} A new function that transforms arguments before passing them to func
21
+ * @returns {(...args: any[]) => any} A new function that transforms arguments before passing them to func
24
22
  * @throws {TypeError} If func is not a function.
25
23
  * @example
26
24
  * ```ts
@@ -12,15 +12,13 @@ import { Many } from '../_internal/Many.js';
12
12
  * If a transform is nullish, the identity function is used instead.
13
13
  * Only transforms arguments up to the number of transform functions provided.
14
14
  *
15
- * @template F - The type of the function to wrap
16
- * @template T - The type of the transform functions array
17
- * @param {F} func - The function to wrap
18
- * @param {T} transforms - The functions to transform arguments. Each transform can be:
15
+ * @param {(...args: any[]) => any} func - The function to wrap
16
+ * @param {Array<Many<(...args: any[]) => any>>} transforms - The functions to transform arguments. Each transform can be:
19
17
  * - A function that accepts and returns a value
20
18
  * - A string to get a property value (e.g. 'name' gets the name property)
21
19
  * - An object to check if arguments match its properties
22
20
  * - An array of [property, value] to check property matches
23
- * @returns {(...args: any[]) => ReturnType<F>} A new function that transforms arguments before passing them to func
21
+ * @returns {(...args: any[]) => any} A new function that transforms arguments before passing them to func
24
22
  * @throws {TypeError} If func is not a function.
25
23
  * @example
26
24
  * ```ts
@@ -5,10 +5,9 @@ import { Many } from '../_internal/Many.mjs';
5
5
  * where the argument value at the first index is provided as the first argument,
6
6
  * the argument value at the second index is provided as the second argument, and so on.
7
7
  *
8
- * @template F The type of the function to re-arrange.
9
- * @param {F} func The function to rearrange arguments for.
8
+ * @param {(...args: any[]) => any} func The function to rearrange arguments for.
10
9
  * @param {Array<number | number[]>} indices The arranged argument indices.
11
- * @returns {(...args: any[]) => ReturnType<F>} Returns the new function.
10
+ * @returns {(...args: any[]) => any} Returns the new function.
12
11
  *
13
12
  * @example
14
13
  * const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
@@ -5,10 +5,9 @@ import { Many } from '../_internal/Many.js';
5
5
  * where the argument value at the first index is provided as the first argument,
6
6
  * the argument value at the second index is provided as the second argument, and so on.
7
7
  *
8
- * @template F The type of the function to re-arrange.
9
- * @param {F} func The function to rearrange arguments for.
8
+ * @param {(...args: any[]) => any} func The function to rearrange arguments for.
10
9
  * @param {Array<number | number[]>} indices The arranged argument indices.
11
- * @returns {(...args: any[]) => ReturnType<F>} Returns the new function.
10
+ * @returns {(...args: any[]) => any} Returns the new function.
12
11
  *
13
12
  * @example
14
13
  * const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
@@ -3,11 +3,10 @@
3
3
  * The transformed arguments are passed to `func` such that the arguments starting from a specified index
4
4
  * are grouped into an array, while the previous arguments are passed as individual elements.
5
5
  *
6
- * @template F - The type of the function being transformed.
7
- * @param {F} func - The function whose arguments are to be transformed.
6
+ * @param {(...args: any[]) => any} func - The function whose arguments are to be transformed.
8
7
  * @param {number} [start=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
9
8
  * 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.
9
+ * @returns {(...args: any[]) => any} A new function that, when called, returns the result of calling `func` with the transformed arguments.
11
10
  *
12
11
  * The transformed arguments are:
13
12
  * - The first `start` arguments as individual elements.
@@ -3,11 +3,10 @@
3
3
  * The transformed arguments are passed to `func` such that the arguments starting from a specified index
4
4
  * are grouped into an array, while the previous arguments are passed as individual elements.
5
5
  *
6
- * @template F - The type of the function being transformed.
7
- * @param {F} func - The function whose arguments are to be transformed.
6
+ * @param {(...args: any[]) => any} func - The function whose arguments are to be transformed.
8
7
  * @param {number} [start=func.length - 1] - The index from which to start grouping the remaining arguments into an array.
9
8
  * 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.
9
+ * @returns {(...args: any[]) => any} A new function that, when called, returns the result of calling `func` with the transformed arguments.
11
10
  *
12
11
  * The transformed arguments are:
13
12
  * - The first `start` arguments as individual elements.
@@ -4,6 +4,13 @@
4
4
  *
5
5
  * If a `value` is provided instead of a function, this value is passed as the first argument to the `wrapper` function.
6
6
  *
7
+ * @template T - The type of the value being wrapped.
8
+ * @template U - The type of the arguments being passed to the `wrapper` function.
9
+ * @template V - The type of the return value of the `wrapper` function.
10
+ * @param {T} value - The value to be wrapped.
11
+ * @param {(value: T, ...args: U[]) => V} wrapper - The function to wrap the value with.
12
+ * @returns {(...args: U[]) => V} A new function that wraps the value with the `wrapper` function.
13
+ *
7
14
  * @example
8
15
  * // Wrap a function
9
16
  * const greet = (name: string) => `Hi, ${name}`;
@@ -4,6 +4,13 @@
4
4
  *
5
5
  * If a `value` is provided instead of a function, this value is passed as the first argument to the `wrapper` function.
6
6
  *
7
+ * @template T - The type of the value being wrapped.
8
+ * @template U - The type of the arguments being passed to the `wrapper` function.
9
+ * @template V - The type of the return value of the `wrapper` function.
10
+ * @param {T} value - The value to be wrapped.
11
+ * @param {(value: T, ...args: U[]) => V} wrapper - The function to wrap the value with.
12
+ * @returns {(...args: U[]) => V} A new function that wraps the value with the `wrapper` function.
13
+ *
7
14
  * @example
8
15
  * // Wrap a function
9
16
  * const greet = (name: string) => `Hi, ${name}`;
@@ -5,14 +5,15 @@
5
5
  * If the array is empty, this function returns `0`.
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
- * @param {T[]} items An array to calculate the sum.
9
- * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
8
+ * @param {readonly T[]} items - An array to calculate the sum.
9
+ * @param {(element: T, index: number) => number} getValue - A function that selects a numeric value from each element.
10
+ * It receives the element and its zero‑based index in the array.
10
11
  * @returns {number} The sum of all the numbers as determined by the `getValue` function.
11
12
  *
12
13
  * @example
13
- * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6
14
- * sumBy([], x => x.a); // Returns: 0
14
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], (x, i) => x.a * i); // Returns: 8
15
+ * sumBy([], () => 1); // Returns: 0
15
16
  */
16
- declare function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number;
17
+ declare function sumBy<T>(items: readonly T[], getValue: (element: T, index: number) => number): number;
17
18
 
18
19
  export { sumBy };
@@ -5,14 +5,15 @@
5
5
  * If the array is empty, this function returns `0`.
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
- * @param {T[]} items An array to calculate the sum.
9
- * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
8
+ * @param {readonly T[]} items - An array to calculate the sum.
9
+ * @param {(element: T, index: number) => number} getValue - A function that selects a numeric value from each element.
10
+ * It receives the element and its zero‑based index in the array.
10
11
  * @returns {number} The sum of all the numbers as determined by the `getValue` function.
11
12
  *
12
13
  * @example
13
- * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6
14
- * sumBy([], x => x.a); // Returns: 0
14
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], (x, i) => x.a * i); // Returns: 8
15
+ * sumBy([], () => 1); // Returns: 0
15
16
  */
16
- declare function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number;
17
+ declare function sumBy<T>(items: readonly T[], getValue: (element: T, index: number) => number): number;
17
18
 
18
19
  export { sumBy };
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  function sumBy(items, getValue) {
6
6
  let result = 0;
7
7
  for (let i = 0; i < items.length; i++) {
8
- result += getValue(items[i]);
8
+ result += getValue(items[i], i);
9
9
  }
10
10
  return result;
11
11
  }
@@ -1,7 +1,7 @@
1
1
  function sumBy(items, getValue) {
2
2
  let result = 0;
3
3
  for (let i = 0; i < items.length; i++) {
4
- result += getValue(items[i]);
4
+ result += getValue(items[i], i);
5
5
  }
6
6
  return result;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
- "version": "1.39.10-dev.1598+9e1549e6",
3
+ "version": "1.39.10-dev.1600+579af7b1",
4
4
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
5
5
  "homepage": "https://es-toolkit.dev",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",