es-toolkit 1.18.0-dev.587 → 1.18.0-dev.589
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 → curry-BmwJrK.js} +21 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/index.d.mts +2 -0
- package/dist/compat/index.d.ts +2 -0
- package/dist/compat/index.js +21 -15
- package/dist/compat/index.mjs +2 -0
- package/dist/compat/predicate/isInteger.d.mts +17 -0
- package/dist/compat/predicate/isInteger.d.ts +17 -0
- package/dist/compat/predicate/isInteger.mjs +5 -0
- package/dist/function/curry.d.mts +127 -0
- package/dist/function/curry.d.ts +127 -0
- package/dist/function/curry.mjs +21 -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
package/dist/compat/index.d.mts
CHANGED
|
@@ -60,6 +60,7 @@ 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';
|
|
63
64
|
export { clamp } from '../math/clamp.mjs';
|
|
64
65
|
export { inRange } from '../math/inRange.mjs';
|
|
65
66
|
export { mean } from '../math/mean.mjs';
|
|
@@ -151,6 +152,7 @@ export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
|
151
152
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
152
153
|
export { conforms } from './predicate/conforms.mjs';
|
|
153
154
|
export { conformsTo } from './predicate/conformsTo.mjs';
|
|
155
|
+
export { isInteger } from './predicate/isInteger.mjs';
|
|
154
156
|
export { camelCase } from './string/camelCase.mjs';
|
|
155
157
|
export { kebabCase } from './string/kebabCase.mjs';
|
|
156
158
|
export { snakeCase } from './string/snakeCase.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ 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';
|
|
63
64
|
export { clamp } from '../math/clamp.js';
|
|
64
65
|
export { inRange } from '../math/inRange.js';
|
|
65
66
|
export { mean } from '../math/mean.js';
|
|
@@ -151,6 +152,7 @@ export { isWeakMap } from './predicate/isWeakMap.js';
|
|
|
151
152
|
export { isWeakSet } from './predicate/isWeakSet.js';
|
|
152
153
|
export { conforms } from './predicate/conforms.js';
|
|
153
154
|
export { conformsTo } from './predicate/conformsTo.js';
|
|
155
|
+
export { isInteger } from './predicate/isInteger.js';
|
|
154
156
|
export { camelCase } from './string/camelCase.js';
|
|
155
157
|
export { kebabCase } from './string/kebabCase.js';
|
|
156
158
|
export { snakeCase } from './string/snakeCase.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-CYaH1Y.js');
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
|
-
const
|
|
7
|
+
const curry = require('../_chunk/curry-BmwJrK.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-LBvzaK.js');
|
|
@@ -684,7 +684,7 @@ function ary(func, n = func.length, guard) {
|
|
|
684
684
|
if (Number.isNaN(n) || n < 0) {
|
|
685
685
|
n = 0;
|
|
686
686
|
}
|
|
687
|
-
return
|
|
687
|
+
return curry.ary(func, n);
|
|
688
688
|
}
|
|
689
689
|
|
|
690
690
|
function bind(func, thisObj, ...partialArgs) {
|
|
@@ -744,7 +744,7 @@ function rest(func, start = func.length - 1) {
|
|
|
744
744
|
if (Number.isNaN(start) || start < 0) {
|
|
745
745
|
start = func.length - 1;
|
|
746
746
|
}
|
|
747
|
-
return
|
|
747
|
+
return curry.rest(func, start);
|
|
748
748
|
}
|
|
749
749
|
|
|
750
750
|
function spread(func, argsIndex = 0) {
|
|
@@ -946,7 +946,7 @@ function mergeWithDeep(target, source, merge, stack) {
|
|
|
946
946
|
}
|
|
947
947
|
|
|
948
948
|
function merge(object, ...sources) {
|
|
949
|
-
return mergeWith(object, ...sources,
|
|
949
|
+
return mergeWith(object, ...sources, curry.noop);
|
|
950
950
|
}
|
|
951
951
|
|
|
952
952
|
function isArrayLike(value) {
|
|
@@ -1028,6 +1028,10 @@ function conforms(source) {
|
|
|
1028
1028
|
};
|
|
1029
1029
|
}
|
|
1030
1030
|
|
|
1031
|
+
function isInteger(value) {
|
|
1032
|
+
return Number.isInteger(value);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1031
1035
|
function normalizeForCase(str) {
|
|
1032
1036
|
if (typeof str === 'object') {
|
|
1033
1037
|
str = str.toString();
|
|
@@ -1272,17 +1276,18 @@ exports.TimeoutError = promise_index.TimeoutError;
|
|
|
1272
1276
|
exports.delay = promise_index.delay;
|
|
1273
1277
|
exports.timeout = promise_index.timeout;
|
|
1274
1278
|
exports.withTimeout = promise_index.withTimeout;
|
|
1275
|
-
exports.after =
|
|
1276
|
-
exports.before =
|
|
1277
|
-
exports.
|
|
1278
|
-
exports.
|
|
1279
|
-
exports.
|
|
1280
|
-
exports.
|
|
1281
|
-
exports.
|
|
1282
|
-
exports.
|
|
1283
|
-
exports.
|
|
1284
|
-
exports.
|
|
1285
|
-
exports.
|
|
1279
|
+
exports.after = curry.after;
|
|
1280
|
+
exports.before = curry.before;
|
|
1281
|
+
exports.curry = curry.curry;
|
|
1282
|
+
exports.debounce = curry.debounce;
|
|
1283
|
+
exports.memoize = curry.memoize;
|
|
1284
|
+
exports.negate = curry.negate;
|
|
1285
|
+
exports.noop = curry.noop;
|
|
1286
|
+
exports.once = curry.once;
|
|
1287
|
+
exports.partial = curry.partial;
|
|
1288
|
+
exports.partialRight = curry.partialRight;
|
|
1289
|
+
exports.throttle = curry.throttle;
|
|
1290
|
+
exports.unary = curry.unary;
|
|
1286
1291
|
exports.clamp = range.clamp;
|
|
1287
1292
|
exports.inRange = range.inRange;
|
|
1288
1293
|
exports.mean = range.mean;
|
|
@@ -1348,6 +1353,7 @@ exports.isArguments = isArguments;
|
|
|
1348
1353
|
exports.isArray = isArray;
|
|
1349
1354
|
exports.isArrayLike = isArrayLike;
|
|
1350
1355
|
exports.isBoolean = isBoolean;
|
|
1356
|
+
exports.isInteger = isInteger;
|
|
1351
1357
|
exports.isMatch = isMatch;
|
|
1352
1358
|
exports.isObject = isObject;
|
|
1353
1359
|
exports.isPlainObject = isPlainObject;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -60,6 +60,7 @@ 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';
|
|
63
64
|
export { clamp } from '../math/clamp.mjs';
|
|
64
65
|
export { inRange } from '../math/inRange.mjs';
|
|
65
66
|
export { mean } from '../math/mean.mjs';
|
|
@@ -151,6 +152,7 @@ export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
|
151
152
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
152
153
|
export { conforms } from './predicate/conforms.mjs';
|
|
153
154
|
export { conformsTo } from './predicate/conformsTo.mjs';
|
|
155
|
+
export { isInteger } from './predicate/isInteger.mjs';
|
|
154
156
|
export { camelCase } from './string/camelCase.mjs';
|
|
155
157
|
export { kebabCase } from './string/kebabCase.mjs';
|
|
156
158
|
export { snakeCase } from './string/snakeCase.mjs';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is an integer.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to check
|
|
7
|
+
* @returns {boolean} `true` if `value` is integer, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* isInteger(3); // Returns: true
|
|
11
|
+
* isInteger(Infinity); // Returns: false
|
|
12
|
+
* isInteger('3'); // Returns: false
|
|
13
|
+
* isInteger([]); // Returns: false
|
|
14
|
+
*/
|
|
15
|
+
declare function isInteger(value?: unknown): value is number;
|
|
16
|
+
|
|
17
|
+
export { isInteger };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `value` is an integer.
|
|
3
|
+
*
|
|
4
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to check
|
|
7
|
+
* @returns {boolean} `true` if `value` is integer, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* isInteger(3); // Returns: true
|
|
11
|
+
* isInteger(Infinity); // Returns: false
|
|
12
|
+
* isInteger('3'); // Returns: false
|
|
13
|
+
* isInteger([]); // Returns: false
|
|
14
|
+
*/
|
|
15
|
+
declare function isInteger(value?: unknown): value is number;
|
|
16
|
+
|
|
17
|
+
export { isInteger };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
3
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
4
|
+
*
|
|
5
|
+
* @param {() => R} func - The function to curry.
|
|
6
|
+
* @returns {() => R} A curried function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* function noArgFunc() {
|
|
10
|
+
* return 42;
|
|
11
|
+
* }
|
|
12
|
+
* const curriedNoArgFunc = curry(noArgFunc);
|
|
13
|
+
* console.log(curriedNoArgFunc()); // 42
|
|
14
|
+
*/
|
|
15
|
+
declare function curry<R>(func: () => R): () => R;
|
|
16
|
+
/**
|
|
17
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
18
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
19
|
+
*
|
|
20
|
+
* @param {(p: P) => R} func - The function to curry.
|
|
21
|
+
* @returns {(p: P) => R} A curried function.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* function oneArgFunc(a: number) {
|
|
25
|
+
* return a * 2;
|
|
26
|
+
* }
|
|
27
|
+
* const curriedOneArgFunc = curry(oneArgFunc);
|
|
28
|
+
* console.log(curriedOneArgFunc(5)); // 10
|
|
29
|
+
*/
|
|
30
|
+
declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
|
|
31
|
+
/**
|
|
32
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
33
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
34
|
+
*
|
|
35
|
+
* @param {(p1: P1, p2: P2) => R} func - The function to curry.
|
|
36
|
+
* @returns {(p1: P1) => (p2: P2) => R} A curried function.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* function twoArgFunc(a: number, b: number) {
|
|
40
|
+
* return a + b;
|
|
41
|
+
* }
|
|
42
|
+
* const curriedTwoArgFunc = curry(twoArgFunc);
|
|
43
|
+
* const add5 = curriedTwoArgFunc(5);
|
|
44
|
+
* console.log(add5(10)); // 15
|
|
45
|
+
*/
|
|
46
|
+
declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
|
|
47
|
+
/**
|
|
48
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
49
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
50
|
+
*
|
|
51
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
52
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
56
|
+
* return a + b + c + d;
|
|
57
|
+
* }
|
|
58
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
59
|
+
* const add1 = curriedFourArgFunc(1);
|
|
60
|
+
* const add2 = add1(2);
|
|
61
|
+
* const add3 = add2(3);
|
|
62
|
+
* console.log(add3(4)); // 10
|
|
63
|
+
*/
|
|
64
|
+
declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
|
|
65
|
+
/**
|
|
66
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
67
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
68
|
+
*
|
|
69
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
70
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
74
|
+
* return a + b + c + d;
|
|
75
|
+
* }
|
|
76
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
77
|
+
* const add1 = curriedFourArgFunc(1);
|
|
78
|
+
* const add2 = add1(2);
|
|
79
|
+
* const add3 = add2(3);
|
|
80
|
+
* console.log(add3(4)); // 10
|
|
81
|
+
*/
|
|
82
|
+
declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
|
|
83
|
+
/**
|
|
84
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
85
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
86
|
+
*
|
|
87
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R} func - The function to curry.
|
|
88
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R} A curried function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
|
|
92
|
+
* return a + b + c + d + e;
|
|
93
|
+
* }
|
|
94
|
+
* const curriedFiveArgFunc = curry(fiveArgFunc);
|
|
95
|
+
* const add1 = curriedFiveArgFunc(1);
|
|
96
|
+
* const add2 = add1(2);
|
|
97
|
+
* const add3 = add2(3);
|
|
98
|
+
* const add4 = add3(4);
|
|
99
|
+
* console.log(add4(5)); // 15
|
|
100
|
+
*/
|
|
101
|
+
declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
|
|
102
|
+
/**
|
|
103
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
104
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
105
|
+
*
|
|
106
|
+
* @param {(...args: any[]) => any} func - The function to curry.
|
|
107
|
+
* @returns {(...args: any[]) => any} A curried function that can be called with a single argument at a time.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* function sum(a: number, b: number, c: number) {
|
|
111
|
+
* return a + b + c;
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const curriedSum = curry(sum);
|
|
115
|
+
*
|
|
116
|
+
* // The parameter `a` should be given the value `10`.
|
|
117
|
+
* const sum10 = curriedSum(10);
|
|
118
|
+
*
|
|
119
|
+
* // The parameter `b` should be given the value `15`.
|
|
120
|
+
* const sum25 = sum10(15);
|
|
121
|
+
*
|
|
122
|
+
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
|
|
123
|
+
* const result = sum25(5);
|
|
124
|
+
*/
|
|
125
|
+
declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
|
|
126
|
+
|
|
127
|
+
export { curry };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
3
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
4
|
+
*
|
|
5
|
+
* @param {() => R} func - The function to curry.
|
|
6
|
+
* @returns {() => R} A curried function.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* function noArgFunc() {
|
|
10
|
+
* return 42;
|
|
11
|
+
* }
|
|
12
|
+
* const curriedNoArgFunc = curry(noArgFunc);
|
|
13
|
+
* console.log(curriedNoArgFunc()); // 42
|
|
14
|
+
*/
|
|
15
|
+
declare function curry<R>(func: () => R): () => R;
|
|
16
|
+
/**
|
|
17
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
18
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
19
|
+
*
|
|
20
|
+
* @param {(p: P) => R} func - The function to curry.
|
|
21
|
+
* @returns {(p: P) => R} A curried function.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* function oneArgFunc(a: number) {
|
|
25
|
+
* return a * 2;
|
|
26
|
+
* }
|
|
27
|
+
* const curriedOneArgFunc = curry(oneArgFunc);
|
|
28
|
+
* console.log(curriedOneArgFunc(5)); // 10
|
|
29
|
+
*/
|
|
30
|
+
declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
|
|
31
|
+
/**
|
|
32
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
33
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
34
|
+
*
|
|
35
|
+
* @param {(p1: P1, p2: P2) => R} func - The function to curry.
|
|
36
|
+
* @returns {(p1: P1) => (p2: P2) => R} A curried function.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* function twoArgFunc(a: number, b: number) {
|
|
40
|
+
* return a + b;
|
|
41
|
+
* }
|
|
42
|
+
* const curriedTwoArgFunc = curry(twoArgFunc);
|
|
43
|
+
* const add5 = curriedTwoArgFunc(5);
|
|
44
|
+
* console.log(add5(10)); // 15
|
|
45
|
+
*/
|
|
46
|
+
declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
|
|
47
|
+
/**
|
|
48
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
49
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
50
|
+
*
|
|
51
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
52
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
56
|
+
* return a + b + c + d;
|
|
57
|
+
* }
|
|
58
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
59
|
+
* const add1 = curriedFourArgFunc(1);
|
|
60
|
+
* const add2 = add1(2);
|
|
61
|
+
* const add3 = add2(3);
|
|
62
|
+
* console.log(add3(4)); // 10
|
|
63
|
+
*/
|
|
64
|
+
declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
|
|
65
|
+
/**
|
|
66
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
67
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
68
|
+
*
|
|
69
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|
70
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|
74
|
+
* return a + b + c + d;
|
|
75
|
+
* }
|
|
76
|
+
* const curriedFourArgFunc = curry(fourArgFunc);
|
|
77
|
+
* const add1 = curriedFourArgFunc(1);
|
|
78
|
+
* const add2 = add1(2);
|
|
79
|
+
* const add3 = add2(3);
|
|
80
|
+
* console.log(add3(4)); // 10
|
|
81
|
+
*/
|
|
82
|
+
declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
|
|
83
|
+
/**
|
|
84
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
85
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
86
|
+
*
|
|
87
|
+
* @param {(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R} func - The function to curry.
|
|
88
|
+
* @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R} A curried function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
|
|
92
|
+
* return a + b + c + d + e;
|
|
93
|
+
* }
|
|
94
|
+
* const curriedFiveArgFunc = curry(fiveArgFunc);
|
|
95
|
+
* const add1 = curriedFiveArgFunc(1);
|
|
96
|
+
* const add2 = add1(2);
|
|
97
|
+
* const add3 = add2(3);
|
|
98
|
+
* const add4 = add3(4);
|
|
99
|
+
* console.log(add4(5)); // 15
|
|
100
|
+
*/
|
|
101
|
+
declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
|
|
102
|
+
/**
|
|
103
|
+
* Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
|
|
104
|
+
* This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|
105
|
+
*
|
|
106
|
+
* @param {(...args: any[]) => any} func - The function to curry.
|
|
107
|
+
* @returns {(...args: any[]) => any} A curried function that can be called with a single argument at a time.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* function sum(a: number, b: number, c: number) {
|
|
111
|
+
* return a + b + c;
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const curriedSum = curry(sum);
|
|
115
|
+
*
|
|
116
|
+
* // The parameter `a` should be given the value `10`.
|
|
117
|
+
* const sum10 = curriedSum(10);
|
|
118
|
+
*
|
|
119
|
+
* // The parameter `b` should be given the value `15`.
|
|
120
|
+
* const sum25 = sum10(15);
|
|
121
|
+
*
|
|
122
|
+
* // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
|
|
123
|
+
* const result = sum25(5);
|
|
124
|
+
*/
|
|
125
|
+
declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
|
|
126
|
+
|
|
127
|
+
export { curry };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function curry(func) {
|
|
2
|
+
if (func.length === 0 || func.length === 1) {
|
|
3
|
+
return func;
|
|
4
|
+
}
|
|
5
|
+
return function (arg) {
|
|
6
|
+
return makeCurry(func, func.length, [arg]);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function makeCurry(origin, argsLength, args) {
|
|
10
|
+
if (args.length === argsLength) {
|
|
11
|
+
return origin(...args);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const next = function (arg) {
|
|
15
|
+
return makeCurry(origin, argsLength, [...args, arg]);
|
|
16
|
+
};
|
|
17
|
+
return next;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { curry };
|
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 curry = require('../_chunk/curry-BmwJrK.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 = 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;
|
|
26
27
|
exports.spread = spread;
|
package/dist/function/index.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -69,6 +69,7 @@ export { unary } from './function/unary.mjs';
|
|
|
69
69
|
export { partial } from './function/partial.mjs';
|
|
70
70
|
export { partialRight } from './function/partialRight.mjs';
|
|
71
71
|
export { rest } from './function/rest.mjs';
|
|
72
|
+
export { curry } from './function/curry.mjs';
|
|
72
73
|
export { spread } from './function/spread.mjs';
|
|
73
74
|
export { clamp } from './math/clamp.mjs';
|
|
74
75
|
export { inRange } from './math/inRange.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export { unary } from './function/unary.js';
|
|
|
69
69
|
export { partial } from './function/partial.js';
|
|
70
70
|
export { partialRight } from './function/partialRight.js';
|
|
71
71
|
export { rest } from './function/rest.js';
|
|
72
|
+
export { curry } from './function/curry.js';
|
|
72
73
|
export { spread } from './function/spread.js';
|
|
73
74
|
export { clamp } from './math/clamp.js';
|
|
74
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-CYaH1Y.js');
|
|
6
6
|
const array_index = require('./array/index.js');
|
|
7
7
|
const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
8
|
-
const
|
|
8
|
+
const curry = require('./_chunk/curry-BmwJrK.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,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 = 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;
|
|
96
97
|
exports.spread = function_index.spread;
|
|
97
98
|
exports.clamp = range.clamp;
|
|
98
99
|
exports.inRange = range.inRange;
|
package/dist/index.mjs
CHANGED
|
@@ -69,6 +69,7 @@ export { unary } from './function/unary.mjs';
|
|
|
69
69
|
export { partial } from './function/partial.mjs';
|
|
70
70
|
export { partialRight } from './function/partialRight.mjs';
|
|
71
71
|
export { rest } from './function/rest.mjs';
|
|
72
|
+
export { curry } from './function/curry.mjs';
|
|
72
73
|
export { spread } from './function/spread.mjs';
|
|
73
74
|
export { clamp } from './math/clamp.mjs';
|
|
74
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.18.0-dev.
|
|
4
|
+
"version": "1.18.0-dev.589+ff8976e5",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|