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 (...partials) {
8
- const holders = replaceHolders(partials);
9
- const length = partials.length - holders.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, holders, arity - length, partials);
11
+ return makeCurry(func, arity - length, partialArgs);
12
12
  }
13
13
  if (this instanceof wrapper) {
14
- return new func(...partials);
14
+ return new func(...partialArgs);
15
15
  }
16
- return func.apply(this, partials);
16
+ return func.apply(this, partialArgs);
17
17
  };
18
18
  wrapper.placeholder = curryPlaceholder;
19
19
  return wrapper;
20
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);
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
- const newHolders = replaceHolders(args);
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(...args);
30
+ return new func(...providedArgs);
32
31
  }
33
- return func.apply(this, args);
32
+ return func.apply(this, providedArgs);
34
33
  }
35
34
  wrapper.placeholder = curryPlaceholder;
36
35
  return wrapper;
37
36
  }
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);
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
- 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];
45
+ else {
46
+ args.push(arg);
55
47
  }
56
48
  }
57
- while (rangeLength--) {
58
- result[leftIndex++] = args[argsIndex++];
49
+ for (let i = startIndex; i < providedArgs.length; i++) {
50
+ args.push(providedArgs[i]);
59
51
  }
60
- return result;
52
+ return args;
61
53
  }
62
54
  const curryPlaceholder = Symbol('curry.placeholder');
63
55
  curry.placeholder = curryPlaceholder;
@@ -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 (...partials) {
837
- const holders = replaceHolders(partials);
838
- const length = partials.length - holders.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, holders, arity - length, partials);
840
+ return makeCurry(func, arity - length, partialArgs);
841
841
  }
842
842
  if (this instanceof wrapper) {
843
- return new func(...partials);
843
+ return new func(...partialArgs);
844
844
  }
845
- return func.apply(this, partials);
845
+ return func.apply(this, partialArgs);
846
846
  };
847
847
  wrapper.placeholder = curryPlaceholder;
848
848
  return wrapper;
849
849
  }
850
- function makeCurry(func, holders, arity, partials) {
851
- function wrapper(...args) {
852
- const holdersCount = args.filter(item => item === curry.placeholder).length;
853
- const length = args.length - holdersCount;
854
- args = composeArgs(args, partials, holders);
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
- const newHolders = replaceHolders(args);
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(...args);
859
+ return new func(...providedArgs);
861
860
  }
862
- return func.apply(this, args);
861
+ return func.apply(this, providedArgs);
863
862
  }
864
863
  wrapper.placeholder = curryPlaceholder;
865
864
  return wrapper;
866
865
  }
867
- function replaceHolders(args) {
868
- const result = [];
869
- for (let i = 0; i < args.length; i++) {
870
- if (args[i] === curry.placeholder) {
871
- result.push(i);
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
- return result;
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
- while (rangeLength--) {
887
- result[leftIndex++] = args[argsIndex++];
878
+ for (let i = startIndex; i < providedArgs.length; i++) {
879
+ args.push(providedArgs[i]);
888
880
  }
889
- return result;
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 = upperCase('fred') // returns 'fred'
9
- * const convertedStr2 = upperCase('Fred') // returns 'Fred'
10
- * const convertedStr3 = upperCase('FRED') // returns 'FRED'
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 = upperCase('fred') // returns 'fred'
9
- * const convertedStr2 = upperCase('Fred') // returns 'Fred'
10
- * const convertedStr3 = upperCase('FRED') // returns 'FRED'
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.631+ea01c771",
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": {