es-toolkit 1.17.0-dev.542 → 1.17.0-dev.543

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.
@@ -10,6 +10,8 @@
10
10
  * from which elements will be compared and filtered.
11
11
  * @param {T[]} secondArr - The array containing elements to be excluded from the first array.
12
12
  * Each element in this array will be checked against the first array, and if a match is found,
13
+ * @param arr
14
+ * @param {...any} values
13
15
  * that element will be excluded from the result.
14
16
  * @returns {T[]} A new array containing the elements that are present in the first array but not
15
17
  * in the second array.
@@ -10,6 +10,8 @@
10
10
  * from which elements will be compared and filtered.
11
11
  * @param {T[]} secondArr - The array containing elements to be excluded from the first array.
12
12
  * Each element in this array will be checked against the first array, and if a match is found,
13
+ * @param arr
14
+ * @param {...any} values
13
15
  * that element will be excluded from the result.
14
16
  * @returns {T[]} A new array containing the elements that are present in the first array but not
15
17
  * in the second array.
@@ -65,6 +65,7 @@ declare function some<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
65
65
  * @param {T[]} arr The array to iterate over.
66
66
  * @param {((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string} [predicate=identity] The function invoked per iteration.
67
67
  * If a property name or an object is provided it will be used to create a predicate function.
68
+ * @param guard
68
69
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
69
70
  *
70
71
  * @example
@@ -65,6 +65,7 @@ declare function some<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
65
65
  * @param {T[]} arr The array to iterate over.
66
66
  * @param {((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string} [predicate=identity] The function invoked per iteration.
67
67
  * If a property name or an object is provided it will be used to create a predicate function.
68
+ * @param guard
68
69
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
69
70
  *
70
71
  * @example
@@ -11,6 +11,30 @@
11
11
  * @param {K} key - The key of the method.
12
12
  * @param {...any} partialArgs - The arguments to be partially applied.
13
13
  * @returns {T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never} - Returns the new bound function.
14
+ *
15
+ * @example
16
+ * const object = {
17
+ * user: 'fred',
18
+ * greet: function (greeting, punctuation) {
19
+ * return greeting + ' ' + this.user + punctuation;
20
+ * },
21
+ * };
22
+ *
23
+ * let bound = bindKey(object, 'greet', 'hi');
24
+ * bound('!');
25
+ * // => 'hi fred!'
26
+ *
27
+ * object.greet = function (greeting, punctuation) {
28
+ * return greeting + 'ya ' + this.user + punctuation;
29
+ * };
30
+ *
31
+ * bound('!');
32
+ * // => 'hiya fred!'
33
+ *
34
+ * // Bound with placeholders.
35
+ * bound = bindKey(object, 'greet', bindKey.placeholder, '!');
36
+ * bound('hi');
37
+ * // => 'hiya fred!'
14
38
  */
15
39
  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
40
  declare namespace bindKey {
@@ -11,6 +11,30 @@
11
11
  * @param {K} key - The key of the method.
12
12
  * @param {...any} partialArgs - The arguments to be partially applied.
13
13
  * @returns {T[K] extends (...args: any[]) => any ? (...args: any[]) => ReturnType<T[K]> : never} - Returns the new bound function.
14
+ *
15
+ * @example
16
+ * const object = {
17
+ * user: 'fred',
18
+ * greet: function (greeting, punctuation) {
19
+ * return greeting + ' ' + this.user + punctuation;
20
+ * },
21
+ * };
22
+ *
23
+ * let bound = bindKey(object, 'greet', 'hi');
24
+ * bound('!');
25
+ * // => 'hi fred!'
26
+ *
27
+ * object.greet = function (greeting, punctuation) {
28
+ * return greeting + 'ya ' + this.user + punctuation;
29
+ * };
30
+ *
31
+ * bound('!');
32
+ * // => 'hiya fred!'
33
+ *
34
+ * // Bound with placeholders.
35
+ * bound = bindKey(object, 'greet', bindKey.placeholder, '!');
36
+ * bound('hi');
37
+ * // => 'hiya fred!'
14
38
  */
15
39
  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
40
  declare namespace bindKey {
@@ -61,7 +61,6 @@ 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';
65
64
  export { clamp } from '../math/clamp.mjs';
66
65
  export { inRange } from '../math/inRange.mjs';
67
66
  export { mean } from '../math/mean.mjs';
@@ -123,6 +122,7 @@ export { zipObjectDeep } from './array/zipObjectDeep.mjs';
123
122
  export { indexOf } from './array/indexOf.mjs';
124
123
  export { ary } from './function/ary.mjs';
125
124
  export { bind } from './function/bind.mjs';
125
+ export { bindKey } from './function/bindKey.mjs';
126
126
  export { rest } from './function/rest.mjs';
127
127
  export { spread } from './function/spread.mjs';
128
128
  export { attempt } from './function/attempt.mjs';
@@ -61,7 +61,6 @@ 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';
65
64
  export { clamp } from '../math/clamp.js';
66
65
  export { inRange } from '../math/inRange.js';
67
66
  export { mean } from '../math/mean.js';
@@ -123,6 +122,7 @@ export { zipObjectDeep } from './array/zipObjectDeep.js';
123
122
  export { indexOf } from './array/indexOf.js';
124
123
  export { ary } from './function/ary.js';
125
124
  export { bind } from './function/bind.js';
125
+ export { bindKey } from './function/bindKey.js';
126
126
  export { rest } from './function/rest.js';
127
127
  export { spread } from './function/spread.js';
128
128
  export { attempt } from './function/attempt.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 bindKey = require('../_chunk/bindKey-DwI1is.js');
7
+ const rest$1 = require('../_chunk/rest-CXt9w3.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 bindKey.ary(func, n);
648
+ return rest$1.ary(func, n);
649
649
  }
650
650
 
651
651
  function bind(func, thisObj, ...partialArgs) {
@@ -674,12 +674,38 @@ function bind(func, thisObj, ...partialArgs) {
674
674
  const bindPlaceholder = Symbol('bind.placeholder');
675
675
  bind.placeholder = bindPlaceholder;
676
676
 
677
+ function bindKey(object, key, ...partialArgs) {
678
+ const bound = function (...providedArgs) {
679
+ const args = [];
680
+ let startIndex = 0;
681
+ for (let i = 0; i < partialArgs.length; i++) {
682
+ const arg = partialArgs[i];
683
+ if (arg === bindKey.placeholder) {
684
+ args.push(providedArgs[startIndex++]);
685
+ }
686
+ else {
687
+ args.push(arg);
688
+ }
689
+ }
690
+ for (let i = startIndex; i < providedArgs.length; i++) {
691
+ args.push(providedArgs[i]);
692
+ }
693
+ if (this instanceof bound) {
694
+ return new object[key](...args);
695
+ }
696
+ return object[key].apply(object, args);
697
+ };
698
+ return bound;
699
+ }
700
+ const bindKeyPlaceholder = Symbol('bindKey.placeholder');
701
+ bindKey.placeholder = bindKeyPlaceholder;
702
+
677
703
  function rest(func, start = func.length - 1) {
678
704
  start = Number.parseInt(start, 10);
679
705
  if (Number.isNaN(start) || start < 0) {
680
706
  start = func.length - 1;
681
707
  }
682
- return bindKey.rest(func, start);
708
+ return rest$1.rest(func, start);
683
709
  }
684
710
 
685
711
  function spread(func, argsIndex = 0) {
@@ -833,7 +859,7 @@ function mergeWithDeep(target, source, merge, stack) {
833
859
  }
834
860
 
835
861
  function merge(object, ...sources) {
836
- return mergeWith(object, ...sources, bindKey.noop);
862
+ return mergeWith(object, ...sources, rest$1.noop);
837
863
  }
838
864
 
839
865
  function isArrayLike(value) {
@@ -987,18 +1013,17 @@ exports.TimeoutError = promise_index.TimeoutError;
987
1013
  exports.delay = promise_index.delay;
988
1014
  exports.timeout = promise_index.timeout;
989
1015
  exports.withTimeout = promise_index.withTimeout;
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;
1016
+ exports.after = rest$1.after;
1017
+ exports.before = rest$1.before;
1018
+ exports.debounce = rest$1.debounce;
1019
+ exports.memoize = rest$1.memoize;
1020
+ exports.negate = rest$1.negate;
1021
+ exports.noop = rest$1.noop;
1022
+ exports.once = rest$1.once;
1023
+ exports.partial = rest$1.partial;
1024
+ exports.partialRight = rest$1.partialRight;
1025
+ exports.throttle = rest$1.throttle;
1026
+ exports.unary = rest$1.unary;
1002
1027
  exports.clamp = math_index.clamp;
1003
1028
  exports.inRange = math_index.inRange;
1004
1029
  exports.mean = math_index.mean;
@@ -1044,6 +1069,7 @@ exports.upperFirst = string_index.upperFirst;
1044
1069
  exports.ary = ary;
1045
1070
  exports.attempt = attempt;
1046
1071
  exports.bind = bind;
1072
+ exports.bindKey = bindKey;
1047
1073
  exports.chunk = chunk;
1048
1074
  exports.concat = concat;
1049
1075
  exports.difference = difference;
@@ -61,7 +61,6 @@ 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';
65
64
  export { clamp } from '../math/clamp.mjs';
66
65
  export { inRange } from '../math/inRange.mjs';
67
66
  export { mean } from '../math/mean.mjs';
@@ -124,6 +123,7 @@ export { zipObjectDeep } from './array/zipObjectDeep.mjs';
124
123
  export { indexOf } from './array/indexOf.mjs';
125
124
  export { ary } from './function/ary.mjs';
126
125
  export { bind } from './function/bind.mjs';
126
+ export { bindKey } from './function/bindKey.mjs';
127
127
  export { rest } from './function/rest.mjs';
128
128
  export { spread } from './function/spread.mjs';
129
129
  export { attempt } from './function/attempt.mjs';
@@ -11,5 +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 { bindKey } from './bindKey.mjs';
15
14
  export { spread } from './spread.mjs';
@@ -11,5 +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 { bindKey } from './bindKey.js';
15
14
  export { spread } from './spread.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const bindKey = require('../_chunk/bindKey-DwI1is.js');
5
+ const rest = require('../_chunk/rest-CXt9w3.js');
6
6
 
7
7
  function spread(func) {
8
8
  return function (argsArr) {
@@ -10,18 +10,17 @@ function spread(func) {
10
10
  };
11
11
  }
12
12
 
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;
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;
27
26
  exports.spread = spread;
@@ -11,5 +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 { bindKey } from './bindKey.mjs';
15
14
  export { spread } from './spread.mjs';
package/dist/index.d.mts CHANGED
@@ -70,7 +70,6 @@ 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';
74
73
  export { spread } from './function/spread.mjs';
75
74
  export { clamp } from './math/clamp.mjs';
76
75
  export { inRange } from './math/inRange.mjs';
package/dist/index.d.ts CHANGED
@@ -70,7 +70,6 @@ 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';
74
73
  export { spread } from './function/spread.js';
75
74
  export { clamp } from './math/clamp.js';
76
75
  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 bindKey = require('./_chunk/bindKey-DwI1is.js');
8
+ const rest = require('./_chunk/rest-CXt9w3.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,20 +80,19 @@ 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 = 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;
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;
97
96
  exports.spread = function_index.spread;
98
97
  exports.clamp = math_index.clamp;
99
98
  exports.inRange = math_index.inRange;
package/dist/index.mjs CHANGED
@@ -70,7 +70,6 @@ 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';
74
73
  export { spread } from './function/spread.mjs';
75
74
  export { clamp } from './math/clamp.mjs';
76
75
  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.542+f1f55c8d",
4
+ "version": "1.17.0-dev.543+61d4acba",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
File without changes