es-toolkit 1.17.0-dev.508 → 1.17.0-dev.509

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,11 @@
1
+ /**
2
+ * Creates a function that invokes `func` with the `this` binding of the create function and an array of arguments much like `Function#apply`.
3
+ *
4
+ * @template F The type of the function to spread arguments over.
5
+ * @param {F} func The function to spread arguments over.
6
+ * @param {number} startIndex The start position of the spread.
7
+ * @returns {(...args: any[]) => ReturnType<F>} A new function that invokes `func` with the spread arguments.
8
+ */
9
+ declare function spread<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
10
+
11
+ export { spread };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a function that invokes `func` with the `this` binding of the create function and an array of arguments much like `Function#apply`.
3
+ *
4
+ * @template F The type of the function to spread arguments over.
5
+ * @param {F} func The function to spread arguments over.
6
+ * @param {number} startIndex The start position of the spread.
7
+ * @returns {(...args: any[]) => ReturnType<F>} A new function that invokes `func` with the spread arguments.
8
+ */
9
+ declare function spread<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
10
+
11
+ export { spread };
@@ -0,0 +1,11 @@
1
+ import { spread as spread$1 } from '../../function/spread.mjs';
2
+
3
+ function spread(func, startIndex = 0) {
4
+ startIndex = Number.parseInt(startIndex, 10);
5
+ if (Number.isNaN(startIndex) || startIndex < 0) {
6
+ startIndex = 0;
7
+ }
8
+ return spread$1(func, startIndex);
9
+ }
10
+
11
+ export { spread };
@@ -116,6 +116,7 @@ export { indexOf } from './array/indexOf.mjs';
116
116
  export { ary } from './function/ary.mjs';
117
117
  export { bind } from './function/bind.mjs';
118
118
  export { rest } from './function/rest.mjs';
119
+ export { spread } from './function/spread.mjs';
119
120
  export { get } from './object/get.mjs';
120
121
  export { set } from './object/set.mjs';
121
122
  export { has } from './object/has.mjs';
@@ -116,6 +116,7 @@ export { indexOf } from './array/indexOf.js';
116
116
  export { ary } from './function/ary.js';
117
117
  export { bind } from './function/bind.js';
118
118
  export { rest } from './function/rest.js';
119
+ export { spread } from './function/spread.js';
119
120
  export { get } from './object/get.js';
120
121
  export { set } from './object/set.js';
121
122
  export { has } from './object/has.js';
@@ -611,6 +611,14 @@ function rest(func, start = func.length - 1) {
611
611
  return function_index.rest(func, start);
612
612
  }
613
613
 
614
+ function spread(func, startIndex = 0) {
615
+ startIndex = Number.parseInt(startIndex, 10);
616
+ if (Number.isNaN(startIndex) || startIndex < 0) {
617
+ startIndex = 0;
618
+ }
619
+ return function_index.spread(func, startIndex);
620
+ }
621
+
614
622
  function identity(x) {
615
623
  return x;
616
624
  }
@@ -961,5 +969,6 @@ exports.property = property;
961
969
  exports.rest = rest;
962
970
  exports.set = set;
963
971
  exports.size = size;
972
+ exports.spread = spread;
964
973
  exports.startsWith = startsWith;
965
974
  exports.zipObjectDeep = zipObjectDeep;
@@ -117,6 +117,7 @@ export { indexOf } from './array/indexOf.mjs';
117
117
  export { ary } from './function/ary.mjs';
118
118
  export { bind } from './function/bind.mjs';
119
119
  export { rest } from './function/rest.mjs';
120
+ export { spread } from './function/spread.mjs';
120
121
  export { get } from './object/get.mjs';
121
122
  export { set } from './object/set.mjs';
122
123
  export { has } from './object/has.mjs';
@@ -11,3 +11,4 @@ export { unary } from './unary.mjs';
11
11
  export { partial } from './partial.mjs';
12
12
  export { partialRight } from './partialRight.mjs';
13
13
  export { rest } from './rest.mjs';
14
+ export { spread } from './spread.mjs';
@@ -11,3 +11,4 @@ export { unary } from './unary.js';
11
11
  export { partial } from './partial.js';
12
12
  export { partialRight } from './partialRight.js';
13
13
  export { rest } from './rest.js';
14
+ export { spread } from './spread.js';
@@ -169,6 +169,17 @@ function rest(func, startIndex = func.length - 1) {
169
169
  };
170
170
  }
171
171
 
172
+ function spread(func, startIndex = 0) {
173
+ return function (...args) {
174
+ const array = args[startIndex];
175
+ const params = args.slice(0, startIndex);
176
+ if (array) {
177
+ params.push(...array);
178
+ }
179
+ return func.apply(this, params);
180
+ };
181
+ }
182
+
172
183
  exports.after = after;
173
184
  exports.ary = ary;
174
185
  exports.before = before;
@@ -180,5 +191,6 @@ exports.once = once;
180
191
  exports.partial = partial;
181
192
  exports.partialRight = partialRight;
182
193
  exports.rest = rest;
194
+ exports.spread = spread;
183
195
  exports.throttle = throttle;
184
196
  exports.unary = unary;
@@ -11,3 +11,4 @@ export { unary } from './unary.mjs';
11
11
  export { partial } from './partial.mjs';
12
12
  export { partialRight } from './partialRight.mjs';
13
13
  export { rest } from './rest.mjs';
14
+ export { spread } from './spread.mjs';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a function that invokes `func` with the `this` binding of the create function and an array of arguments much like `Function#apply`.
3
+ *
4
+ * @template F The type of the function to spread arguments over.
5
+ * @param {F} func The function to spread arguments over.
6
+ * @param {number} startIndex The start position of the spread.
7
+ * @returns {(...args: any[]) => ReturnType<F>} A new function that invokes `func` with the spread arguments.
8
+ */
9
+ declare function spread<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
10
+
11
+ export { spread };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a function that invokes `func` with the `this` binding of the create function and an array of arguments much like `Function#apply`.
3
+ *
4
+ * @template F The type of the function to spread arguments over.
5
+ * @param {F} func The function to spread arguments over.
6
+ * @param {number} startIndex The start position of the spread.
7
+ * @returns {(...args: any[]) => ReturnType<F>} A new function that invokes `func` with the spread arguments.
8
+ */
9
+ declare function spread<F extends (...args: any[]) => any>(func: F, startIndex?: number): (...args: any[]) => ReturnType<F>;
10
+
11
+ export { spread };
@@ -0,0 +1,12 @@
1
+ function spread(func, startIndex = 0) {
2
+ return function (...args) {
3
+ const array = args[startIndex];
4
+ const params = args.slice(0, startIndex);
5
+ if (array) {
6
+ params.push(...array);
7
+ }
8
+ return func.apply(this, params);
9
+ };
10
+ }
11
+
12
+ export { spread };
package/dist/index.d.mts CHANGED
@@ -68,6 +68,7 @@ export { unary } from './function/unary.mjs';
68
68
  export { partial } from './function/partial.mjs';
69
69
  export { partialRight } from './function/partialRight.mjs';
70
70
  export { rest } from './function/rest.mjs';
71
+ export { spread } from './function/spread.mjs';
71
72
  export { clamp } from './math/clamp.mjs';
72
73
  export { inRange } from './math/inRange.mjs';
73
74
  export { mean } from './math/mean.mjs';
package/dist/index.d.ts CHANGED
@@ -68,6 +68,7 @@ export { unary } from './function/unary.js';
68
68
  export { partial } from './function/partial.js';
69
69
  export { partialRight } from './function/partialRight.js';
70
70
  export { rest } from './function/rest.js';
71
+ export { spread } from './function/spread.js';
71
72
  export { clamp } from './math/clamp.js';
72
73
  export { inRange } from './math/inRange.js';
73
74
  export { mean } from './math/mean.js';
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ exports.once = function_index.once;
88
88
  exports.partial = function_index.partial;
89
89
  exports.partialRight = function_index.partialRight;
90
90
  exports.rest = function_index.rest;
91
+ exports.spread = function_index.spread;
91
92
  exports.throttle = function_index.throttle;
92
93
  exports.unary = function_index.unary;
93
94
  exports.clamp = math_index.clamp;
package/dist/index.mjs CHANGED
@@ -68,6 +68,7 @@ export { unary } from './function/unary.mjs';
68
68
  export { partial } from './function/partial.mjs';
69
69
  export { partialRight } from './function/partialRight.mjs';
70
70
  export { rest } from './function/rest.mjs';
71
+ export { spread } from './function/spread.mjs';
71
72
  export { clamp } from './math/clamp.mjs';
72
73
  export { inRange } from './math/inRange.mjs';
73
74
  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.17.0-dev.508+5bccc517",
4
+ "version": "1.17.0-dev.509+1c748480",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {