es-toolkit 1.23.0-dev.751 → 1.23.0-dev.755

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.
@@ -1998,14 +1998,14 @@ function defaultTo(value, defaultValue) {
1998
1998
  return value;
1999
1999
  }
2000
2000
 
2001
- function times(n, iteratee) {
2001
+ function times(n, getValue) {
2002
2002
  n = toInteger(n);
2003
2003
  if (n < 1 || !Number.isSafeInteger(n)) {
2004
2004
  return [];
2005
2005
  }
2006
2006
  const result = new Array(n);
2007
2007
  for (let i = 0; i < n; i++) {
2008
- result[i] = typeof iteratee === 'function' ? iteratee(i) : i;
2008
+ result[i] = typeof getValue === 'function' ? getValue(i) : i;
2009
2009
  }
2010
2010
  return result;
2011
2011
  }
@@ -1,4 +1,3 @@
1
- import '../../string/deburr.mjs';
2
1
  import { upperCase as upperCase$1 } from '../../string/upperCase.mjs';
3
2
  import { normalizeForCase } from '../_internal/normalizeForCase.mjs';
4
3
 
@@ -1,11 +1,9 @@
1
1
  /**
2
- * Checks value to determine whether a default value should be returned in its place.
2
+ * Returns the default value for `null`, `undefined`, and `NaN`.
3
3
  *
4
- * The defaultValue is returned if value is NaN, null, or undefined.
5
- *
6
- * @param {unknown} value - The value to check.
7
- * @param {unknown} defaultValue - The default value to return if the first value is null, undefined, or NaN.
8
- * @returns {unknown} Returns either the first value or the default value.
4
+ * @param {T | null | undefined} value - The value to check.
5
+ * @param {T} [defaultValue] - The default value to return if the first value is null, undefined, or NaN.
6
+ * @returns {T} Returns either the first value or the default value.
9
7
  *
10
8
  * @example
11
9
  * defaultTo(null, 'default') // returns 'default'
@@ -14,6 +12,6 @@
14
12
  * defaultTo('actual', 'default') // returns 'actual'
15
13
  * defaultTo(123, 0) // returns 123
16
14
  */
17
- declare function defaultTo(value?: unknown, defaultValue?: unknown): any;
15
+ declare function defaultTo<T>(value: T | null | undefined, defaultValue?: T): T;
18
16
 
19
17
  export { defaultTo };
@@ -1,11 +1,9 @@
1
1
  /**
2
- * Checks value to determine whether a default value should be returned in its place.
2
+ * Returns the default value for `null`, `undefined`, and `NaN`.
3
3
  *
4
- * The defaultValue is returned if value is NaN, null, or undefined.
5
- *
6
- * @param {unknown} value - The value to check.
7
- * @param {unknown} defaultValue - The default value to return if the first value is null, undefined, or NaN.
8
- * @returns {unknown} Returns either the first value or the default value.
4
+ * @param {T | null | undefined} value - The value to check.
5
+ * @param {T} [defaultValue] - The default value to return if the first value is null, undefined, or NaN.
6
+ * @returns {T} Returns either the first value or the default value.
9
7
  *
10
8
  * @example
11
9
  * defaultTo(null, 'default') // returns 'default'
@@ -14,6 +12,6 @@
14
12
  * defaultTo('actual', 'default') // returns 'actual'
15
13
  * defaultTo(123, 0) // returns 123
16
14
  */
17
- declare function defaultTo(value?: unknown, defaultValue?: unknown): any;
15
+ declare function defaultTo<T>(value: T | null | undefined, defaultValue?: T): T;
18
16
 
19
17
  export { defaultTo };
@@ -1,18 +1,14 @@
1
1
  /**
2
- * Invokes the iteratee n times, returning an array of the results of each invocation.
3
- *
4
- * The iteratee is invoked with one argument; (index).
5
- *
6
- * @template F The type of the iteratee function.
7
- * @param {number} n - The number of times to invoke iteratee.
8
- * @param {F extends (n: number) => any} [iteratee] - The function invoked per iteration. Default is identity.
9
- * @returns {Array<ReturnType<F>>} - Returns the array of results.
2
+ * Invokes the getValue function n times, returning an array of the results.
10
3
  *
4
+ * @template R The return type of the getValue function.
5
+ * @param {number} n - The number of times to invoke getValue.
6
+ * @param {(index: number) => R} getValue - The function to invoke for each index.
7
+ * @returns {R[]} An array containing the results of invoking getValue n times.
11
8
  * @example
12
- * times(3, doubled); // => [0, 2, 4]
13
- * times(4); // => [0, 1, 2, 3]
14
- * times(2, () => 'es-toolkit') // => ['es-toolkit', 'es-toolkit']
9
+ * times(3, (i) => i * 2); // => [0, 2, 4]
10
+ * times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
15
11
  */
16
- declare function times<F extends (n: number) => any>(n?: number, iteratee?: F): Array<ReturnType<F>>;
12
+ declare function times<R = number>(n?: number, getValue?: (index: number) => R): R[];
17
13
 
18
14
  export { times };
@@ -1,18 +1,14 @@
1
1
  /**
2
- * Invokes the iteratee n times, returning an array of the results of each invocation.
3
- *
4
- * The iteratee is invoked with one argument; (index).
5
- *
6
- * @template F The type of the iteratee function.
7
- * @param {number} n - The number of times to invoke iteratee.
8
- * @param {F extends (n: number) => any} [iteratee] - The function invoked per iteration. Default is identity.
9
- * @returns {Array<ReturnType<F>>} - Returns the array of results.
2
+ * Invokes the getValue function n times, returning an array of the results.
10
3
  *
4
+ * @template R The return type of the getValue function.
5
+ * @param {number} n - The number of times to invoke getValue.
6
+ * @param {(index: number) => R} getValue - The function to invoke for each index.
7
+ * @returns {R[]} An array containing the results of invoking getValue n times.
11
8
  * @example
12
- * times(3, doubled); // => [0, 2, 4]
13
- * times(4); // => [0, 1, 2, 3]
14
- * times(2, () => 'es-toolkit') // => ['es-toolkit', 'es-toolkit']
9
+ * times(3, (i) => i * 2); // => [0, 2, 4]
10
+ * times(2, () => 'es-toolkit'); // => ['es-toolkit', 'es-toolkit']
15
11
  */
16
- declare function times<F extends (n: number) => any>(n?: number, iteratee?: F): Array<ReturnType<F>>;
12
+ declare function times<R = number>(n?: number, getValue?: (index: number) => R): R[];
17
13
 
18
14
  export { times };
@@ -1,13 +1,13 @@
1
1
  import { toInteger } from './toInteger.mjs';
2
2
 
3
- function times(n, iteratee) {
3
+ function times(n, getValue) {
4
4
  n = toInteger(n);
5
5
  if (n < 1 || !Number.isSafeInteger(n)) {
6
6
  return [];
7
7
  }
8
8
  const result = new Array(n);
9
9
  for (let i = 0; i < n; i++) {
10
- result[i] = typeof iteratee === 'function' ? iteratee(i) : i;
10
+ result[i] = typeof getValue === 'function' ? getValue(i) : i;
11
11
  }
12
12
  return result;
13
13
  }
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Converts value to an integer suitable for use as the length of an array-like object.
2
+ * Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
3
3
  *
4
- * @param {unknown} value - The value to convert to an array length.
5
- * @returns {number} Returns the converted integer.
4
+ * It converts the given value to a number and floors it to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`.
5
+ *
6
+ * @param {unknown} value - The value to convert to a valid index.
7
+ * @returns {number} The converted value.
6
8
  *
7
9
  * @example
8
10
  * toLength(3.2) // => 3
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Converts value to an integer suitable for use as the length of an array-like object.
2
+ * Converts the value to a valid index. A valid index is an integer that is greater than or equal to `0` and less than or equal to `2^32 - 1`.
3
3
  *
4
- * @param {unknown} value - The value to convert to an array length.
5
- * @returns {number} Returns the converted integer.
4
+ * It converts the given value to a number and floors it to an integer. If the value is less than `0`, it returns `0`. If the value exceeds `2^32 - 1`, it returns `2^32 - 1`.
5
+ *
6
+ * @param {unknown} value - The value to convert to a valid index.
7
+ * @returns {number} The converted value.
6
8
  *
7
9
  * @example
8
10
  * toLength(3.2) // => 3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.23.0-dev.751+aaec4abb",
4
+ "version": "1.23.0-dev.755+c5bbf032",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {