es-toolkit 1.19.0-dev.605 → 1.19.0-dev.607

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.
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
3
+ * The arity of `func` may be specified if `func.length` is not sufficient.
4
+ *
5
+ * The `curry.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
6
+ *
7
+ * Note: This method doesn't set the `length` property of curried functions.
8
+ *
9
+ * @param {(...args: any[]) => any} func - The function to curry.
10
+ * @param {number=func.length} arity - The arity of func.
11
+ * @param {unknown} guard - Enables use as an iteratee for methods like `Array#map`.
12
+ * @returns {((...args: any[]) => any) & { placeholder: typeof curry.placeholder }} - Returns the new curried function.
13
+ *
14
+ * @example
15
+ * const abc = function(a, b, c) {
16
+ * return Array.from(arguments);
17
+ * };
18
+ *
19
+ * let curried = curry(abc);
20
+ *
21
+ * curried(1)(2)(3);
22
+ * // => [1, 2, 3]
23
+ *
24
+ * curried(1, 2)(3);
25
+ * // => [1, 2, 3]
26
+ *
27
+ * curried(1, 2, 3);
28
+ * // => [1, 2, 3]
29
+ *
30
+ * // Curried with placeholders.
31
+ * curried(1)(curry.placeholder, 3)(2);
32
+ * // => [1, 2, 3]
33
+ *
34
+ * // Curried with arity.
35
+ * curried = curry(abc, 2);
36
+ *
37
+ * curried(1)(2);
38
+ * // => [1, 2]
39
+ */
40
+ declare function curry(func: (...args: any[]) => any, arity?: number, guard?: unknown): ((...args: any[]) => any) & {
41
+ placeholder: typeof curry.placeholder;
42
+ };
43
+ declare namespace curry {
44
+ var placeholder: typeof curryPlaceholder;
45
+ }
46
+ declare const curryPlaceholder: unique symbol;
47
+
48
+ export { curry };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Creates a function that accepts arguments of `func` and either invokes `func` returning its result, if at least `arity` number of arguments have been provided, or returns a function that accepts the remaining `func` arguments, and so on.
3
+ * The arity of `func` may be specified if `func.length` is not sufficient.
4
+ *
5
+ * The `curry.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
6
+ *
7
+ * Note: This method doesn't set the `length` property of curried functions.
8
+ *
9
+ * @param {(...args: any[]) => any} func - The function to curry.
10
+ * @param {number=func.length} arity - The arity of func.
11
+ * @param {unknown} guard - Enables use as an iteratee for methods like `Array#map`.
12
+ * @returns {((...args: any[]) => any) & { placeholder: typeof curry.placeholder }} - Returns the new curried function.
13
+ *
14
+ * @example
15
+ * const abc = function(a, b, c) {
16
+ * return Array.from(arguments);
17
+ * };
18
+ *
19
+ * let curried = curry(abc);
20
+ *
21
+ * curried(1)(2)(3);
22
+ * // => [1, 2, 3]
23
+ *
24
+ * curried(1, 2)(3);
25
+ * // => [1, 2, 3]
26
+ *
27
+ * curried(1, 2, 3);
28
+ * // => [1, 2, 3]
29
+ *
30
+ * // Curried with placeholders.
31
+ * curried(1)(curry.placeholder, 3)(2);
32
+ * // => [1, 2, 3]
33
+ *
34
+ * // Curried with arity.
35
+ * curried = curry(abc, 2);
36
+ *
37
+ * curried(1)(2);
38
+ * // => [1, 2]
39
+ */
40
+ declare function curry(func: (...args: any[]) => any, arity?: number, guard?: unknown): ((...args: any[]) => any) & {
41
+ placeholder: typeof curry.placeholder;
42
+ };
43
+ declare namespace curry {
44
+ var placeholder: typeof curryPlaceholder;
45
+ }
46
+ declare const curryPlaceholder: unique symbol;
47
+
48
+ export { curry };
@@ -0,0 +1,65 @@
1
+ function curry(func, arity = func.length, guard) {
2
+ arity = guard ? func.length : arity;
3
+ arity = Number.parseInt(arity, 10);
4
+ if (Number.isNaN(arity) || arity < 1) {
5
+ arity = 0;
6
+ }
7
+ const wrapper = function (...partials) {
8
+ const holders = replaceHolders(partials);
9
+ const length = partials.length - holders.length;
10
+ if (length < arity) {
11
+ return makeCurry(func, holders, arity - length, partials);
12
+ }
13
+ if (this instanceof wrapper) {
14
+ return new func(...partials);
15
+ }
16
+ return func.apply(this, partials);
17
+ };
18
+ wrapper.placeholder = curryPlaceholder;
19
+ return wrapper;
20
+ }
21
+ function makeCurry(func, holders, arity, partials) {
22
+ function wrapper(...args) {
23
+ const holdersCount = args.filter(item => item === curry.placeholder).length;
24
+ const length = args.length - holdersCount;
25
+ args = composeArgs(args, partials, holders);
26
+ if (length < arity) {
27
+ const newHolders = replaceHolders(args);
28
+ return makeCurry(func, newHolders, arity - length, args);
29
+ }
30
+ if (this instanceof wrapper) {
31
+ return new func(...args);
32
+ }
33
+ return func.apply(this, args);
34
+ }
35
+ wrapper.placeholder = curryPlaceholder;
36
+ return wrapper;
37
+ }
38
+ function replaceHolders(args) {
39
+ const result = [];
40
+ for (let i = 0; i < args.length; i++) {
41
+ if (args[i] === curry.placeholder) {
42
+ result.push(i);
43
+ }
44
+ }
45
+ return result;
46
+ }
47
+ function composeArgs(args, partials, holders) {
48
+ const result = [...partials];
49
+ const argsLength = args.length;
50
+ const holdersLength = holders.length;
51
+ let argsIndex = -1, leftIndex = partials.length, rangeLength = Math.max(argsLength - holdersLength, 0);
52
+ while (++argsIndex < holdersLength) {
53
+ if (argsIndex < argsLength) {
54
+ result[holders[argsIndex]] = args[argsIndex];
55
+ }
56
+ }
57
+ while (rangeLength--) {
58
+ result[leftIndex++] = args[argsIndex++];
59
+ }
60
+ return result;
61
+ }
62
+ const curryPlaceholder = Symbol('curry.placeholder');
63
+ curry.placeholder = curryPlaceholder;
64
+
65
+ export { curry };
@@ -60,7 +60,6 @@ export { MemoizeCache, memoize } from '../function/memoize.mjs';
60
60
  export { unary } from '../function/unary.mjs';
61
61
  export { partial } from '../function/partial.mjs';
62
62
  export { partialRight } from '../function/partialRight.mjs';
63
- export { curry } from '../function/curry.mjs';
64
63
  export { clamp } from '../math/clamp.mjs';
65
64
  export { inRange } from '../math/inRange.mjs';
66
65
  export { mean } from '../math/mean.mjs';
@@ -124,6 +123,7 @@ export { rest } from './function/rest.mjs';
124
123
  export { spread } from './function/spread.mjs';
125
124
  export { attempt } from './function/attempt.mjs';
126
125
  export { rearg } from './function/rearg.mjs';
126
+ export { curry } from './function/curry.mjs';
127
127
  export { get } from './object/get.mjs';
128
128
  export { set } from './object/set.mjs';
129
129
  export { pick } from './object/pick.mjs';
@@ -60,7 +60,6 @@ export { MemoizeCache, memoize } from '../function/memoize.js';
60
60
  export { unary } from '../function/unary.js';
61
61
  export { partial } from '../function/partial.js';
62
62
  export { partialRight } from '../function/partialRight.js';
63
- export { curry } from '../function/curry.js';
64
63
  export { clamp } from '../math/clamp.js';
65
64
  export { inRange } from '../math/inRange.js';
66
65
  export { mean } from '../math/mean.js';
@@ -124,6 +123,7 @@ export { rest } from './function/rest.js';
124
123
  export { spread } from './function/spread.js';
125
124
  export { attempt } from './function/attempt.js';
126
125
  export { rearg } from './function/rearg.js';
126
+ export { curry } from './function/curry.js';
127
127
  export { get } from './object/get.js';
128
128
  export { set } from './object/set.js';
