es-toolkit 1.20.0-dev.631 → 1.20.0-dev.633
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.
|
@@ -4,60 +4,52 @@ function curry(func, arity = func.length, guard) {
|
|
|
4
4
|
if (Number.isNaN(arity) || arity < 1) {
|
|
5
5
|
arity = 0;
|
|
6
6
|
}
|
|
7
|
-
const wrapper = function (...
|
|
8
|
-
const holders =
|
|
9
|
-
const length =
|
|
7
|
+
const wrapper = function (...partialArgs) {
|
|
8
|
+
const holders = partialArgs.filter(item => item === curry.placeholder);
|
|
9
|
+
const length = partialArgs.length - holders.length;
|
|
10
10
|
if (length < arity) {
|
|
11
|
-
return makeCurry(func,
|
|
11
|
+
return makeCurry(func, arity - length, partialArgs);
|
|
12
12
|
}
|
|
13
13
|
if (this instanceof wrapper) {
|
|
14
|
-
return new func(...
|
|
14
|
+
return new func(...partialArgs);
|
|
15
15
|
}
|
|
16
|
-
return func.apply(this,
|
|
16
|
+
return func.apply(this, partialArgs);
|
|
17
17
|
};
|
|
18
18
|
wrapper.placeholder = curryPlaceholder;
|
|
19
19
|
return wrapper;
|
|
20
20
|
}
|
|
21
|
-
function makeCurry(func,
|
|
22
|
-
function wrapper(...
|
|
23
|
-
const
|
|
24
|
-
const length =
|
|
25
|
-
|
|
21
|
+
function makeCurry(func, arity, partialArgs) {
|
|
22
|
+
function wrapper(...providedArgs) {
|
|
23
|
+
const holders = providedArgs.filter(item => item === curry.placeholder);
|
|
24
|
+
const length = providedArgs.length - holders.length;
|
|
25
|
+
providedArgs = composeArgs(providedArgs, partialArgs);
|
|
26
26
|
if (length < arity) {
|
|
27
|
-
|
|
28
|
-
return makeCurry(func, newHolders, arity - length, args);
|
|
27
|
+
return makeCurry(func, arity - length, providedArgs);
|
|
29
28
|
}
|
|
30
29
|
if (this instanceof wrapper) {
|
|
31
|
-
return new func(...
|
|
30
|
+
return new func(...providedArgs);
|
|
32
31
|
}
|
|
33
|
-
return func.apply(this,
|
|
32
|
+
return func.apply(this, providedArgs);
|
|
34
33
|
}
|
|
35
34
|
wrapper.placeholder = curryPlaceholder;
|
|
36
35
|
return wrapper;
|
|
37
36
|
}
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
function composeArgs(providedArgs, partialArgs) {
|
|
38
|
+
const args = [];
|
|
39
|
+
let startIndex = 0;
|
|
40
|
+
for (let i = 0; i < partialArgs.length; i++) {
|
|
41
|
+
const arg = partialArgs[i];
|
|
42
|
+
if (arg === curry.placeholder && startIndex < providedArgs.length) {
|
|
43
|
+
args.push(providedArgs[startIndex++]);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
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];
|
|
45
|
+
else {
|
|
46
|
+
args.push(arg);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
for (let i = startIndex; i < providedArgs.length; i++) {
|
|
50
|
+
args.push(providedArgs[i]);
|
|
59
51
|
}
|
|
60
|
-
return
|
|
52
|
+
return args;
|
|
61
53
|
}
|
|
62
54
|
const curryPlaceholder = Symbol('curry.placeholder');
|
|
63
55
|
curry.placeholder = curryPlaceholder;
|
package/dist/compat/index.js
CHANGED
|
@@ -833,60 +833,52 @@ function curry(func, arity = func.length, guard) {
|
|
|
833
833
|
if (Number.isNaN(arity) || arity < 1) {
|
|
834
834
|
arity = 0;
|
|
835
835
|
}
|
|
836
|
-
const wrapper = function (...
|
|
837
|
-
const holders =
|
|
838
|
-
const length =
|
|
836
|
+
const wrapper = function (...partialArgs) {
|
|
837
|
+
const holders = partialArgs.filter(item => item === curry.placeholder);
|
|
838
|
+
const length = partialArgs.length - holders.length;
|
|
839
839
|
if (length < arity) {
|
|
840
|
-
return makeCurry(func,
|
|
840
|
+
return makeCurry(func, arity - length, partialArgs);
|
|
841
841
|
}
|
|
842
842
|
if (this instanceof wrapper) {
|
|
843
|
-
return new func(...
|
|
843
|
+
return new func(...partialArgs);
|
|
844
844
|
}
|
|
845
|
-
return func.apply(this,
|
|
845
|
+
return func.apply(this, partialArgs);
|
|
846
846
|
};
|
|
847
847
|
wrapper.placeholder = curryPlaceholder;
|
|
848
848
|
return wrapper;
|
|
849
849
|
}
|
|
850
|
-
function makeCurry(func,
|
|
851
|
-
function wrapper(...
|
|
852
|
-
const
|
|
853
|
-
const length =
|
|
854
|
-
|
|
850
|
+
function makeCurry(func, arity, partialArgs) {
|
|
851
|
+
function wrapper(...providedArgs) {
|
|
852
|
+
const holders = providedArgs.filter(item => item === curry.placeholder);
|
|
853
|
+
const length = providedArgs.length - holders.length;
|
|
854
|
+
providedArgs = composeArgs(providedArgs, partialArgs);
|
|
855
855
|
if (length < arity) {
|
|
856
|
-
|
|
857
|
-
return makeCurry(func, newHolders, arity - length, args);
|
|
856
|
+
return makeCurry(func, arity - length, providedArgs);
|
|
858
857
|
}
|
|
859
858
|
if (this instanceof wrapper) {
|
|
860
|
-
return new func(...
|
|
859
|
+
return new func(...providedArgs);
|
|
861
860
|
}
|
|
862
|
-
return func.apply(this,
|
|
861
|
+
return func.apply(this, providedArgs);
|
|
863
862
|
}
|
|
864
863
|
wrapper.placeholder = curryPlaceholder;
|
|
865
864
|
return wrapper;
|
|
866
865
|
}
|
|
867
|
-
function
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
866
|
+
function composeArgs(providedArgs, partialArgs) {
|
|
867
|
+
const args = [];
|
|
868
|
+
let startIndex = 0;
|
|
869
|
+
for (let i = 0; i < partialArgs.length; i++) {
|
|
870
|
+
const arg = partialArgs[i];
|
|
871
|
+
if (arg === curry.placeholder && startIndex < providedArgs.length) {
|
|
872
|
+
args.push(providedArgs[startIndex++]);
|
|
872
873
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
}
|
|
876
|
-
function composeArgs(args, partials, holders) {
|
|
877
|
-
const result = [...partials];
|
|
878
|
-
const argsLength = args.length;
|
|
879
|
-
const holdersLength = holders.length;
|
|
880
|
-
let argsIndex = -1, leftIndex = partials.length, rangeLength = Math.max(argsLength - holdersLength, 0);
|
|
881
|
-
while (++argsIndex < holdersLength) {
|
|
882
|
-
if (argsIndex < argsLength) {
|
|
883
|
-
result[holders[argsIndex]] = args[argsIndex];
|
|
874
|
+
else {
|
|
875
|
+
args.push(arg);
|
|
884
876
|
}
|
|
885
877
|
}
|
|
886
|
-
|
|
887
|
-
|
|
878
|
+
for (let i = startIndex; i < providedArgs.length; i++) {
|
|
879
|
+
args.push(providedArgs[i]);
|
|
888
880
|
}
|
|
889
|
-
return
|
|
881
|
+
return args;
|
|
890
882
|
}
|
|
891
883
|
const curryPlaceholder = Symbol('curry.placeholder');
|
|
892
884
|
curry.placeholder = curryPlaceholder;
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @returns {string} - The converted string.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* const convertedStr1 =
|
|
9
|
-
* const convertedStr2 =
|
|
10
|
-
* const convertedStr3 =
|
|
8
|
+
* const convertedStr1 = upperFirst('fred') // returns 'Fred'
|
|
9
|
+
* const convertedStr2 = upperFirst('Fred') // returns 'Fred'
|
|
10
|
+
* const convertedStr3 = upperFirst('FRED') // returns 'FRED'
|
|
11
11
|
*/
|
|
12
12
|
declare function upperFirst(str: string): string;
|
|
13
13
|
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @returns {string} - The converted string.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* const convertedStr1 =
|
|
9
|
-
* const convertedStr2 =
|
|
10
|
-
* const convertedStr3 =
|
|
8
|
+
* const convertedStr1 = upperFirst('fred') // returns 'Fred'
|
|
9
|
+
* const convertedStr2 = upperFirst('Fred') // returns 'Fred'
|
|
10
|
+
* const convertedStr3 = upperFirst('FRED') // returns 'FRED'
|
|
11
11
|
*/
|
|
12
12
|
declare function upperFirst(str: string): string;
|
|
13
13
|
|
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.20.0-dev.
|
|
4
|
+
"version": "1.20.0-dev.633+db235b97",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|