es-toolkit 1.23.0-dev.732 → 1.23.0-dev.734

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.
@@ -61,6 +61,7 @@ export { randomInt } from '../math/randomInt.mjs';
61
61
  export { sum } from '../math/sum.mjs';
62
62
  export { sumBy } from '../math/sumBy.mjs';
63
63
  export { range } from '../math/range.mjs';
64
+ export { rangeRight } from '../math/rangeRight.mjs';
64
65
  export { omitBy } from '../object/omitBy.mjs';
65
66
  export { pickBy } from '../object/pickBy.mjs';
66
67
  export { invert } from '../object/invert.mjs';
@@ -61,6 +61,7 @@ export { randomInt } from '../math/randomInt.js';
61
61
  export { sum } from '../math/sum.js';
62
62
  export { sumBy } from '../math/sumBy.js';
63
63
  export { range } from '../math/range.js';
64
+ export { rangeRight } from '../math/rangeRight.js';
64
65
  export { omitBy } from '../object/omitBy.js';
65
66
  export { pickBy } from '../object/pickBy.js';
66
67
  export { invert } from '../object/invert.js';
@@ -4,9 +4,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const zipWith = require('../_chunk/zipWith-EOU_KZ.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const flowRight$1 = require('../_chunk/flowRight-CVcg72.js');
7
+ const flowRight$1 = require('../_chunk/flowRight-B6_Omw.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
- const range = require('../_chunk/range-BXlMmn.js');
9
+ const rangeRight = require('../_chunk/rangeRight-CtcxMd.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
11
  const isObjectLike = require('../_chunk/isObjectLike-aywuSF.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-DgrsU7.js');
@@ -1754,7 +1754,7 @@ function clamp(value, bound1, bound2) {
1754
1754
  if (Number.isNaN(bound2)) {
1755
1755
  bound2 = 0;
1756
1756
  }
1757
- return range.clamp(value, bound1, bound2);
1757
+ return rangeRight.clamp(value, bound1, bound2);
1758
1758
  }
1759
1759
 
1760
1760
  function max(items = []) {
@@ -1842,7 +1842,7 @@ function inRange(value, minimum, maximum) {
1842
1842
  if (minimum === maximum) {
1843
1843
  return false;
1844
1844
  }
1845
- return range.inRange(value, minimum, maximum);
1845
+ return rangeRight.inRange(value, minimum, maximum);
1846
1846
  }
1847
1847
 
1848
1848
  function random(...args) {
@@ -1971,11 +1971,12 @@ exports.partial = flowRight$1.partial;
1971
1971
  exports.partialRight = flowRight$1.partialRight;
1972
1972
  exports.unary = flowRight$1.unary;
1973
1973
  exports.noop = noop.noop;
1974
- exports.mean = range.mean;
1975
- exports.meanBy = range.meanBy;
1976
- exports.range = range.range;
1977
- exports.sum = range.sum;
1978
- exports.sumBy = range.sumBy;
1974
+ exports.mean = rangeRight.mean;
1975
+ exports.meanBy = rangeRight.meanBy;
1976
+ exports.range = rangeRight.range;
1977
+ exports.rangeRight = rangeRight.rangeRight;
1978
+ exports.sum = rangeRight.sum;
1979
+ exports.sumBy = rangeRight.sumBy;
1979
1980
  exports.randomInt = randomInt.randomInt;
1980
1981
  exports.clone = isObjectLike.clone;
1981
1982
  exports.flattenObject = isObjectLike.flattenObject;
@@ -61,6 +61,7 @@ export { randomInt } from '../math/randomInt.mjs';
61
61
  export { sum } from '../math/sum.mjs';
62
62
  export { sumBy } from '../math/sumBy.mjs';
63
63
  export { range } from '../math/range.mjs';
64
+ export { rangeRight } from '../math/rangeRight.mjs';
64
65
  export { omitBy } from '../object/omitBy.mjs';
65
66
  export { pickBy } from '../object/pickBy.mjs';
66
67
  export { invert } from '../object/invert.mjs';
@@ -6,7 +6,7 @@
6
6
  * - If `n` is 0, `func` will never be called.
7
7
  * - If `n` is a positive integer, `func` will be called up to `n-1` times.
8
8
  * @param {F} func - The function to be called with the limit applied.
9
- * @returns {F} - A new function that:
9
+ * @returns {(...args: Parameters<F>) => ReturnType<F> | undefined} - A new function that:
10
10
  * - Tracks the number of calls.
11
11
  * - Invokes `func` until the `n-1`-th call.
12
12
  * - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
@@ -26,6 +26,6 @@
26
26
  * // Will not log anything.
27
27
  * beforeFn();
28
28
  */
29
- declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
29
+ declare function before<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
30
30
 
31
31
  export { before };
@@ -6,7 +6,7 @@
6
6
  * - If `n` is 0, `func` will never be called.
7
7
  * - If `n` is a positive integer, `func` will be called up to `n-1` times.
8
8
  * @param {F} func - The function to be called with the limit applied.
9
- * @returns {F} - A new function that:
9
+ * @returns {(...args: Parameters<F>) => ReturnType<F> | undefined} - A new function that:
10
10
  * - Tracks the number of calls.
11
11
  * - Invokes `func` until the `n-1`-th call.
12
12
  * - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls.
@@ -26,6 +26,6 @@
26
26
  * // Will not log anything.
27
27
  * beforeFn();
28
28
  */
29
- declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
29
+ declare function before<F extends (...args: any[]) => any>(n: number, func: F): (...args: Parameters<F>) => ReturnType<F> | undefined;
30
30
 
31
31
  export { before };
@@ -3,12 +3,12 @@ function before(n, func) {
3
3
  throw new Error('n must be a non-negative integer.');
4
4
  }
5
5
  let counter = 0;
6
- return ((...args) => {
6
+ return (...args) => {
7
7
  if (++counter < n) {
8
8
  return func(...args);
9
9
  }
10
10
  return undefined;
11
- });
11
+ };
12
12
  }
13
13
 
14
14
  export { before };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const flowRight = require('../_chunk/flowRight-CVcg72.js');
5
+ const flowRight = require('../_chunk/flowRight-B6_Omw.js');
6
6
  const noop = require('../_chunk/noop-2IwLUk.js');
7
7
 
8
8
  function before(n, func) {
@@ -10,12 +10,12 @@ function before(n, func) {
10
10
  throw new Error('n must be a non-negative integer.');
11
11
  }
12
12
  let counter = 0;
13
- return ((...args) => {
13
+ return (...args) => {
14
14
  if (++counter < n) {
15
15
  return func(...args);
16
16
  }
17
17
  return undefined;
18
- });
18
+ };
19
19
  }
20
20
 
21
21
  function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
@@ -3,7 +3,7 @@
3
3
  * Repeated calls to the function will return the value from the first invocation.
4
4
  *
5
5
  * @template F - The type of function.
6
- * @param {F} func - The function to restrict.
6
+ * @param {F extends () => any} func - The function to restrict.
7
7
  * @returns {F} A new function that invokes `func` once and caches the result.
8
8
  *
9
9
  * @example
@@ -16,5 +16,20 @@
16
16
  * initialize(); // Returns true without logging
17
17
  */
18
18
  declare function once<F extends () => any>(func: F): F;
19
+ /**
20
+ * Creates a function that is restricted to invoking the provided function `func` once.
21
+ * Repeated calls to the function will return the value from the first invocation.
22
+ *
23
+ * @template F - The type of function.
24
+ * @param {F extends (...args: any[]) => void} func - The function to restrict with arguments.
25
+ * @returns {F} A new function that invokes `func` once.
26
+ *
27
+ * @example
28
+ * const log = once(console.log);
29
+ *
30
+ * log('Hello, world!'); // prints 'Hello, world!' and doesn't return anything
31
+ * log('Hello, world!'); // doesn't print anything and doesn't return anything
32
+ */
33
+ declare function once<F extends (...args: any[]) => void>(func: F): F;
19
34
 
20
35
  export { once };
@@ -3,7 +3,7 @@
3
3
  * Repeated calls to the function will return the value from the first invocation.
4
4
  *
5
5
  * @template F - The type of function.
6
- * @param {F} func - The function to restrict.
6
+ * @param {F extends () => any} func - The function to restrict.
7
7
  * @returns {F} A new function that invokes `func` once and caches the result.
8
8
  *
9
9
  * @example
@@ -16,5 +16,20 @@
16
16
  * initialize(); // Returns true without logging
17
17
  */
18
18
  declare function once<F extends () => any>(func: F): F;
19
+ /**
20
+ * Creates a function that is restricted to invoking the provided function `func` once.
21
+ * Repeated calls to the function will return the value from the first invocation.
22
+ *
23
+ * @template F - The type of function.
24
+ * @param {F extends (...args: any[]) => void} func - The function to restrict with arguments.
25
+ * @returns {F} A new function that invokes `func` once.
26
+ *
27
+ * @example
28
+ * const log = once(console.log);
29
+ *
30
+ * log('Hello, world!'); // prints 'Hello, world!' and doesn't return anything
31
+ * log('Hello, world!'); // doesn't print anything and doesn't return anything
32
+ */
33
+ declare function once<F extends (...args: any[]) => void>(func: F): F;
19
34
 
20
35
  export { once };
@@ -1,14 +1,12 @@
1
1
  function once(func) {
2
2
  let called = false;
3
3
  let cache;
4
- return function () {
5
- if (called) {
6
- return cache;
4
+ return function (...args) {
5
+ if (!called) {
6
+ called = true;
7
+ cache = func(...args);
7
8
  }
8
- const result = func();
9
- called = true;
10
- cache = result;
11
- return result;
9
+ return cache;
12
10
  };
13
11
  }
14
12
 
package/dist/index.d.mts CHANGED
@@ -84,6 +84,7 @@ export { round } from './math/round.mjs';
84
84
  export { sum } from './math/sum.mjs';
85
85
  export { sumBy } from './math/sumBy.mjs';
86
86
  export { range } from './math/range.mjs';
87
+ export { rangeRight } from './math/rangeRight.mjs';
87
88
  export { omit } from './object/omit.mjs';
88
89
  export { omitBy } from './object/omitBy.mjs';
89
90
  export { pick } from './object/pick.mjs';
package/dist/index.d.ts CHANGED
@@ -84,6 +84,7 @@ export { round } from './math/round.js';
84
84
  export { sum } from './math/sum.js';
85
85
  export { sumBy } from './math/sumBy.js';
86
86
  export { range } from './math/range.js';
87
+ export { rangeRight } from './math/rangeRight.js';
87
88
  export { omit } from './object/omit.js';
88
89
  export { omitBy } from './object/omitBy.js';
89
90
  export { pick } from './object/pick.js';
package/dist/index.js CHANGED
@@ -6,9 +6,9 @@ const zipWith = require('./_chunk/zipWith-EOU_KZ.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
8
  const function_index = require('./function/index.js');
9
- const flowRight = require('./_chunk/flowRight-CVcg72.js');
9
+ const flowRight = require('./_chunk/flowRight-B6_Omw.js');
10
10
  const noop = require('./_chunk/noop-2IwLUk.js');
11
- const range = require('./_chunk/range-BXlMmn.js');
11
+ const rangeRight = require('./_chunk/rangeRight-CtcxMd.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
14
  const object_index = require('./object/index.js');
@@ -100,13 +100,14 @@ exports.partialRight = flowRight.partialRight;
100
100
  exports.rest = flowRight.rest;
101
101
  exports.unary = flowRight.unary;
102
102
  exports.noop = noop.noop;
103
- exports.clamp = range.clamp;
104
- exports.inRange = range.inRange;
105
- exports.mean = range.mean;
106
- exports.meanBy = range.meanBy;
107
- exports.range = range.range;
108
- exports.sum = range.sum;
109
- exports.sumBy = range.sumBy;
103
+ exports.clamp = rangeRight.clamp;
104
+ exports.inRange = rangeRight.inRange;
105
+ exports.mean = rangeRight.mean;
106
+ exports.meanBy = rangeRight.meanBy;
107
+ exports.range = rangeRight.range;
108
+ exports.rangeRight = rangeRight.rangeRight;
109
+ exports.sum = rangeRight.sum;
110
+ exports.sumBy = rangeRight.sumBy;
110
111
  exports.random = randomInt.random;
111
112
  exports.randomInt = randomInt.randomInt;
112
113
  exports.round = math_index.round;
package/dist/index.mjs CHANGED
@@ -84,6 +84,7 @@ export { round } from './math/round.mjs';
84
84
  export { sum } from './math/sum.mjs';
85
85
  export { sumBy } from './math/sumBy.mjs';
86
86
  export { range } from './math/range.mjs';
87
+ export { rangeRight } from './math/rangeRight.mjs';
87
88
  export { omit } from './object/omit.mjs';
88
89
  export { omitBy } from './object/omitBy.mjs';
89
90
  export { pick } from './object/pick.mjs';
@@ -8,3 +8,4 @@ export { round } from './round.mjs';
8
8
  export { sum } from './sum.mjs';
9
9
  export { sumBy } from './sumBy.mjs';
10
10
  export { range } from './range.mjs';
11
+ export { rangeRight } from './rangeRight.mjs';
@@ -8,3 +8,4 @@ export { round } from './round.js';
8
8
  export { sum } from './sum.js';
9
9
  export { sumBy } from './sumBy.js';
10
10
  export { range } from './range.js';
11
+ export { rangeRight } from './rangeRight.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const range = require('../_chunk/range-BXlMmn.js');
5
+ const rangeRight = require('../_chunk/rangeRight-CtcxMd.js');
6
6
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
7
7
 
8
8
  function round(value, precision = 0) {
@@ -13,13 +13,14 @@ function round(value, precision = 0) {
13
13
  return Math.round(value * multiplier) / multiplier;
14
14
  }
15
15
 
16
- exports.clamp = range.clamp;
17
- exports.inRange = range.inRange;
18
- exports.mean = range.mean;
19
- exports.meanBy = range.meanBy;
20
- exports.range = range.range;
21
- exports.sum = range.sum;
22
- exports.sumBy = range.sumBy;
16
+ exports.clamp = rangeRight.clamp;
17
+ exports.inRange = rangeRight.inRange;
18
+ exports.mean = rangeRight.mean;
19
+ exports.meanBy = rangeRight.meanBy;
20
+ exports.range = rangeRight.range;
21
+ exports.rangeRight = rangeRight.rangeRight;
22
+ exports.sum = rangeRight.sum;
23
+ exports.sumBy = rangeRight.sumBy;
23
24
  exports.random = randomInt.random;
24
25
  exports.randomInt = randomInt.randomInt;
25
26
  exports.round = round;
@@ -8,3 +8,4 @@ export { round } from './round.mjs';
8
8
  export { sum } from './sum.mjs';
9
9
  export { sumBy } from './sumBy.mjs';
10
10
  export { range } from './range.mjs';
11
+ export { rangeRight } from './rangeRight.mjs';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Returns an array of numbers from `end` (exclusive) to `0` (inclusive), decrementing by `1`.
3
+ *
4
+ * @param {number} end - The end number of the range (exclusive).
5
+ * @returns {number[]} An array of numbers from `end` (exclusive) to `0` (inclusive) with a step of `1`.
6
+ *
7
+ * @example
8
+ * // Returns [3, 2, 1, 0]
9
+ * rangeRight(4);
10
+ */
11
+ declare function rangeRight(end: number): number[];
12
+ /**
13
+ * Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `1`.
14
+ *
15
+ * @param {number} start - The starting number of the range (inclusive).
16
+ * @param {number} end - The end number of the range (exclusive).
17
+ * @returns {number[]} An array of numbers from `end` (exclusive) to `start` (inclusive) with a step of `1`.
18
+ *
19
+ * @example
20
+ * // Returns [3, 2, 1]
21
+ * rangeRight(1, 4);
22
+ */
23
+ declare function rangeRight(start: number, end: number): number[];
24
+ /**
25
+ * Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `step`.
26
+ *
27
+ * @param {number} start - The starting number of the range (inclusive).
28
+ * @param {number} end - The end number of the range (exclusive).
29
+ * @param {number} step - The step value for the range.
30
+ * @returns {number[]} An array of numbers from `end` (exclusive) to `start` (inclusive) with the specified `step`.
31
+ *
32
+ * @example
33
+ * // Returns [15, 10, 5, 0]
34
+ * rangeRight(0, 20, 5);
35
+ */
36
+ declare function rangeRight(start: number, end: number, step: number): number[];
37
+
38
+ export { rangeRight };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Returns an array of numbers from `end` (exclusive) to `0` (inclusive), decrementing by `1`.
3
+ *
4
+ * @param {number} end - The end number of the range (exclusive).
5
+ * @returns {number[]} An array of numbers from `end` (exclusive) to `0` (inclusive) with a step of `1`.
6
+ *
7
+ * @example
8
+ * // Returns [3, 2, 1, 0]
9
+ * rangeRight(4);
10
+ */
11
+ declare function rangeRight(end: number): number[];
12
+ /**
13
+ * Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `1`.
14
+ *
15
+ * @param {number} start - The starting number of the range (inclusive).
16
+ * @param {number} end - The end number of the range (exclusive).
17
+ * @returns {number[]} An array of numbers from `end` (exclusive) to `start` (inclusive) with a step of `1`.
18
+ *
19
+ * @example
20
+ * // Returns [3, 2, 1]
21
+ * rangeRight(1, 4);
22
+ */
23
+ declare function rangeRight(start: number, end: number): number[];
24
+ /**
25
+ * Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `step`.
26
+ *
27
+ * @param {number} start - The starting number of the range (inclusive).
28
+ * @param {number} end - The end number of the range (exclusive).
29
+ * @param {number} step - The step value for the range.
30
+ * @returns {number[]} An array of numbers from `end` (exclusive) to `start` (inclusive) with the specified `step`.
31
+ *
32
+ * @example
33
+ * // Returns [15, 10, 5, 0]
34
+ * rangeRight(0, 20, 5);
35
+ */
36
+ declare function rangeRight(start: number, end: number, step: number): number[];
37
+
38
+ export { rangeRight };
@@ -0,0 +1,20 @@
1
+ function rangeRight(start, end, step) {
2
+ if (end == null) {
3
+ end = start;
4
+ start = 0;
5
+ }
6
+ if (step == null) {
7
+ step = 1;
8
+ }
9
+ if (!Number.isInteger(step) || step === 0) {
10
+ throw new Error(`The step value must be a non-zero integer.`);
11
+ }
12
+ const length = Math.max(Math.ceil((end - start) / step), 0);
13
+ const result = new Array(length);
14
+ for (let i = 0; i < length; i++) {
15
+ result[i] = start + (length - i - 1) * step;
16
+ }
17
+ return result;
18
+ }
19
+
20
+ export { rangeRight };
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.732+65d65b57",
4
+ "version": "1.23.0-dev.734+21bd4826",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {