es-toolkit 1.15.1-dev.445 → 1.15.1-dev.447

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.
@@ -0,0 +1,33 @@
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, start?: number): (...args: any[]) => ReturnType<F>;
32
+
33
+ export { rest };
@@ -0,0 +1,33 @@
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, start?: number): (...args: any[]) => ReturnType<F>;
32
+
33
+ export { rest };
@@ -0,0 +1,11 @@
1
+ import { rest as rest$1 } from '../../function/rest.mjs';
2
+
3
+ function rest(func, start = func.length - 1) {
4
+ start = Number.parseInt(start, 10);
5
+ if (Number.isNaN(start) || start < 0) {
6
+ start = func.length - 1;
7
+ }
8
+ return rest$1(func, start);
9
+ }
10
+
11
+ export { rest };
@@ -108,6 +108,7 @@ export { zipObjectDeep } from './array/zipObjectDeep.mjs';
108
108
  export { indexOf } from './array/indexOf.mjs';
109
109
  export { ary } from './function/ary.mjs';
110
110
  export { bind } from './function/bind.mjs';
111
+ export { rest } from './function/rest.mjs';
111
112
  export { get } from './object/get.mjs';
112
113
  export { set } from './object/set.mjs';
113
114
  export { has } from './object/has.mjs';
@@ -108,6 +108,7 @@ export { zipObjectDeep } from './array/zipObjectDeep.js';
108
108
  export { indexOf } from './array/indexOf.js';
109
109
  export { ary } from './function/ary.js';
110
110
  export { bind } from './function/bind.js';
111
+ export { rest } from './function/rest.js';
111
112
  export { get } from './object/get.js';
112
113
  export { set } from './object/set.js';
113
114
  export { has } from './object/has.js';
@@ -601,6 +601,14 @@ function bind(func, thisObj, ...partialArgs) {
601
601
  const bindPlaceholder = Symbol('bind.placeholder');
602
602
  bind.placeholder = bindPlaceholder;
603
603
 
604
+ function rest(func, start = func.length - 1) {
605
+ start = Number.parseInt(start, 10);
606
+ if (Number.isNaN(start) || start < 0) {
607
+ start = func.length - 1;
608
+ }
609
+ return function_index.rest(func, start);
610
+ }
611
+
604
612
  function identity(x) {
605
613
  return x;
606
614
  }
@@ -936,6 +944,7 @@ exports.orderBy = orderBy;
936
944
  exports.padEnd = padEnd;
937
945
  exports.padStart = padStart;
938
946
  exports.property = property;
947
+ exports.rest = rest;
939
948
  exports.set = set;
940
949
  exports.size = size;
941
950
  exports.startsWith = startsWith;
@@ -109,6 +109,7 @@ export { zipObjectDeep } from './array/zipObjectDeep.mjs';
109
109
  export { indexOf } from './array/indexOf.mjs';
110
110
  export { ary } from './function/ary.mjs';
111
111
  export { bind } from './function/bind.mjs';
112
+ export { rest } from './function/rest.mjs';
112
113
  export { get } from './object/get.mjs';
113
114
  export { set } from './object/set.mjs';
114
115
  export { has } from './object/has.mjs';
@@ -9,3 +9,4 @@ export { ary } from './ary.mjs';
9
9
  export { unary } from './unary.mjs';
10
10
  export { partial } from './partial.mjs';
11
11
  export { partialRight } from './partialRight.mjs';
12
+ export { rest } from './rest.mjs';
@@ -9,3 +9,4 @@ export { ary } from './ary.js';
9
9
  export { unary } from './unary.js';
10
10
  export { partial } from './partial.js';
11
11
  export { partialRight } from './partialRight.js';
12
+ export { rest } from './rest.js';
@@ -143,6 +143,17 @@ function partialRight(func, ...partialArgs) {
143
143
  const partialRightPlaceholder = Symbol('partialRight.placeholder');
144
144
  partialRight.placeholder = partialRightPlaceholder;
145
145
 
146
+ function rest(func, startIndex = func.length - 1) {
147
+ return function (...args) {
148
+ const rest = args.slice(startIndex);
149
+ const params = args.slice(0, startIndex);
150
+ while (params.length < startIndex) {
151
+ params.push(undefined);
152
+ }
153
+ return func.apply(this, [...params, rest]);
154
+ };
155
+ }
156
+
146
157
  exports.after = after;
147
158
  exports.ary = ary;
148
159
  exports.before = before;
@@ -152,5 +163,6 @@ exports.noop = noop;
152
163
  exports.once = once;
153
164
  exports.partial = partial;
154
165
  exports.partialRight = partialRight;
166
+ exports.rest = rest;
155
167
  exports.throttle = throttle;
156
168
  exports.unary = unary;
@@ -9,3 +9,4 @@ export { ary } from './ary.mjs';
9
9
  export { unary } from './unary.mjs';
10
10
  export { partial } from './partial.mjs';
11
11
  export { partialRight } from './partialRight.mjs';
12
+ export { rest } from './rest.mjs';
@@ -0,0 +1,33 @@
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 };
@@ -0,0 +1,33 @@
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 };
@@ -0,0 +1,12 @@
1
+ function rest(func, startIndex = func.length - 1) {
2
+ return function (...args) {
3
+ const rest = args.slice(startIndex);
4
+ const params = args.slice(0, startIndex);
5
+ while (params.length < startIndex) {
6
+ params.push(undefined);
7
+ }
8
+ return func.apply(this, [...params, rest]);
9
+ };
10
+ }
11
+
12
+ export { rest };
package/dist/index.d.mts CHANGED
@@ -64,6 +64,7 @@ export { ary } from './function/ary.mjs';
64
64
  export { unary } from './function/unary.mjs';
65
65
  export { partial } from './function/partial.mjs';
66
66
  export { partialRight } from './function/partialRight.mjs';
67
+ export { rest } from './function/rest.mjs';
67
68
  export { clamp } from './math/clamp.mjs';
68
69
  export { inRange } from './math/inRange.mjs';
69
70
  export { mean } from './math/mean.mjs';
package/dist/index.d.ts CHANGED
@@ -64,6 +64,7 @@ export { ary } from './function/ary.js';
64
64
  export { unary } from './function/unary.js';
65
65
  export { partial } from './function/partial.js';
66
66
  export { partialRight } from './function/partialRight.js';
67
+ export { rest } from './function/rest.js';
67
68
  export { clamp } from './math/clamp.js';
68
69
  export { inRange } from './math/inRange.js';
69
70
  export { mean } from './math/mean.js';
package/dist/index.js CHANGED
@@ -83,6 +83,7 @@ exports.noop = function_index.noop;
83
83
  exports.once = function_index.once;
84
84
  exports.partial = function_index.partial;
85
85
  exports.partialRight = function_index.partialRight;
86
+ exports.rest = function_index.rest;
86
87
  exports.throttle = function_index.throttle;
87
88
  exports.unary = function_index.unary;
88
89
  exports.clamp = math_index.clamp;
package/dist/index.mjs CHANGED
@@ -64,6 +64,7 @@ export { ary } from './function/ary.mjs';
64
64
  export { unary } from './function/unary.mjs';
65
65
  export { partial } from './function/partial.mjs';
66
66
  export { partialRight } from './function/partialRight.mjs';
67
+ export { rest } from './function/rest.mjs';
67
68
  export { clamp } from './math/clamp.mjs';
68
69
  export { inRange } from './math/inRange.mjs';
69
70
  export { mean } from './math/mean.mjs';
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.15.1-dev.445+50b48669",
4
+ "version": "1.15.1-dev.447+98af4a3a",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {