es-toolkit 1.13.1-dev.384 → 1.13.1-dev.385

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.
@@ -1,10 +1,9 @@
1
1
  /**
2
- *
3
2
  * Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
4
3
  *
5
4
  * The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
6
5
  *
7
- * **Note:** Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
6
+ * Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
8
7
  *
9
8
  * @param {(...args: any[]) => any} func The function to bind.
10
9
  * @param {any} thisArg The `this` binding of `func`.
@@ -24,7 +23,7 @@
24
23
  * bound('hi');
25
24
  * // => 'hi fred!'
26
25
  */
27
- declare function bind(func: (...args: any[]) => any, thisArg?: any, ...partials: any[]): (...args: any[]) => any;
26
+ declare function bind<F extends Function>(func: F, thisObj?: unknown, ...partialArgs: any[]): F;
28
27
  declare namespace bind {
29
28
  var placeholder: symbol;
30
29
  }
@@ -1,10 +1,9 @@
1
1
  /**
2
- *
3
2
  * Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
4
3
  *
5
4
  * The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
6
5
  *
7
- * **Note:** Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
6
+ * Note: Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
8
7
  *
9
8
  * @param {(...args: any[]) => any} func The function to bind.
10
9
  * @param {any} thisArg The `this` binding of `func`.
@@ -24,7 +23,7 @@
24
23
  * bound('hi');
25
24
  * // => 'hi fred!'
26
25
  */
27
- declare function bind(func: (...args: any[]) => any, thisArg?: any, ...partials: any[]): (...args: any[]) => any;
26
+ declare function bind<F extends Function>(func: F, thisObj?: unknown, ...partialArgs: any[]): F;
28
27
  declare namespace bind {
29
28
  var placeholder: symbol;
30
29
  }
@@ -0,0 +1,26 @@
1
+ function bind(func, thisObj, ...partialArgs) {
2
+ const binded = function (...providedArgs) {
3
+ const args = [];
4
+ let startIndex = 0;
5
+ for (let i = 0; i < partialArgs.length; i++) {
6
+ const arg = partialArgs[i];
7
+ if (arg === bind.placeholder) {
8
+ args.push(providedArgs[startIndex++]);
9
+ }
10
+ else {
11
+ args.push(arg);
12
+ }
13
+ }
14
+ for (let i = startIndex; i < providedArgs.length; i++) {
15
+ args.push(providedArgs[i]);
16
+ }
17
+ if (this instanceof binded) {
18
+ return new func(...args);
19
+ }
20
+ return func.apply(thisObj, args);
21
+ };
22
+ return binded;
23
+ }
24
+ bind.placeholder = Symbol('bind.placeholder');
25
+
26
+ export { bind };
@@ -56,7 +56,6 @@ export { once } from '../function/once.mjs';
56
56
  export { throttle } from '../function/throttle.mjs';
57
57
  export { negate } from '../function/negate.mjs';
58
58
  export { unary } from '../function/unary.mjs';
59
- export { bind } from '../function/bind.mjs';
60
59
  export { clamp } from '../math/clamp.mjs';
61
60
  export { inRange } from '../math/inRange.mjs';
62
61
  export { mean } from '../math/mean.mjs';
@@ -106,6 +105,7 @@ export { flattenDeep } from './array/flattenDeep.mjs';
106
105
  export { flattenDepth } from './array/flattenDepth.mjs';
107
106
  export { zipObjectDeep } from './array/zipObjectDeep.mjs';
108
107
  export { ary } from './function/ary.mjs';
108
+ export { bind } from './function/bind.mjs';
109
109
  export { get } from './object/get.mjs';
110
110
  export { set } from './object/set.mjs';
111
111
  export { property } from './object/property.mjs';
@@ -56,7 +56,6 @@ export { once } from '../function/once.js';
56
56
  export { throttle } from '../function/throttle.js';
57
57
  export { negate } from '../function/negate.js';
58
58
  export { unary } from '../function/unary.js';
59
- export { bind } from '../function/bind.js';
60
59
  export { clamp } from '../math/clamp.js';
61
60
  export { inRange } from '../math/inRange.js';
62
61
  export { mean } from '../math/mean.js';
@@ -106,6 +105,7 @@ export { flattenDeep } from './array/flattenDeep.js';
106
105
  export { flattenDepth } from './array/flattenDepth.js';
107
106
  export { zipObjectDeep } from './array/zipObjectDeep.js';
108
107
  export { ary } from './function/ary.js';
108
+ export { bind } from './function/bind.js';
109
109
  export { get } from './object/get.js';
110
110
  export { set } from './object/set.js';
111
111
  export { property } from './object/property.js';
@@ -175,6 +175,31 @@ function ary(func, n = func.length, guard) {
175
175
  return function_index.ary(func, n);
176
176
  }
177
177
 
178
+ function bind(func, thisObj, ...partialArgs) {
179
+ const binded = function (...providedArgs) {
180
+ const args = [];
181
+ let startIndex = 0;
182
+ for (let i = 0; i < partialArgs.length; i++) {
183
+ const arg = partialArgs[i];
184
+ if (arg === bind.placeholder) {
185
+ args.push(providedArgs[startIndex++]);
186
+ }
187
+ else {
188
+ args.push(arg);
189
+ }
190
+ }
191
+ for (let i = startIndex; i < providedArgs.length; i++) {
192
+ args.push(providedArgs[i]);
193
+ }
194
+ if (this instanceof binded) {
195
+ return new func(...args);
196
+ }
197
+ return func.apply(thisObj, args);
198
+ };
199
+ return binded;
200
+ }
201
+ bind.placeholder = Symbol('bind.placeholder');
202
+
178
203
  const IS_PLAIN = /^\w*$/;
179
204
  const IS_DEEP = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