129
129
  export { pick } from './object/pick.js';
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const zipWith = require('../_chunk/zipWith-B-5AMf.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const curry = require('../_chunk/curry-BmwJrK.js');
7
+ const rest$1 = require('../_chunk/rest-CXt9w3.js');
8
8
  const range = require('../_chunk/range-BXlMmn.js');
9
9
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
10
10
  const toMerged = require('../_chunk/toMerged-Bzkqyz.js');
@@ -721,7 +721,7 @@ function ary(func, n = func.length, guard) {
721
721
  if (Number.isNaN(n) || n < 0) {
722
722
  n = 0;
723
723
  }
724
- return curry.ary(func, n);
724
+ return rest$1.ary(func, n);
725
725
  }
726
726
 
727
727
  function bind(func, thisObj, ...partialArgs) {
@@ -781,7 +781,7 @@ function rest(func, start = func.length - 1) {
781
781
  if (Number.isNaN(start) || start < 0) {
782
782
  start = func.length - 1;
783
783
  }
784
- return curry.rest(func, start);
784
+ return rest$1.rest(func, start);
785
785
  }
786
786
 
787
787
  function spread(func, argsIndex = 0) {
@@ -819,6 +819,70 @@ function rearg(func, ...indices) {
819
819
  };
820
820
  }
821
821
 
822
+ function curry(func, arity = func.length, guard) {
823
+ arity = guard ? func.length : arity;
824
+ arity = Number.parseInt(arity, 10);
825
+ if (Number.isNaN(arity) || arity < 1) {
826
+ arity = 0;
827
+ }
828
+ const wrapper = function (...partials) {
829
+ const holders = replaceHolders(partials);
830
+ const length = partials.length - holders.length;
831
+ if (length < arity) {
832
+ return makeCurry(func, holders, arity - length, partials);
833
+ }
834
+ if (this instanceof wrapper) {
835
+ return new func(...partials);
836
+ }
837
+ return func.apply(this, partials);
838
+ };
839
+ wrapper.placeholder = curryPlaceholder;
840
+ return wrapper;
841
+ }
842
+ function makeCurry(func, holders, arity, partials) {
843
+ function wrapper(...args) {
844
+ const holdersCount = args.filter(item => item === curry.placeholder).length;
845
+ const length = args.length - holdersCount;
846
+ args = composeArgs(args, partials, holders);
847
+ if (length < arity) {
848
+ const newHolders = replaceHolders(args);
849
+ return makeCurry(func, newHolders, arity - length, args);
850
+ }
851
+ if (this instanceof wrapper) {
852
+ return new func(...args);
853
+ }
854
+ return func.apply(this, args);
855
+ }
856
+ wrapper.placeholder = curryPlaceholder;
857
+ return wrapper;
858
+ }
859
+ function replaceHolders(args) {
860
+ const result = [];
861
+ for (let i = 0; i < args.length; i++) {
862
+ if (args[i] === curry.placeholder) {
863
+ result.push(i);
864
+ }
865
+ }
866
+ return result;
867
+ }
868
+ function composeArgs(args, partials, holders) {
869
+ const result = [...partials];
870
+ const argsLength = args.length;
871
+ const holdersLength = holders.length;
872
+ let argsIndex = -1, leftIndex = partials.length, rangeLength = Math.max(argsLength - holdersLength, 0);
873
+ while (++argsIndex < holdersLength) {
874
+ if (argsIndex < argsLength) {
875
+ result[holders[argsIndex]] = args[argsIndex];
876
+ }
877
+ }
878
+ while (rangeLength--) {
879
+ result[leftIndex++] = args[argsIndex++];
880
+ }
881
+ return result;
882
+ }
883
+ const curryPlaceholder = Symbol('curry.placeholder');
884
+ curry.placeholder = curryPlaceholder;
885
+
822
886
  function isNil(x) {
823
887
  return x == null;
824
888
  }
@@ -1085,7 +1149,7 @@ function mergeWithDeep(target, source, merge, stack) {
1085
1149
  }
1086
1150
 
1087
1151
  function merge(object, ...sources) {
1088
- return mergeWith(object, ...sources, curry.noop);
1152
+ return mergeWith(object, ...sources, rest$1.noop);
1089
1153
  }
1090
1154
 
1091
1155
  function isArrayLike(value) {
@@ -1418,18 +1482,17 @@ exports.TimeoutError = promise_index.TimeoutError;
1418
1482
  exports.delay = promise_index.delay;
1419
1483
  exports.timeout = promise_index.timeout;
1420
1484
  exports.withTimeout = promise_index.withTimeout;
1421
- exports.after = curry.after;
1422
- exports.before = curry.before;
1423
- exports.curry = curry.curry;
1424
- exports.debounce = curry.debounce;
1425
- exports.memoize = curry.memoize;
1426
- exports.negate = curry.negate;
1427
- exports.noop = curry.noop;
1428
- exports.once = curry.once;
1429
- exports.partial = curry.partial;
1430
- exports.partialRight = curry.partialRight;
1431
- exports.throttle = curry.throttle;
1432
- exports.unary = curry.unary;
1485
+ exports.after = rest$1.after;
1486
+ exports.before = rest$1.before;
1487
+ exports.debounce = rest$1.debounce;
1488
+ exports.memoize = rest$1.memoize;
1489
+ exports.negate = rest$1.negate;
1490
+ exports.noop = rest$1.noop;
1491
+ exports.once = rest$1.once;
1492
+ exports.partial = rest$1.partial;
1493
+ exports.partialRight = rest$1.partialRight;
1494
+ exports.throttle = rest$1.throttle;
1495
+ exports.unary = rest$1.unary;
1433
1496
  exports.clamp = range.clamp;
1434
1497
  exports.inRange = range.inRange;
1435
1498
  exports.mean = range.mean;
@@ -1477,6 +1540,7 @@ exports.chunk = chunk;
1477
1540
  exports.concat = concat;
1478
1541
  exports.conforms = conforms;
1479
1542
  exports.conformsTo = conformsTo;
1543
+ exports.curry = curry;
1480
1544
  exports.difference = difference;
1481
1545
  exports.endsWith = endsWith;
1482
1546
  exports.fill = fill;
@@ -60,7 +60,6 @@ export { memoize } from '../function/memoize.mjs';
60
60
  export { unary } from '../function/unary.mjs';
61
61
  export { partial } from '../function/partial.mjs';
62
62
  export { partialRight } from '../function/partialRight.mjs';
63
- export { curry } from '../function/curry.mjs';
64
63
  export { clamp } from '../math/clamp.mjs';
65
64
  export { inRange } from '../math/inRange.mjs';
66
65
  export { mean } from '../math/mean.mjs';
@@ -125,6 +124,7 @@ export { rest } from './function/rest.mjs';
125
124
  export { spread } from './function/spread.mjs';
126
125
  export { attempt } from './function/attempt.mjs';
127
126
  export { rearg } from './function/rearg.mjs';
127
+ export { curry } from './function/curry.mjs';
128
128
  export { get } from './object/get.mjs';
129
129
  export { set } from './object/set.mjs';
130
130
  export { pick } from './object/pick.mjs';
@@ -2,7 +2,27 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const curry = require('../_chunk/curry-BmwJrK.js');
5
+ const rest = require('../_chunk/rest-CXt9w3.js');
6
+
7
+ function curry(func) {
8
+ if (func.length === 0 || func.length === 1) {
9
+ return func;
10
+ }
11
+ return function (arg) {
12
+ return makeCurry(func, func.length, [arg]);
13
+ };
14
+ }
15
+ function makeCurry(origin, argsLength, args) {
16
+ if (args.length === argsLength) {
17
+ return origin(...args);
18
+ }
19
+ else {
20
+ const next = function (arg) {
21
+ return makeCurry(origin, argsLength, [...args, arg]);
22
+ };
23
+ return next;
24
+ }
25
+ }
6
26
 
7
27
  function spread(func) {
8
28
  return function (argsArr) {
@@ -10,18 +30,18 @@ function spread(func) {
10
30
  };
11
31
  }
12
32
 
13
- exports.after = curry.after;
14
- exports.ary = curry.ary;
15
- exports.before = curry.before;
16
- exports.curry = curry.curry;
17
- exports.debounce = curry.debounce;
18
- exports.memoize = curry.memoize;
19
- exports.negate = curry.negate;
20
- exports.noop = curry.noop;
21
- exports.once = curry.once;
22
- exports.partial = curry.partial;
23
- exports.partialRight = curry.partialRight;
24
- exports.rest = curry.rest;
25
- exports.throttle = curry.throttle;
26
- exports.unary = curry.unary;
33
+ exports.after = rest.after;
34
+ exports.ary = rest.ary;
35
+ exports.before = rest.before;
36
+ exports.debounce = rest.debounce;
37
+ exports.memoize = rest.memoize;
38
+ exports.negate = rest.negate;
39
+ exports.noop = rest.noop;
40
+ exports.once = rest.once;
41
+ exports.partial = rest.partial;
42
+ exports.partialRight = rest.partialRight;
43
+ exports.rest = rest.rest;
44
+ exports.throttle = rest.throttle;
45
+ exports.unary = rest.unary;
46
+ exports.curry = curry;
27
47
  exports.spread = spread;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  const zipWith = require('./_chunk/zipWith-B-5AMf.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
- const curry = require('./_chunk/curry-BmwJrK.js');
8
+ const rest = require('./_chunk/rest-CXt9w3.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const range = require('./_chunk/range-BXlMmn.js');
11
11
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
@@ -80,20 +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 = curry.after;
84
- exports.ary = curry.ary;
85
- exports.before = curry.before;
86
- exports.curry = curry.curry;
87
- exports.debounce = curry.debounce;
88
- exports.memoize = curry.memoize;
89
- exports.negate = curry.negate;
90
- exports.noop = curry.noop;
91
- exports.once = curry.once;
92
- exports.partial = curry.partial;
93
- exports.partialRight = curry.partialRight;
94
- exports.rest = curry.rest;
95
- exports.throttle = curry.throttle;
96
- exports.unary = curry.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;
96
+ exports.curry = function_index.curry;
97
97
  exports.spread = function_index.spread;
98
98
  exports.clamp = range.clamp;
99
99
  exports.inRange = range.inRange;
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.19.0-dev.605+9bb1203b",
4
+ "version": "1.19.0-dev.607+c92faba7",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {