es-toolkit 1.17.0-dev.552 → 1.17.0-dev.554

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.
@@ -1,13 +1,18 @@
1
1
  /**
2
- * Creates a function that invokes `func` with arguments arranged according to the specified `indexes`
2
+ * Creates a function that invokes `func` with arguments arranged according to the specified `indices`
3
3
  * where the argument value at the first index is provided as the first argument,
4
4
  * the argument value at the second index is provided as the second argument, and so on.
5
5
  *
6
6
  * @template F The type of the function to re-arrange.
7
7
  * @param {F} func The function to rearrange arguments for.
8
- * @param {Array<number | number[]>} indexes The arranged argument indexes.
8
+ * @param {Array<number | number[]>} indices The arranged argument indices.
9
9
  * @returns {(...args: any[]) => ReturnType<F>} Returns the new function.
10
+ *
11
+ * @example
12
+ * const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
13
+ * const rearrangedGreet = rearg(greet, 1, 0);
14
+ * console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
10
15
  */
11
- declare function rearg<F extends (...args: any[]) => any>(func: F, ...indexes: Array<number | number[]>): (...args: any[]) => ReturnType<F>;
16
+ declare function rearg<F extends (...args: any[]) => any>(func: F, ...indices: Array<number | number[]>): (...args: any[]) => ReturnType<F>;
12
17
 
13
18
  export { rearg };
@@ -1,13 +1,18 @@
1
1
  /**
2
- * Creates a function that invokes `func` with arguments arranged according to the specified `indexes`
2
+ * Creates a function that invokes `func` with arguments arranged according to the specified `indices`
3
3
  * where the argument value at the first index is provided as the first argument,
4
4
  * the argument value at the second index is provided as the second argument, and so on.
5
5
  *
6
6
  * @template F The type of the function to re-arrange.
7
7
  * @param {F} func The function to rearrange arguments for.
8
- * @param {Array<number | number[]>} indexes The arranged argument indexes.
8
+ * @param {Array<number | number[]>} indices The arranged argument indices.
9
9
  * @returns {(...args: any[]) => ReturnType<F>} Returns the new function.
10
+ *
11
+ * @example
12
+ * const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
13
+ * const rearrangedGreet = rearg(greet, 1, 0);
14
+ * console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
10
15
  */
11
- declare function rearg<F extends (...args: any[]) => any>(func: F, ...indexes: Array<number | number[]>): (...args: any[]) => ReturnType<F>;
16
+ declare function rearg<F extends (...args: any[]) => any>(func: F, ...indices: Array<number | number[]>): (...args: any[]) => ReturnType<F>;
12
17
 
13
18
  export { rearg };
@@ -1,9 +1,9 @@
1
1
  import { flatten } from '../array/flatten.mjs';
2
2
 