180
205
  function isDeepKey(key) {
@@ -471,7 +496,6 @@ exports.delay = promise_index.delay;
471
496
  exports.withTimeout = promise_index.withTimeout;
472
497
  exports.after = function_index.after;
473
498
  exports.before = function_index.before;
474
- exports.bind = function_index.bind;
475
499
  exports.debounce = function_index.debounce;
476
500
  exports.negate = function_index.negate;
477
501
  exports.noop = function_index.noop;
@@ -517,6 +541,7 @@ exports.padStart = string_index.padStart;
517
541
  exports.snakeCase = string_index.snakeCase;
518
542
  exports.startCase = string_index.startCase;
519
543
  exports.ary = ary;
544
+ exports.bind = bind;
520
545
  exports.chunk = chunk;
521
546
  exports.concat = concat;
522
547
  exports.difference = difference;
@@ -56,7 +56,6 @@ export { once } from '../function/once.mjs';
56
56
  export { throttle } from '../function/throttle.mjs';
57
57
  export { negate } from '../function/negate.mjs';
58
58
  export { unary } from '../function/unary.mjs';
59
- export { bind } from '../function/bind.mjs';
60
59
  export { clamp } from '../math/clamp.mjs';
61
60
  export { inRange } from '../math/inRange.mjs';
62
61
  export { mean } from '../math/mean.mjs';
@@ -106,6 +105,7 @@ export { flattenDeep } from './array/flattenDeep.mjs';
106
105
  export { flattenDepth } from './array/flattenDepth.mjs';
107
106
  export { zipObjectDeep } from './array/zipObjectDeep.mjs';
108
107
  export { ary } from './function/ary.mjs';
108
+ export { bind } from './function/bind.mjs';
109
109
  export { get } from './object/get.mjs';
110
110
  export { set } from './object/set.mjs';
111
111
  export { property } from './object/property.mjs';
@@ -7,4 +7,3 @@ export { throttle } from './throttle.mjs';
7
7
  export { negate } from './negate.mjs';
8
8
  export { ary } from './ary.mjs';
9
9
  export { unary } from './unary.mjs';
10
- export { bind } from './bind.mjs';
@@ -7,4 +7,3 @@ export { throttle } from './throttle.js';
7
7
  export { negate } from './negate.js';
8
8
  export { ary } from './ary.js';
9
9
  export { unary } from './unary.js';
10
- export { bind } from './bind.js';
@@ -97,31 +97,9 @@ function unary(func) {
97
97
  return ary(func, 1);
98
98
  }
99
99
 
100
- function bind(func, thisArg, ...partials) {
101
- const wrapper = function (...args) {
102
- let index = 0;
103
- const result = partials.map(bindArg => {
104
- if (bindArg === bind.placeholder) {
105
- return args[index++];
106
- }
107
- return bindArg;
108
- });
109
- for (let i = index; i < args.length; i++) {
110
- result.push(args[i]);
111
- }
112
- if (this instanceof wrapper) {
113
- return new func(...result);
114
- }
115
- return func.apply(thisArg, result);
116
- };
117
- return wrapper;
118
- }
119
- bind.placeholder = Symbol('bind.placeholder');
120
-
121
100
  exports.after = after;
122
101
  exports.ary = ary;
123
102
  exports.before = before;
124
- exports.bind = bind;
125
103
  exports.debounce = debounce;
126
104
  exports.negate = negate;
127
105
  exports.noop = noop;
@@ -7,4 +7,3 @@ export { throttle } from './throttle.mjs';
7
7
  export { negate } from './negate.mjs';
8
8
  export { ary } from './ary.mjs';
9
9
  export { unary } from './unary.mjs';
10
- export { bind } from './bind.mjs';
package/dist/index.d.mts CHANGED
@@ -62,7 +62,6 @@ export { throttle } from './function/throttle.mjs';
62
62
  export { negate } from './function/negate.mjs';
63
63
  export { ary } from './function/ary.mjs';
64
64
  export { unary } from './function/unary.mjs';
65
- export { bind } from './function/bind.mjs';
66
65
  export { clamp } from './math/clamp.mjs';
67
66
  export { inRange } from './math/inRange.mjs';
68
67
  export { mean } from './math/mean.mjs';
package/dist/index.d.ts CHANGED
@@ -62,7 +62,6 @@ export { throttle } from './function/throttle.js';
62
62
  export { negate } from './function/negate.js';
63
63
  export { ary } from './function/ary.js';
64
64
  export { unary } from './function/unary.js';
65
- export { bind } from './function/bind.js';
66
65
  export { clamp } from './math/clamp.js';
67
66
  export { inRange } from './math/inRange.js';
68
67
  export { mean } from './math/mean.js';
package/dist/index.js CHANGED
@@ -76,7 +76,6 @@ exports.withTimeout = promise_index.withTimeout;
76
76
  exports.after = function_index.after;
77
77
  exports.ary = function_index.ary;
78
78
  exports.before = function_index.before;
79
- exports.bind = function_index.bind;
80
79
  exports.debounce = function_index.debounce;
81
80
  exports.negate = function_index.negate;
82
81
  exports.noop = function_index.noop;
package/dist/index.mjs CHANGED
@@ -62,7 +62,6 @@ export { throttle } from './function/throttle.mjs';
62
62
  export { negate } from './function/negate.mjs';
63
63
  export { ary } from './function/ary.mjs';
64
64
  export { unary } from './function/unary.mjs';
65
- export { bind } from './function/bind.mjs';
66
65
  export { clamp } from './math/clamp.mjs';
67
66
  export { inRange } from './math/inRange.mjs';
68
67
  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.13.1-dev.384+11028f76",
4
+ "version": "1.13.1-dev.385+f6be4d7a",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1,22 +0,0 @@
1
- function bind(func, thisArg, ...partials) {
2
- const wrapper = function (...args) {
3
- let index = 0;
4
- const result = partials.map(bindArg => {
5
- if (bindArg === bind.placeholder) {
6
- return args[index++];
7
- }
8
- return bindArg;
9
- });
10
- for (let i = index; i < args.length; i++) {
11
- result.push(args[i]);
12
- }
13
- if (this instanceof wrapper) {
14
- return new func(...result);
15
- }
16
- return func.apply(thisArg, result);
17
- };
18
- return wrapper;
19
- }
20
- bind.placeholder = Symbol('bind.placeholder');
21
-
22
- export { bind };