es-toolkit 1.23.0-dev.735 → 1.23.0-dev.736

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,50 @@
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
+ * Unlike `curry`, this function curries the function from right to left.
6
+ *
7
+ * The `curryRight.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
8
+ *
9
+ * Note: This method doesn't set the `length` property of curried functions.
10
+ *
11
+ * @param {(...args: any[]) => any} func - The function to curry.
12
+ * @param {number=func.length} arity - The arity of func.
13
+ * @param {unknown} guard - Enables use as an iteratee for methods like `Array#map`.
14
+ * @returns {((...args: any[]) => any) & { placeholder: typeof curryRight.placeholder }} - Returns the new curried function.
15
+ *
16
+ * @example
17
+ * const abc = function(a, b, c) {
18
+ * return Array.from(arguments);
19
+ * };
20
+ *
21
+ * let curried = curryRight(abc);
22
+ *
23
+ * curried(3)(2)(1);
24
+ * // => [1, 2, 3]
25
+ *
26
+ * curried(2, 3)(1);
27
+ * // => [1, 2, 3]
28
+ *
29
+ * curried(1, 2, 3);
30
+ * // => [1, 2, 3]
31
+ *
32
+ * // Curried with placeholders.
33
+ * curried(3)(curryRight.placeholder, 2)(1);
34
+ * // => [1, 2, 3]
35
+ *
36
+ * // Curried with arity.
37
+ * curried = curryRight(abc, 2);
38
+ *
39
+ * curried(2)(1);
40
+ * // => [1, 2]
41
+ */
42
+ declare function curryRight(func: (...args: any[]) => any, arity?: number, guard?: unknown): ((...args: any[]) => any) & {
43
+ placeholder: typeof curryRight.placeholder;
44
+ };
45
+ declare namespace curryRight {
46
+ var placeholder: typeof curryRightPlaceholder;
47
+ }
48
+ declare const curryRightPlaceholder: unique symbol;
49
+
50
+ export { curryRight };
@@ -0,0 +1,50 @@
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
+ * Unlike `curry`, this function curries the function from right to left.
6
+ *
7
+ * The `curryRight.placeholder` value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
8
+ *
9
+ * Note: This method doesn't set the `length` property of curried functions.
10
+ *
11
+ * @param {(...args: any[]) => any} func - The function to curry.
12
+ * @param {number=func.length} arity - The arity of func.
13
+ * @param {unknown} guard - Enables use as an iteratee for methods like `Array#map`.
14
+ * @returns {((...args: any[]) => any) & { placeholder: typeof curryRight.placeholder }} - Returns the new curried function.
15
+ *
16
+ * @example
17
+ * const abc = function(a, b, c) {
18
+ * return Array.from(arguments);
19
+ * };
20
+ *
21
+ * let curried = curryRight(abc);
22
+ *
23
+ * curried(3)(2)(1);
24
+ * // => [1, 2, 3]
25
+ *
26
+ * curried(2, 3)(1);
27
+ * // => [1, 2, 3]
28
+ *
29
+ * curried(1, 2, 3);
30
+ * // => [1, 2, 3]
31
+ *
32
+ * // Curried with placeholders.
33
+ * curried(3)(curryRight.placeholder, 2)(1);
34
+ * // => [1, 2, 3]
35
+ *
36
+ * // Curried with arity.
37
+ * curried = curryRight(abc, 2);
38
+ *
39
+ * curried(2)(1);
40
+ * // => [1, 2]
41
+ */
42
+ declare function curryRight(func: (...args: any[]) => any, arity?: number, guard?: unknown): ((...args: any[]) => any) & {
43
+ placeholder: typeof curryRight.placeholder;
44
+ };
45
+ declare namespace curryRight {
46
+ var placeholder: typeof curryRightPlaceholder;
47
+ }
48
+ declare const curryRightPlaceholder: unique symbol;
49
+
50
+ export { curryRight };
@@ -0,0 +1,64 @@
1
+ function curryRight(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 (...partialArgs) {
8
+ const holders = partialArgs.filter(item => item === curryRight.placeholder);
9
+ const length = partialArgs.length - holders.length;
10
+ if (length < arity) {
11
+ return makeCurryRight(func, arity - length, partialArgs);
12
+ }
13
+ if (this instanceof wrapper) {
14
+ return new func(...partialArgs);
15
+ }
16
+ return func.apply(this, partialArgs);
17
+ };
18
+ wrapper.placeholder = curryRightPlaceholder;
19
+ return wrapper;
20
+ }
21
+ function makeCurryRight(func, arity, partialArgs) {
22
+ function wrapper(...providedArgs) {
23
+ const holders = providedArgs.filter(item => item === curryRight.placeholder);
24
+ const length = providedArgs.length - holders.length;
25
+ providedArgs = composeArgs(providedArgs, partialArgs);
26
+ if (length < arity) {
27
+ return makeCurryRight(func, arity - length, providedArgs);
28
+ }
29
+ if (this instanceof wrapper) {
30
+ return new func(...providedArgs);
31
+ }
32
+ return func.apply(this, providedArgs);
33
+ }
34
+ wrapper.placeholder = curryRightPlaceholder;
35
+ return wrapper;
36
+ }
37
+ function composeArgs(providedArgs, partialArgs) {
38
+ const placeholderLength = partialArgs.filter(arg => arg === curryRight.placeholder).length;
39
+ const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
40
+ const args = [];
41
+ let providedIndex = 0;
42
+ for (let i = 0; i < rangeLength; i++) {
43
+ args.push(providedArgs[providedIndex++]);
44
+ }
45
+ for (let i = 0; i < partialArgs.length; i++) {
46
+ const arg = partialArgs[i];
47
+ if (arg === curryRight.placeholder) {
48
+ if (providedIndex < providedArgs.length) {
49
+ args.push(providedArgs[providedIndex++]);
50
+ }
51
+ else {
52
+ args.push(arg);
53
+ }
54
+ }
55
+ else {
56
+ args.push(arg);
57
+ }
58
+ }
59
+ return args;
60
+ }
61
+ const curryRightPlaceholder = Symbol('curryRight.placeholder');
62
+ curryRight.placeholder = curryRightPlaceholder;
63
+
64
+ export { curryRight };
@@ -54,7 +54,6 @@ export { MemoizeCache, memoize } from '../function/memoize.mjs';
54
54
  export { unary } from '../function/unary.mjs';
55
55
  export { partial } from '../function/partial.mjs';
56
56
  export { partialRight } from '../function/partialRight.mjs';
57
- export { curryRight } from '../function/curryRight.mjs';
58
57
  export { mean } from '../math/mean.mjs';
59
58
  export { meanBy } from '../math/meanBy.mjs';
60
59
  export { randomInt } from '../math/randomInt.mjs';
@@ -125,6 +124,7 @@ export { spread } from './function/spread.mjs';
125
124
  export { attempt } from './function/attempt.mjs';
126
125
  export { rearg } from './function/rearg.mjs';
127
126
  export { curry } from './function/curry.mjs';
127
+ export { curryRight } from './function/curryRight.mjs';
128
128
  export { debounce } from './function/debounce.mjs';
129
129
  export { throttle } from './function/throttle.mjs';
130
130
  export { flip } from './function/flip.mjs';
@@ -54,7 +54,6 @@ export { MemoizeCache, memoize } from '../function/memoize.js';
54
54
  export { unary } from '../function/unary.js';
55
55
  export { partial } from '../function/partial.js';
56
56
  export { partialRight } from '../function/partialRight.js';
57
- export { curryRight } from '../function/curryRight.js';
58
57
  export { mean } from '../math/mean.js';
59
58
  export { meanBy } from '../math/meanBy.js';
60
59
  export { randomInt } from '../math/randomInt.js';
@@ -125,6 +124,7 @@ export { spread } from './function/spread.js';
125
124
  export { attempt } from './function/attempt.js';
126
125
  export { rearg } from './function/rearg.js';
127
126
  export { curry } from './function/curry.js';
127
+ export { curryRight } from './function/curryRight.js';
128
128
  export { debounce } from './function/debounce.js';
