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.
@@ -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
  *
@@ -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';
@@ -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';
@@ -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 rest$1 = require('../_chunk/rest-CXt9w3.js');
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 rest$1.ary(func, n);
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 rest$1.rest(func, start);
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, rest$1.noop);
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 = rest$1.after;
991
- exports.before = rest$1.before;
992
- exports.debounce = rest$1.debounce;
993
- exports.memoize = rest$1.memoize;
994
- exports.negate = rest$1.negate;
995
- exports.noop = rest$1.noop;
996
- exports.once = rest$1.once;
997
- exports.partial = rest$1.partial;
998
- exports.partialRight = rest$1.partialRight;
999
- exports.throttle = rest$1.throttle;
1000
- exports.unary = rest$1.unary;
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;
@@ -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 };
@@ -11,4 +11,5 @@ 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 { bindKey } from './bindKey.mjs';
14
15
  export { spread } from './spread.mjs';
@@ -11,4 +11,5 @@ 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 { bindKey } from './bindKey.js';
14
15
  export { spread } from './spread.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const rest = require('../_chunk/rest-CXt9w3.js');
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 = rest.after;
14
- exports.ary = rest.ary;
15
- exports.before = rest.before;
16
- exports.debounce = rest.debounce;
17
- exports.memoize = rest.memoize;
18
- exports.negate = rest.negate;
19
- exports.noop = rest.noop;
20
- exports.once = rest.once;
21
- exports.partial = rest.partial;
22
- exports.partialRight = rest.partialRight;
23
- exports.rest = rest.rest;
24
- exports.throttle = rest.throttle;
25
- exports.unary = rest.unary;
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;
@@ -11,4 +11,5 @@ 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 { bindKey } from './bindKey.mjs';
14
15
  export { spread } from './spread.mjs';
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 rest = require('./_chunk/rest-CXt9w3.js');
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 = rest.after;
84
- exports.ary = rest.ary;
85
- exports.before = rest.before;
86
- exports.debounce = rest.debounce;
87
- exports.memoize = rest.memoize;
88
- exports.negate = rest.negate;
89
- exports.noop = rest.noop;
90
- exports.once = rest.once;
91
- exports.partial = rest.partial;
92
- exports.partialRight = rest.partialRight;
93
- exports.rest = rest.rest;
94
- exports.throttle = rest.throttle;
95
- exports.unary = rest.unary;
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.540+03005244",
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": {