es-toolkit 1.17.0-dev.540 → 1.17.0-dev.542
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/_chunk/{rest-CXt9w3.js → bindKey-DwI1is.js} +27 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/some.d.mts +11 -0
- package/dist/compat/array/some.d.ts +11 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +16 -15
- package/dist/compat/index.mjs +1 -0
- package/dist/function/bindKey.d.mts +21 -0
- package/dist/function/bindKey.d.ts +21 -0
- package/dist/function/bindKey.mjs +27 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +15 -14
- 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 +15 -14
- package/dist/index.mjs +1 -0
- package/package.json +1 -1
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if there is an element in an array that is truthy.
|
|
3
|
+
*
|
|
4
|
+
* @param {T[]} arr The array to iterate over.
|
|
5
|
+
* @returns {boolean} Returns `true` if any element is truthy, else `false`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* some([1, 2, 3, 4]);
|
|
9
|
+
* // => true
|
|
10
|
+
*/
|
|
11
|
+
declare function some<T>(arr: readonly T[]): boolean;
|
|
1
12
|
/**
|
|
2
13
|
* Checks if there is an element in an array that matches the given predicate function.
|
|
3
14
|
*
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if there is an element in an array that is truthy.
|
|
3
|
+
*
|
|
4
|
+
* @param {T[]} arr The array to iterate over.
|
|
5
|
+
* @returns {boolean} Returns `true` if any element is truthy, else `false`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* some([1, 2, 3, 4]);
|
|
9
|
+
* // => true
|
|
10
|
+
*/
|
|
11
|
+
declare function some<T>(arr: readonly T[]): boolean;
|
|
1
12
|
/**
|
|
2
13
|
* Checks if there is an element in an array that matches the given predicate function.
|
|
3
14
|
*
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -61,6 +61,7 @@ export { MemoizeCache, memoize } from '../function/memoize.mjs';
|
|
|
61
61
|
export { unary } from '../function/unary.mjs';
|
|
62
62
|
export { partial } from '../function/partial.mjs';
|
|
63
63
|
export { partialRight } from '../function/partialRight.mjs';
|
|
64
|
+
export { bindKey } from '../function/bindKey.mjs';
|
|
64
65
|
export { clamp } from '../math/clamp.mjs';
|
|
65
66
|
export { inRange } from '../math/inRange.mjs';
|
|
66
67
|
export { mean } from '../math/mean.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export { MemoizeCache, memoize } from '../function/memoize.js';
|
|
|
61
61
|
export { unary } from '../function/unary.js';
|
|
62
62
|
export { partial } from '../function/partial.js';
|
|
63
63
|
export { partialRight } from '../function/partialRight.js';
|
|
64
|
+
export { bindKey } from '../function/bindKey.js';
|
|
64
65
|
export { clamp } from '../math/clamp.js';
|
|
65
66
|
export { inRange } from '../math/inRange.js';
|
|
66
67
|
export { mean } from '../math/mean.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
|
|
5
5
|
const zipWith = require('../_chunk/zipWith-CaTQLt.js');
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
|
-
const
|
|
7
|
+
const bindKey = require('../_chunk/bindKey-DwI1is.js');
|
|
8
8
|
const math_index = require('../math/index.js');
|
|
9
9
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
10
10
|
const toMerged = require('../_chunk/toMerged-DN1PPP.js');
|
|
@@ -645,7 +645,7 @@ function ary(func, n = func.length, guard) {
|
|
|
645
645
|
if (Number.isNaN(n) || n < 0) {
|
|
646
646
|
n = 0;
|
|
647
647
|
}
|
|
648
|
-
return
|
|
648
|
+
return bindKey.ary(func, n);
|
|
649
649
|
}
|
|
650
650
|
|
|
651
651
|
function bind(func, thisObj, ...partialArgs) {
|
|
@@ -679,7 +679,7 @@ function rest(func, start = func.length - 1) {
|
|
|
679
679
|
if (Number.isNaN(start) || start < 0) {
|
|
680
680
|
start = func.length - 1;
|
|
681
681
|
}
|
|
682
|
-
return
|
|
682
|
+
return bindKey.rest(func, start);
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
function spread(func, argsIndex = 0) {
|
|
@@ -833,7 +833,7 @@ function mergeWithDeep(target, source, merge, stack) {
|
|
|
833
833
|
}
|
|
834
834
|
|
|
835
835
|
function merge(object, ...sources) {
|
|
836
|
-
return mergeWith(object, ...sources,
|
|
836
|
+
return mergeWith(object, ...sources, bindKey.noop);
|
|
837
837
|
}
|
|
838
838
|
|
|
839
839
|
function isArrayLike(value) {
|
|
@@ -987,17 +987,18 @@ exports.TimeoutError = promise_index.TimeoutError;
|
|
|
987
987
|
exports.delay = promise_index.delay;
|
|
988
988
|
exports.timeout = promise_index.timeout;
|
|
989
989
|
exports.withTimeout = promise_index.withTimeout;
|
|
990
|
-
exports.after =
|
|
991
|
-
exports.before =
|
|
992
|
-
exports.
|
|
993
|
-
exports.
|
|
994
|
-
exports.
|
|
995
|
-
exports.
|
|
996
|
-
exports.
|
|
997
|
-
exports.
|
|
998
|
-
exports.
|
|
999
|
-
exports.
|
|
1000
|
-
exports.
|
|
990
|
+
exports.after = bindKey.after;
|
|
991
|
+
exports.before = bindKey.before;
|
|
992
|
+
exports.bindKey = bindKey.bindKey;
|
|
993
|
+
exports.debounce = bindKey.debounce;
|
|
994
|
+
exports.memoize = bindKey.memoize;
|
|
995
|
+
exports.negate = bindKey.negate;
|
|
996
|
+
exports.noop = bindKey.noop;
|
|
997
|
+
exports.once = bindKey.once;
|
|
998
|
+
exports.partial = bindKey.partial;
|
|
999
|
+
exports.partialRight = bindKey.partialRight;
|
|
1000
|
+
exports.throttle = bindKey.throttle;
|
|
1001
|
+
exports.unary = bindKey.unary;
|
|
1001
1002
|
exports.clamp = math_index.clamp;
|
|
1002
1003
|
exports.inRange = math_index.inRange;
|
|
1003
1004
|
exports.mean = math_index.mean;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -61,6 +61,7 @@ export { memoize } from '../function/memoize.mjs';
|
|
|
61
61
|
export { unary } from '../function/unary.mjs';
|
|
62
62
|
export { partial } from '../function/partial.mjs';
|
|
63
63
|
export { partialRight } from '../function/partialRight.mjs';
|
|
64
|
+
export { bindKey } from '../function/bindKey.mjs';
|
|
64
65
|
export { clamp } from '../math/clamp.mjs';
|
|
65
66
|
export { inRange } from '../math/inRange.mjs';
|
|
66
67
|
export { mean } from '../math/mean.mjs';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
|
|
3
|
+
*
|
|
4
|
+
* This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
|
|
5
|
+
*
|
|
6
|
+
* The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object to bind.
|
|
9
|
+
* @template K - The type of the key to bind.
|
|
10
|
+
* @param {T} object - The object to invoke the method on.
|
|
11
|
+
* @param {K} key - The key of the method.
|
|
12
|
+
* @param {...any} partialArgs - The arguments to be partially applied.
|
|
13
|
+
* @returns {T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never} - Returns the new bound function.
|
|
14
|
+
*/
|
|
15
|
+
declare function bindKey<T extends Record<PropertyKey, any>, K extends keyof T>(object: T, key: K, ...partialArgs: any[]): T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never;
|
|
16
|
+
declare namespace bindKey {
|
|
17
|
+
var placeholder: typeof bindKeyPlaceholder;
|
|
18
|
+
}
|
|
19
|
+
declare const bindKeyPlaceholder: unique symbol;
|
|
20
|
+
|
|
21
|
+
export { bindKey };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that invokes the method at `object[key]` with `partialArgs` prepended to the arguments it receives.
|
|
3
|
+
*
|
|
4
|
+
* This method differs from `bind` by allowing bound functions to reference methods that may be redefined or don't yet exist.
|
|
5
|
+
*
|
|
6
|
+
* The `bindKey.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of the object to bind.
|
|
9
|
+
* @template K - The type of the key to bind.
|
|
10
|
+
* @param {T} object - The object to invoke the method on.
|
|
11
|
+
* @param {K} key - The key of the method.
|
|
12
|
+
* @param {...any} partialArgs - The arguments to be partially applied.
|
|
13
|
+
* @returns {T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never} - Returns the new bound function.
|
|
14
|
+
*/
|
|
15
|
+
declare function bindKey<T extends Record<PropertyKey, any>, K extends keyof T>(object: T, key: K, ...partialArgs: any[]): T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never;
|
|
16
|
+
declare namespace bindKey {
|
|
17
|
+
var placeholder: typeof bindKeyPlaceholder;
|
|
18
|
+
}
|
|
19
|
+
declare const bindKeyPlaceholder: unique symbol;
|
|
20
|
+
|
|
21
|
+
export { bindKey };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function bindKey(object, key, ...partialArgs) {
|
|
2
|
+
const bound = 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 === bindKey.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 bound) {
|
|
18
|
+
return new object[key](...args);
|
|
19
|
+
}
|
|
20
|
+
return object[key].apply(object, args);
|
|
21
|
+
};
|
|
22
|
+
return bound;
|
|
23
|
+
}
|
|
24
|
+
const bindKeyPlaceholder = Symbol('bindKey.placeholder');
|
|
25
|
+
bindKey.placeholder = bindKeyPlaceholder;
|
|
26
|
+
|
|
27
|
+
export { bindKey };
|
package/dist/function/index.d.ts
CHANGED
package/dist/function/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const bindKey = require('../_chunk/bindKey-DwI1is.js');
|
|
6
6
|
|
|
7
7
|
function spread(func) {
|
|
8
8
|
return function (argsArr) {
|
|
@@ -10,17 +10,18 @@ function spread(func) {
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
exports.after =
|
|
14
|
-
exports.ary =
|
|
15
|
-
exports.before =
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
13
|
+
exports.after = bindKey.after;
|
|
14
|
+
exports.ary = bindKey.ary;
|
|
15
|
+
exports.before = bindKey.before;
|
|
16
|
+
exports.bindKey = bindKey.bindKey;
|
|
17
|
+
exports.debounce = bindKey.debounce;
|
|
18
|
+
exports.memoize = bindKey.memoize;
|
|
19
|
+
exports.negate = bindKey.negate;
|
|
20
|
+
exports.noop = bindKey.noop;
|
|
21
|
+
exports.once = bindKey.once;
|
|
22
|
+
exports.partial = bindKey.partial;
|
|
23
|
+
exports.partialRight = bindKey.partialRight;
|
|
24
|
+
exports.rest = bindKey.rest;
|
|
25
|
+
exports.throttle = bindKey.throttle;
|
|
26
|
+
exports.unary = bindKey.unary;
|
|
26
27
|
exports.spread = spread;
|
package/dist/function/index.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -70,6 +70,7 @@ export { unary } from './function/unary.mjs';
|
|
|
70
70
|
export { partial } from './function/partial.mjs';
|
|
71
71
|
export { partialRight } from './function/partialRight.mjs';
|
|
72
72
|
export { rest } from './function/rest.mjs';
|
|
73
|
+
export { bindKey } from './function/bindKey.mjs';
|
|
73
74
|
export { spread } from './function/spread.mjs';
|
|
74
75
|
export { clamp } from './math/clamp.mjs';
|
|
75
76
|
export { inRange } from './math/inRange.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export { unary } from './function/unary.js';
|
|
|
70
70
|
export { partial } from './function/partial.js';
|
|
71
71
|
export { partialRight } from './function/partialRight.js';
|
|
72
72
|
export { rest } from './function/rest.js';
|
|
73
|
+
export { bindKey } from './function/bindKey.js';
|
|
73
74
|
export { spread } from './function/spread.js';
|
|
74
75
|
export { clamp } from './math/clamp.js';
|
|
75
76
|
export { inRange } from './math/inRange.js';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const zipWith = require('./_chunk/zipWith-CaTQLt.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
7
|
const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
8
|
-
const
|
|
8
|
+
const bindKey = require('./_chunk/bindKey-DwI1is.js');
|
|
9
9
|
const function_index = require('./function/index.js');
|
|
10
10
|
const math_index = require('./math/index.js');
|
|
11
11
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
@@ -80,19 +80,20 @@ exports.TimeoutError = promise_index.TimeoutError;
|
|
|
80
80
|
exports.delay = promise_index.delay;
|
|
81
81
|
exports.timeout = promise_index.timeout;
|
|
82
82
|
exports.withTimeout = promise_index.withTimeout;
|
|
83
|
-
exports.after =
|
|
84
|
-
exports.ary =
|
|
85
|
-
exports.before =
|
|
86
|
-
exports.
|
|
87
|
-
exports.
|
|
88
|
-
exports.
|
|
89
|
-
exports.
|
|
90
|
-
exports.
|
|
91
|
-
exports.
|
|
92
|
-
exports.
|
|
93
|
-
exports.
|
|
94
|
-
exports.
|
|
95
|
-
exports.
|
|
83
|
+
exports.after = bindKey.after;
|
|
84
|
+
exports.ary = bindKey.ary;
|
|
85
|
+
exports.before = bindKey.before;
|
|
86
|
+
exports.bindKey = bindKey.bindKey;
|
|
87
|
+
exports.debounce = bindKey.debounce;
|
|
88
|
+
exports.memoize = bindKey.memoize;
|
|
89
|
+
exports.negate = bindKey.negate;
|
|
90
|
+
exports.noop = bindKey.noop;
|
|
91
|
+
exports.once = bindKey.once;
|
|
92
|
+
exports.partial = bindKey.partial;
|
|
93
|
+
exports.partialRight = bindKey.partialRight;
|
|
94
|
+
exports.rest = bindKey.rest;
|
|
95
|
+
exports.throttle = bindKey.throttle;
|
|
96
|
+
exports.unary = bindKey.unary;
|
|
96
97
|
exports.spread = function_index.spread;
|
|
97
98
|
exports.clamp = math_index.clamp;
|
|
98
99
|
exports.inRange = math_index.inRange;
|
package/dist/index.mjs
CHANGED
|
@@ -70,6 +70,7 @@ export { unary } from './function/unary.mjs';
|
|
|
70
70
|
export { partial } from './function/partial.mjs';
|
|
71
71
|
export { partialRight } from './function/partialRight.mjs';
|
|
72
72
|
export { rest } from './function/rest.mjs';
|
|
73
|
+
export { bindKey } from './function/bindKey.mjs';
|
|
73
74
|
export { spread } from './function/spread.mjs';
|
|
74
75
|
export { clamp } from './math/clamp.mjs';
|
|
75
76
|
export { inRange } from './math/inRange.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.
|
|
4
|
+
"version": "1.17.0-dev.542+f1f55c8d",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|