es-toolkit 1.13.1-dev.368 → 1.13.1-dev.371
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.
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +1 -0
- package/dist/compat/index.mjs +1 -0
- package/dist/function/bind.d.mts +32 -0
- package/dist/function/bind.d.ts +32 -0
- package/dist/function/bind.mjs +22 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +22 -0
- package/dist/function/index.mjs +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -55,6 +55,7 @@ export { noop } from '../function/noop.mjs';
|
|
|
55
55
|
export { once } from '../function/once.mjs';
|
|
56
56
|
export { throttle } from '../function/throttle.mjs';
|
|
57
57
|
export { negate } from '../function/negate.mjs';
|
|
58
|
+
export { bind } from '../function/bind.mjs';
|
|
58
59
|
export { clamp } from '../math/clamp.mjs';
|
|
59
60
|
export { inRange } from '../math/inRange.mjs';
|
|
60
61
|
export { mean } from '../math/mean.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export { noop } from '../function/noop.js';
|
|
|
55
55
|
export { once } from '../function/once.js';
|
|
56
56
|
export { throttle } from '../function/throttle.js';
|
|
57
57
|
export { negate } from '../function/negate.js';
|
|
58
|
+
export { bind } from '../function/bind.js';
|
|
58
59
|
export { clamp } from '../math/clamp.js';
|
|
59
60
|
export { inRange } from '../math/inRange.js';
|
|
60
61
|
export { mean } from '../math/mean.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -462,6 +462,7 @@ exports.delay = promise_index.delay;
|
|
|
462
462
|
exports.withTimeout = promise_index.withTimeout;
|
|
463
463
|
exports.after = function_index.after;
|
|
464
464
|
exports.before = function_index.before;
|
|
465
|
+
exports.bind = function_index.bind;
|
|
465
466
|
exports.debounce = function_index.debounce;
|
|
466
467
|
exports.negate = function_index.negate;
|
|
467
468
|
exports.noop = function_index.noop;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -55,6 +55,7 @@ export { noop } from '../function/noop.mjs';
|
|
|
55
55
|
export { once } from '../function/once.mjs';
|
|
56
56
|
export { throttle } from '../function/throttle.mjs';
|
|
57
57
|
export { negate } from '../function/negate.mjs';
|
|
58
|
+
export { bind } from '../function/bind.mjs';
|
|
58
59
|
export { clamp } from '../math/clamp.mjs';
|
|
59
60
|
export { inRange } from '../math/inRange.mjs';
|
|
60
61
|
export { mean } from '../math/mean.mjs';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
|
|
4
|
+
*
|
|
5
|
+
* The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
|
|
6
|
+
*
|
|
7
|
+
* **Note:** Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
|
|
8
|
+
*
|
|
9
|
+
* @param {(...args: any[]) => any} func The function to bind.
|
|
10
|
+
* @param {any} thisArg The `this` binding of `func`.
|
|
11
|
+
* @param {any[]} partials The arguments to be partially applied.
|
|
12
|
+
* @returns {(...args: any[]) => any} Returns the new bound function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* function greet(greeting, punctuation) {
|
|
16
|
+
* return greeting + ' ' + this.user + punctuation;
|
|
17
|
+
* }
|
|
18
|
+
* const object = { user: 'fred' };
|
|
19
|
+
* let bound = bind(greet, object, 'hi');
|
|
20
|
+
* bound('!');
|
|
21
|
+
* // => 'hi fred!'
|
|
22
|
+
*
|
|
23
|
+
* bound = bind(greet, object, bind.placeholder, '!');
|
|
24
|
+
* bound('hi');
|
|
25
|
+
* // => 'hi fred!'
|
|
26
|
+
*/
|
|
27
|
+
declare function bind(func: (...args: any[]) => any, thisArg?: any, ...partials: any[]): (...args: any[]) => any;
|
|
28
|
+
declare namespace bind {
|
|
29
|
+
var placeholder: symbol;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { bind };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Creates a function that invokes `func` with the `this` binding of `thisArg` and `partials` prepended to the arguments it receives.
|
|
4
|
+
*
|
|
5
|
+
* The `bind.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
|
|
6
|
+
*
|
|
7
|
+
* **Note:** Unlike native `Function#bind`, this method doesn't set the `length` property of bound functions.
|
|
8
|
+
*
|
|
9
|
+
* @param {(...args: any[]) => any} func The function to bind.
|
|
10
|
+
* @param {any} thisArg The `this` binding of `func`.
|
|
11
|
+
* @param {any[]} partials The arguments to be partially applied.
|
|
12
|
+
* @returns {(...args: any[]) => any} Returns the new bound function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* function greet(greeting, punctuation) {
|
|
16
|
+
* return greeting + ' ' + this.user + punctuation;
|
|
17
|
+
* }
|
|
18
|
+
* const object = { user: 'fred' };
|
|
19
|
+
* let bound = bind(greet, object, 'hi');
|
|
20
|
+
* bound('!');
|
|
21
|
+
* // => 'hi fred!'
|
|
22
|
+
*
|
|
23
|
+
* bound = bind(greet, object, bind.placeholder, '!');
|
|
24
|
+
* bound('hi');
|
|
25
|
+
* // => 'hi fred!'
|
|
26
|
+
*/
|
|
27
|
+
declare function bind(func: (...args: any[]) => any, thisArg?: any, ...partials: any[]): (...args: any[]) => any;
|
|
28
|
+
declare namespace bind {
|
|
29
|
+
var placeholder: symbol;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { bind };
|
|
@@ -0,0 +1,22 @@
|
|
|
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 };
|
package/dist/function/index.d.ts
CHANGED
package/dist/function/index.js
CHANGED
|
@@ -87,8 +87,30 @@ function negate(func) {
|
|
|
87
87
|
return ((...args) => !func(...args));
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
function bind(func, thisArg, ...partials) {
|
|
91
|
+
const wrapper = function (...args) {
|
|
92
|
+
let index = 0;
|
|
93
|
+
const result = partials.map(bindArg => {
|
|
94
|
+
if (bindArg === bind.placeholder) {
|
|
95
|
+
return args[index++];
|
|
96
|
+
}
|
|
97
|
+
return bindArg;
|
|
98
|
+
});
|
|
99
|
+
for (let i = index; i < args.length; i++) {
|
|
100
|
+
result.push(args[i]);
|
|
101
|
+
}
|
|
102
|
+
if (this instanceof wrapper) {
|
|
103
|
+
return new func(...result);
|
|
104
|
+
}
|
|
105
|
+
return func.apply(thisArg, result);
|
|
106
|
+
};
|
|
107
|
+
return wrapper;
|
|
108
|
+
}
|
|
109
|
+
bind.placeholder = Symbol('bind.placeholder');
|
|
110
|
+
|
|
90
111
|
exports.after = after;
|
|
91
112
|
exports.before = before;
|
|
113
|
+
exports.bind = bind;
|
|
92
114
|
exports.debounce = debounce;
|
|
93
115
|
exports.negate = negate;
|
|
94
116
|
exports.noop = noop;
|
package/dist/function/index.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -60,6 +60,7 @@ export { noop } from './function/noop.mjs';
|
|
|
60
60
|
export { once } from './function/once.mjs';
|
|
61
61
|
export { throttle } from './function/throttle.mjs';
|
|
62
62
|
export { negate } from './function/negate.mjs';
|
|
63
|
+
export { bind } from './function/bind.mjs';
|
|
63
64
|
export { clamp } from './math/clamp.mjs';
|
|
64
65
|
export { inRange } from './math/inRange.mjs';
|
|
65
66
|
export { mean } from './math/mean.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export { noop } from './function/noop.js';
|
|
|
60
60
|
export { once } from './function/once.js';
|
|
61
61
|
export { throttle } from './function/throttle.js';
|
|
62
62
|
export { negate } from './function/negate.js';
|
|
63
|
+
export { bind } from './function/bind.js';
|
|
63
64
|
export { clamp } from './math/clamp.js';
|
|
64
65
|
export { inRange } from './math/inRange.js';
|
|
65
66
|
export { mean } from './math/mean.js';
|
package/dist/index.js
CHANGED
|
@@ -76,6 +76,7 @@ exports.delay = promise_index.delay;
|
|
|
76
76
|
exports.withTimeout = promise_index.withTimeout;
|
|
77
77
|
exports.after = function_index.after;
|
|
78
78
|
exports.before = function_index.before;
|
|
79
|
+
exports.bind = function_index.bind;
|
|
79
80
|
exports.debounce = function_index.debounce;
|
|
80
81
|
exports.negate = function_index.negate;
|
|
81
82
|
exports.noop = function_index.noop;
|
package/dist/index.mjs
CHANGED
|
@@ -60,6 +60,7 @@ export { noop } from './function/noop.mjs';
|
|
|
60
60
|
export { once } from './function/once.mjs';
|
|
61
61
|
export { throttle } from './function/throttle.mjs';
|
|
62
62
|
export { negate } from './function/negate.mjs';
|
|
63
|
+
export { bind } from './function/bind.mjs';
|
|
63
64
|
export { clamp } from './math/clamp.mjs';
|
|
64
65
|
export { inRange } from './math/inRange.mjs';
|
|
65
66
|
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.
|
|
4
|
+
"version": "1.13.1-dev.371+86fe776f",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|