3
- function rearg(func, ...indexes) {
4
- const flattenIndexes = flatten(indexes);
3
+ function rearg(func, ...indices) {
4
+ const flattenIndices = flatten(indices);
5
5
  return function (...args) {
6
- const reorderedArgs = flattenIndexes.map(i => args[i]).slice(0, args.length);
6
+ const reorderedArgs = flattenIndices.map(i => args[i]).slice(0, args.length);
7
7
  for (let i = reorderedArgs.length; i < args.length; i++) {
8
8
  reorderedArgs.push(args[i]);
9
9
  }
@@ -61,7 +61,6 @@ export { MemoizeCache, memoize } from '../function/memoize.mjs';
61
61
  export { unary } from '../function/unary.mjs';
62
62
  export { partial } from '../function/partial.mjs';
63
63
  export { partialRight } from '../function/partialRight.mjs';
64
- export { rearg } from '../function/rearg.mjs';
65
64
  export { clamp } from '../math/clamp.mjs';
66
65
  export { inRange } from '../math/inRange.mjs';
67
66
  export { mean } from '../math/mean.mjs';
@@ -128,6 +127,7 @@ export { bindKey } from './function/bindKey.mjs';
128
127
  export { rest } from './function/rest.mjs';
129
128
  export { spread } from './function/spread.mjs';
130
129
  export { attempt } from './function/attempt.mjs';
130
+ export { rearg } from './function/rearg.mjs';
131
131
  export { get } from './object/get.mjs';
132
132
  export { set } from './object/set.mjs';
133
133
  export { has } from './object/has.mjs';
@@ -61,7 +61,6 @@ export { MemoizeCache, memoize } from '../function/memoize.js';
61
61
  export { unary } from '../function/unary.js';
62
62
  export { partial } from '../function/partial.js';
63
63
  export { partialRight } from '../function/partialRight.js';
64
- export { rearg } from '../function/rearg.js';
65
64
  export { clamp } from '../math/clamp.js';
66
65
  export { inRange } from '../math/inRange.js';
67
66
  export { mean } from '../math/mean.js';
@@ -128,6 +127,7 @@ export { bindKey } from './function/bindKey.js';
128
127
  export { rest } from './function/rest.js';
129
128
  export { spread } from './function/spread.js';
130
129
  export { attempt } from './function/attempt.js';
130
+ export { rearg } from './function/rearg.js';
131
131
  export { get } from './object/get.js';
132
132
  export { set } from './object/set.js';
133
133
  export { has } from './object/has.js';
@@ -2,16 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('../_chunk/zipWith-BgvFO2.js');
5
+ const zipWith = require('../_chunk/zipWith-CaTQLt.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const rearg = require('../_chunk/rearg-DDTf0O.js');
7
+ const rest$1 = require('../_chunk/rest-CXt9w3.js');
8
8
  const math_index = require('../math/index.js');
9
9
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
10
10
  const toMerged = require('../_chunk/toMerged-DN1PPP.js');
11
11
  const isWeakSet$1 = require('../_chunk/isWeakSet-CogETi.js');
12
12
  const isTypedArray$1 = require('../_chunk/isTypedArray-Dsrnb1.js');
13
13
  const string_index = require('../string/index.js');
14
- const flatten$1 = require('../_chunk/flatten-ewkiGP.js');
15
14
 
16
15
  function castArray(value) {
17
16
  if (arguments.length === 0) {
@@ -29,12 +28,12 @@ function chunk(arr, size = 1) {
29
28
  }
30
29
 
31
30
  function concat(...values) {
32
- return flatten$1.flatten(values);
31
+ return zipWith.flatten(values);
33
32
  }
34
33
 
35
34
  function difference(arr, ...values) {
36
35
  const arr1 = arr;
37
- const arr2 = flatten$1.flatten(values);
36
+ const arr2 = zipWith.flatten(values);
38
37
  return zipWith.difference(arr1, arr2);
39
38
  }
40
39
 
@@ -653,7 +652,7 @@ function ary(func, n = func.length, guard) {
653
652
  if (Number.isNaN(n) || n < 0) {
654
653
  n = 0;
655
654
  }
656
- return rearg.ary(func, n);
655
+ return rest$1.ary(func, n);
657
656
  }
658
657
 
659
658
  function bind(func, thisObj, ...partialArgs) {
@@ -713,7 +712,7 @@ function rest(func, start = func.length - 1) {
713
712
  if (Number.isNaN(start) || start < 0) {
714
713
  start = func.length - 1;
715
714
  }
716
- return rearg.rest(func, start);
715
+ return rest$1.rest(func, start);
717
716
  }
718
717
 
719
718
  function spread(func, argsIndex = 0) {
@@ -740,6 +739,17 @@ function attempt(func, ...args) {
740
739
  }
741
740
  }
742
741
 
742
+ function rearg(func, ...indices) {
743
+ const flattenIndices = flatten(indices);
744
+ return function (...args) {
745
+ const reorderedArgs = flattenIndices.map(i => args[i]).slice(0, args.length);
746
+ for (let i = reorderedArgs.length; i < args.length; i++) {
747
+ reorderedArgs.push(args[i]);
748
+ }
749
+ return func.apply(this, reorderedArgs);
750
+ };
751
+ }
752
+
743
753
  function mapKeys(object, getNewKey) {
744
754
  getNewKey = getNewKey ?? identity;
745
755
  switch (typeof getNewKey) {
@@ -867,7 +877,7 @@ function mergeWithDeep(target, source, merge, stack) {
867
877
  }
868
878
 
869
879
  function merge(object, ...sources) {
870
- return mergeWith(object, ...sources, rearg.noop);
880
+ return mergeWith(object, ...sources, rest$1.noop);
871
881
  }
872
882
 
873
883
  function isArrayLike(value) {
@@ -1045,18 +1055,17 @@ exports.TimeoutError = promise_index.TimeoutError;
1045
1055
  exports.delay = promise_index.delay;
1046
1056
  exports.timeout = promise_index.timeout;
1047
1057
  exports.withTimeout = promise_index.withTimeout;
1048
- exports.after = rearg.after;
1049
- exports.before = rearg.before;
1050
- exports.debounce = rearg.debounce;
1051
- exports.memoize = rearg.memoize;
1052
- exports.negate = rearg.negate;
1053
- exports.noop = rearg.noop;
1054
- exports.once = rearg.once;
1055
- exports.partial = rearg.partial;
1056
- exports.partialRight = rearg.partialRight;
1057
- exports.rearg = rearg.rearg;
1058
- exports.throttle = rearg.throttle;
1059
- exports.unary = rearg.unary;
1058
+ exports.after = rest$1.after;
1059
+ exports.before = rest$1.before;
1060
+ exports.debounce = rest$1.debounce;
1061
+ exports.memoize = rest$1.memoize;
1062
+ exports.negate = rest$1.negate;
1063
+ exports.noop = rest$1.noop;
1064
+ exports.once = rest$1.once;
1065
+ exports.partial = rest$1.partial;
1066
+ exports.partialRight = rest$1.partialRight;
1067
+ exports.throttle = rest$1.throttle;
1068
+ exports.unary = rest$1.unary;
1060
1069
  exports.clamp = math_index.clamp;
1061
1070
  exports.inRange = math_index.inRange;
1062
1071
  exports.mean = math_index.mean;
@@ -1144,6 +1153,7 @@ exports.orderBy = orderBy;
1144
1153
  exports.padEnd = padEnd;
1145
1154
  exports.padStart = padStart;
1146
1155
  exports.property = property;
1156
+ exports.rearg = rearg;
1147
1157
  exports.repeat = repeat;
1148
1158
  exports.rest = rest;
1149
1159
  exports.set = set;
@@ -61,7 +61,6 @@ export { memoize } from '../function/memoize.mjs';
61
61
  export { unary } from '../function/unary.mjs';
62
62
  export { partial } from '../function/partial.mjs';
63
63
  export { partialRight } from '../function/partialRight.mjs';
64
- export { rearg } from '../function/rearg.mjs';
65
64
  export { clamp } from '../math/clamp.mjs';
66
65
  export { inRange } from '../math/inRange.mjs';
67
66
  export { mean } from '../math/mean.mjs';
@@ -129,6 +128,7 @@ export { bindKey } from './function/bindKey.mjs';
129
128
  export { rest } from './function/rest.mjs';
130
129
  export { spread } from './function/spread.mjs';
131
130
  export { attempt } from './function/attempt.mjs';
131
+ export { rearg } from './function/rearg.mjs';
132
132
  export { get } from './object/get.mjs';
133
133
  export { set } from './object/set.mjs';
134
134
  export { has } from './object/has.mjs';
@@ -11,5 +11,4 @@ export { unary } from './unary.mjs';
11
11
  export { partial } from './partial.mjs';
12
12
  export { partialRight } from './partialRight.mjs';
13
13
  export { rest } from './rest.mjs';
14
- export { rearg } from './rearg.mjs';
15
14
  export { spread } from './spread.mjs';
@@ -11,5 +11,4 @@ export { unary } from './unary.js';
11
11
  export { partial } from './partial.js';
12
12
  export { partialRight } from './partialRight.js';
13
13
  export { rest } from './rest.js';
14
- export { rearg } from './rearg.js';
15
14
  export { spread } from './spread.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const rearg = require('../_chunk/rearg-DDTf0O.js');
5
+ const rest = require('../_chunk/rest-CXt9w3.js');
6
6
 
7
7
  function spread(func) {
8
8
  return function (argsArr) {
@@ -10,18 +10,17 @@ function spread(func) {
10
10
  };
11
11
  }
12
12
 
13
- exports.after = rearg.after;
14
- exports.ary = rearg.ary;
15
- exports.before = rearg.before;
16
- exports.debounce = rearg.debounce;
17
- exports.memoize = rearg.memoize;
18
- exports.negate = rearg.negate;
19
- exports.noop = rearg.noop;
20
- exports.once = rearg.once;
21
- exports.partial = rearg.partial;
22
- exports.partialRight = rearg.partialRight;
23
- exports.rearg = rearg.rearg;
24
- exports.rest = rearg.rest;
25
- exports.throttle = rearg.throttle;
26
- exports.unary = rearg.unary;
13
+ exports.after = rest.after;
14
+ exports.ary = rest.ary;
15
+ exports.before = rest.before;
16
+ exports.debounce = rest.debounce;
17
+ exports.memoize = rest.memoize;
18
+ exports.negate = rest.negate;
19
+ exports.noop = rest.noop;
20
+ exports.once = rest.once;
21
+ exports.partial = rest.partial;
22
+ exports.partialRight = rest.partialRight;
23
+ exports.rest = rest.rest;
24
+ exports.throttle = rest.throttle;
25
+ exports.unary = rest.unary;
27
26
  exports.spread = spread;
@@ -11,5 +11,4 @@ export { unary } from './unary.mjs';
11
11
  export { partial } from './partial.mjs';
12
12
  export { partialRight } from './partialRight.mjs';
13
13
  export { rest } from './rest.mjs';
14
- export { rearg } from './rearg.mjs';
15
14
  export { spread } from './spread.mjs';
package/dist/index.d.mts CHANGED
@@ -70,7 +70,6 @@ export { unary } from './function/unary.mjs';
70
70
  export { partial } from './function/partial.mjs';
71
71
  export { partialRight } from './function/partialRight.mjs';
72
72
  export { rest } from './function/rest.mjs';
73
- export { rearg } from './function/rearg.mjs';
74
73
  export { spread } from './function/spread.mjs';
75
74
  export { clamp } from './math/clamp.mjs';
76
75
  export { inRange } from './math/inRange.mjs';
package/dist/index.d.ts CHANGED
@@ -70,7 +70,6 @@ export { unary } from './function/unary.js';
70
70
  export { partial } from './function/partial.js';
71
71
  export { partialRight } from './function/partialRight.js';
72
72
  export { rest } from './function/rest.js';
73
- export { rearg } from './function/rearg.js';
74
73
  export { spread } from './function/spread.js';
75
74
  export { clamp } from './math/clamp.js';
76
75
  export { inRange } from './math/inRange.js';
package/dist/index.js CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('./_chunk/zipWith-BgvFO2.js');
6
- const flatten = require('./_chunk/flatten-ewkiGP.js');
5
+ const zipWith = require('./_chunk/zipWith-CaTQLt.js');
7
6
  const array_index = require('./array/index.js');
8
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
9
- const rearg = require('./_chunk/rearg-DDTf0O.js');
8
+ const rest = require('./_chunk/rest-CXt9w3.js');
10
9
  const function_index = require('./function/index.js');
11
10
  const math_index = require('./math/index.js');
12
11
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
@@ -33,6 +32,7 @@ exports.dropWhile = zipWith.dropWhile;
33
32
  exports.fill = zipWith.fill;
34
33
  exports.flatMap = zipWith.flatMap;
35
34
  exports.flatMapDeep = zipWith.flatMapDeep;
35
+ exports.flatten = zipWith.flatten;
36
36
  exports.flattenDeep = zipWith.flattenDeep;
37
37
  exports.forEachRight = zipWith.forEachRight;
38
38
  exports.groupBy = zipWith.groupBy;
@@ -73,7 +73,6 @@ exports.xorWith = zipWith.xorWith;
73
73
  exports.zip = zipWith.zip;
74
74
  exports.zipObject = zipWith.zipObject;
75
75
  exports.zipWith = zipWith.zipWith;
76
- exports.flatten = flatten.flatten;
77
76
  exports.orderBy = array_index.orderBy;
78
77
  exports.sortBy = array_index.sortBy;
79
78
  exports.AbortError = promise_index.AbortError;
@@ -81,20 +80,19 @@ exports.TimeoutError = promise_index.TimeoutError;
81
80
  exports.delay = promise_index.delay;
82
81
  exports.timeout = promise_index.timeout;
83
82
  exports.withTimeout = promise_index.withTimeout;
84
- exports.after = rearg.after;
85
- exports.ary = rearg.ary;
86
- exports.before = rearg.before;
87
- exports.debounce = rearg.debounce;
88
- exports.memoize = rearg.memoize;
89
- exports.negate = rearg.negate;
90
- exports.noop = rearg.noop;
91
- exports.once = rearg.once;
92
- exports.partial = rearg.partial;
93
- exports.partialRight = rearg.partialRight;
94
- exports.rearg = rearg.rearg;
95
- exports.rest = rearg.rest;
96
- exports.throttle = rearg.throttle;
97
- exports.unary = rearg.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;
98
96
  exports.spread = function_index.spread;
99
97
  exports.clamp = math_index.clamp;
100
98
  exports.inRange = math_index.inRange;
package/dist/index.mjs CHANGED
@@ -70,7 +70,6 @@ export { unary } from './function/unary.mjs';
70
70
  export { partial } from './function/partial.mjs';
71
71
  export { partialRight } from './function/partialRight.mjs';
72
72
  export { rest } from './function/rest.mjs';
73
- export { rearg } from './function/rearg.mjs';
74
73
  export { spread } from './function/spread.mjs';
75
74
  export { clamp } from './math/clamp.mjs';
76
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.17.0-dev.552+ff595628",
4
+ "version": "1.17.0-dev.554+aa92dcf6",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- function flatten(arr, depth = 1) {
4
- const result = [];
5
- const flooredDepth = Math.floor(depth);
6
- const recursive = (arr, currentDepth) => {
7
- for (const item of arr) {
8
- if (Array.isArray(item) && currentDepth < flooredDepth) {
9
- recursive(item, currentDepth + 1);
10
- }
11
- else {
12
- result.push(item);
13
- }
14
- }
15
- };
16
- recursive(arr, 0);
17
- return result;
18
- }
19
-
20
- exports.flatten = flatten;