129
129
  export { throttle } from './function/throttle.js';
130
130
  export { flip } from './function/flip.js';
@@ -4,13 +4,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const zipWith = require('../_chunk/zipWith-EOU_KZ.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const flowRight$1 = require('../_chunk/flowRight-bRd7s5.js');
7
+ const flowRight$1 = require('../_chunk/flowRight-DFVdlB.js');
8
8
  const partialRight = require('../_chunk/partialRight-CRhV1h.js');
9
9
  const rangeRight = require('../_chunk/rangeRight-CtcxMd.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
11
  const isObjectLike = require('../_chunk/isObjectLike-aywuSF.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-DgrsU7.js');
13
- const isJSONObject = require('../_chunk/isJSONObject-XuEao3.js');
13
+ const isJSONObject = require('../_chunk/isJSONObject-CkW4Fc.js');
14
14
  const deburr = require('../_chunk/deburr-BPmkoM.js');
15
15
  const pad$1 = require('../_chunk/pad-Bgd7Ah.js');
16
16
 
@@ -1852,7 +1852,6 @@ exports.delay = promise_index.delay;
1852
1852
  exports.timeout = promise_index.timeout;
1853
1853
  exports.withTimeout = promise_index.withTimeout;
1854
1854
  exports.after = flowRight$1.after;
1855
- exports.curryRight = flowRight$1.curryRight;
1856
1855
  exports.memoize = flowRight$1.memoize;
1857
1856
  exports.negate = flowRight$1.negate;
1858
1857
  exports.once = flowRight$1.once;
@@ -1878,6 +1877,7 @@ exports.isPrimitive = isPlainObject$1.isPrimitive;
1878
1877
  exports.bind = isJSONObject.bind;
1879
1878
  exports.bindKey = isJSONObject.bindKey;
1880
1879
  exports.curry = isJSONObject.curry;
1880
+ exports.curryRight = isJSONObject.curryRight;
1881
1881
  exports.eq = isJSONObject.eq;
1882
1882
  exports.isDate = isJSONObject.isDate;
1883
1883
  exports.isEqual = isJSONObject.isEqual;
@@ -54,7 +54,6 @@ export { memoize } from '../function/memoize.mjs';
54
54
  export { unary } from '../function/unary.mjs';
55
55
  export { partial } from '../function/partial.mjs';
56
56
  export { partialRight } from '../function/partialRight.mjs';
57
- export { curryRight } from '../function/curryRight.mjs';
58
57
  export { mean } from '../math/mean.mjs';
59
58
  export { meanBy } from '../math/meanBy.mjs';
60
59
  export { randomInt } from '../math/randomInt.mjs';
@@ -106,6 +105,7 @@ export { spread } from './function/spread.mjs';
106
105
  export { attempt } from './function/attempt.mjs';
107
106
  export { rearg } from './function/rearg.mjs';
108
107
  export { curry } from './function/curry.mjs';
108
+ export { curryRight } from './function/curryRight.mjs';
109
109
  export { debounce } from './function/debounce.mjs';
110
110
  export { throttle } from './function/throttle.mjs';
111
111
  export { flip } from './function/flip.mjs';
@@ -4,6 +4,7 @@ import '../../string/deburr.mjs';
4
4
  import '../function/bind.mjs';
5
5
  import '../function/bindKey.mjs';
6
6
  import '../function/curry.mjs';
7
+ import '../function/curryRight.mjs';
7
8
  import { isMap as isMap$1 } from '../../predicate/isMap.mjs';
8
9
 
9
10
  function isMap(value) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const flowRight = require('../_chunk/flowRight-bRd7s5.js');
5
+ const flowRight = require('../_chunk/flowRight-DFVdlB.js');
6
6
  const partialRight = require('../_chunk/partialRight-CRhV1h.js');
7
7
 
8
8
  function before(n, func) {
@@ -59,6 +59,26 @@ function makeCurry(origin, argsLength, args) {
59
59
  }
60
60
  }
61
61
 
62
+ function curryRight(func) {
63
+ if (func.length === 0 || func.length === 1) {
64
+ return func;
65
+ }
66
+ return function (arg) {
67
+ return makeCurryRight(func, func.length, [arg]);
68
+ };
69
+ }
70
+ function makeCurryRight(origin, argsLength, args) {
71
+ if (args.length === argsLength) {
72
+ return origin(...args);
73
+ }
74
+ else {
75
+ const next = function (arg) {
76
+ return makeCurryRight(origin, argsLength, [arg, ...args]);
77
+ };
78
+ return next;
79
+ }
80
+ }
81
+
62
82
  function spread(func) {
63
83
  return function (argsArr) {
64
84
  return func.apply(this, argsArr);
@@ -67,7 +87,6 @@ function spread(func) {
67
87
 
68
88
  exports.after = flowRight.after;
69
89
  exports.ary = flowRight.ary;
70
- exports.curryRight = flowRight.curryRight;
71
90
  exports.debounce = flowRight.debounce;
72
91
  exports.flow = flowRight.flow;
73
92
  exports.flowRight = flowRight.flowRight;
@@ -81,5 +100,6 @@ exports.partial = partialRight.partial;
81
100
  exports.partialRight = partialRight.partialRight;
82
101
  exports.before = before;
83
102
  exports.curry = curry;
103
+ exports.curryRight = curryRight;
84
104
  exports.spread = spread;
85
105
  exports.throttle = throttle;
package/dist/index.js CHANGED
@@ -6,14 +6,14 @@ const zipWith = require('./_chunk/zipWith-EOU_KZ.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
8
  const function_index = require('./function/index.js');
9
- const flowRight = require('./_chunk/flowRight-bRd7s5.js');
9
+ const flowRight = require('./_chunk/flowRight-DFVdlB.js');
10
10
  const partialRight = require('./_chunk/partialRight-CRhV1h.js');
11
11
  const rangeRight = require('./_chunk/rangeRight-CtcxMd.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
14
  const object_index = require('./object/index.js');
15
15
  const isObjectLike = require('./_chunk/isObjectLike-aywuSF.js');
16
- const isJSONObject = require('./_chunk/isJSONObject-XuEao3.js');
16
+ const isJSONObject = require('./_chunk/isJSONObject-CkW4Fc.js');
17
17
  const predicate_index = require('./predicate/index.js');
18
18
  const isPlainObject = require('./_chunk/isPlainObject-DgrsU7.js');
19
19
  const pad = require('./_chunk/pad-Bgd7Ah.js');
@@ -85,11 +85,11 @@ exports.timeout = promise_index.timeout;
85
85
  exports.withTimeout = promise_index.withTimeout;
86
86
  exports.before = function_index.before;
87
87
  exports.curry = function_index.curry;
88
+ exports.curryRight = function_index.curryRight;
88
89
  exports.spread = function_index.spread;
89
90
  exports.throttle = function_index.throttle;
90
91
  exports.after = flowRight.after;
91
92
  exports.ary = flowRight.ary;
92
- exports.curryRight = flowRight.curryRight;
93
93
  exports.debounce = flowRight.debounce;
94
94
  exports.flow = flowRight.flow;
95
95
  exports.flowRight = flowRight.flowRight;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isJSONObject = require('../_chunk/isJSONObject-XuEao3.js');
5
+ const isJSONObject = require('../_chunk/isJSONObject-CkW4Fc.js');
6
6
  const isPlainObject = require('../_chunk/isPlainObject-DgrsU7.js');
7
7
 
8
8
  function isError(value) {
@@ -9,6 +9,7 @@ import { eq } from '../compat/util/eq.mjs';
9
9
  import '../compat/function/bind.mjs';
10
10
  import '../compat/function/bindKey.mjs';
11
11
  import '../compat/function/curry.mjs';
12
+ import '../compat/function/curryRight.mjs';
12
13
 
13
14
  function isEqualWith(a, b, areValuesEqual) {
14
15
  return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
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.23.0-dev.735+76b9a12f",
4
+ "version": "1.23.0-dev.736+f452321c",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {