es-toolkit 1.35.0 → 1.36.0-dev.1215

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_chunk/{isPromise-ByAybB.js → isPromise-CxqI1v.js} +122 -36
  3. package/dist/_chunk/{reverseString-D-wK2p.js → reverseString-BixeGz.js} +84 -13
  4. package/dist/_chunk/toSnakeCaseKeys-DZO2eB.js +4901 -0
  5. package/dist/_chunk/{unary-BsNWRM.js → unary-EIEhcF.js} +46 -0
  6. package/dist/_chunk/{zip-_HttSl.js → zip-BJSrRi.js} +38 -57
  7. package/dist/array/index.js +55 -6
  8. package/dist/array/pullAt.d.mts +0 -2
  9. package/dist/array/pullAt.d.ts +0 -2
  10. package/dist/array/take.d.mts +1 -1
  11. package/dist/array/take.d.ts +1 -1
  12. package/dist/array/take.mjs +4 -1
  13. package/dist/array/takeRight.d.mts +1 -1
  14. package/dist/array/takeRight.d.ts +1 -1
  15. package/dist/array/takeRight.mjs +5 -2
  16. package/dist/browser.global.js +1 -1
  17. package/dist/browser.global.js.map +1 -1
  18. package/dist/compat/_internal/copyArray.mjs +12 -0
  19. package/dist/compat/_internal/mapToEntries.mjs +11 -0
  20. package/dist/compat/_internal/setToEntries.mjs +11 -0
  21. package/dist/compat/_internal/toKey.mjs +2 -2
  22. package/dist/compat/array/find.mjs +3 -3
  23. package/dist/compat/array/findLast.mjs +2 -2
  24. package/dist/compat/array/flatMap.d.mts +20 -0
  25. package/dist/compat/array/flatMap.d.ts +20 -0
  26. package/dist/compat/array/flatMap.mjs +13 -0
  27. package/dist/compat/array/forEachRight.d.mts +106 -0
  28. package/dist/compat/array/forEachRight.d.ts +106 -0
  29. package/dist/compat/array/forEachRight.mjs +21 -0
  30. package/dist/compat/array/groupBy.d.mts +55 -0
  31. package/dist/compat/array/groupBy.d.ts +55 -0
  32. package/dist/compat/array/groupBy.mjs +15 -0
  33. package/dist/compat/array/partition.d.mts +65 -0
  34. package/dist/compat/array/partition.d.ts +65 -0
  35. package/dist/compat/array/partition.mjs +24 -0
  36. package/dist/compat/array/pullAllWith.d.mts +59 -0
  37. package/dist/compat/array/pullAllWith.d.ts +59 -0
  38. package/dist/compat/array/pullAllWith.mjs +33 -0
  39. package/dist/compat/array/pullAt.d.mts +32 -0
  40. package/dist/compat/array/pullAt.d.ts +32 -0
  41. package/dist/compat/array/pullAt.mjs +34 -0
  42. package/dist/compat/compat.d.mts +310 -0
  43. package/dist/compat/compat.d.ts +310 -0
  44. package/dist/compat/compat.mjs +312 -0
  45. package/dist/compat/function/partial.d.mts +575 -0
  46. package/dist/compat/function/partial.d.ts +575 -0
  47. package/dist/compat/function/partial.mjs +8 -0
  48. package/dist/compat/function/partialRight.d.mts +651 -0
  49. package/dist/compat/function/partialRight.d.ts +651 -0
  50. package/dist/compat/function/partialRight.mjs +8 -0
  51. package/dist/compat/index.d.mts +16 -7
  52. package/dist/compat/index.d.ts +16 -7
  53. package/dist/compat/index.js +290 -3771
  54. package/dist/compat/index.mjs +19 -8
  55. package/dist/compat/object/defaults.mjs +7 -1
  56. package/dist/compat/object/forIn.d.mts +58 -0
  57. package/dist/compat/object/forIn.d.ts +58 -0
  58. package/dist/compat/object/forIn.mjs +16 -0
  59. package/dist/compat/object/forInRight.d.mts +58 -0
  60. package/dist/compat/object/forInRight.d.ts +58 -0
  61. package/dist/compat/object/forInRight.mjs +21 -0
  62. package/dist/compat/object/forOwn.d.mts +54 -0
  63. package/dist/compat/object/forOwn.d.ts +54 -0
  64. package/dist/compat/object/forOwn.mjs +19 -0
  65. package/dist/compat/object/forOwnRight.d.mts +54 -0
  66. package/dist/compat/object/forOwnRight.d.ts +54 -0
  67. package/dist/compat/object/forOwnRight.mjs +19 -0
  68. package/dist/compat/object/hasIn.d.mts +40 -0
  69. package/dist/compat/object/hasIn.d.ts +40 -0
  70. package/dist/compat/object/hasIn.mjs +34 -0
  71. package/dist/compat/object/toPairs.mjs +7 -2
  72. package/dist/compat/object/toPairsIn.mjs +7 -2
  73. package/dist/compat/string/repeat.d.mts +1 -1
  74. package/dist/compat/string/repeat.d.ts +1 -1
  75. package/dist/compat/string/repeat.mjs +12 -2
  76. package/dist/compat/string/words.d.mts +1 -1
  77. package/dist/compat/string/words.d.ts +1 -1
  78. package/dist/compat/string/words.mjs +2 -1
  79. package/dist/compat/toolkit.d.mts +9 -0
  80. package/dist/compat/toolkit.d.ts +9 -0
  81. package/dist/compat/toolkit.mjs +10 -0
  82. package/dist/compat/util/overEvery.d.mts +67 -0
  83. package/dist/compat/util/overEvery.d.ts +67 -0
  84. package/dist/compat/util/overEvery.mjs +23 -0
  85. package/dist/compat/util/overSome.d.mts +69 -0
  86. package/dist/compat/util/overSome.d.ts +69 -0
  87. package/dist/compat/util/overSome.mjs +23 -0
  88. package/dist/function/index.js +3 -5
  89. package/dist/function/partial.d.mts +3 -3
  90. package/dist/function/partial.d.ts +3 -3
  91. package/dist/function/partial.mjs +17 -19
  92. package/dist/function/partialRight.d.mts +3 -3
  93. package/dist/function/partialRight.d.ts +3 -3
  94. package/dist/function/partialRight.mjs +18 -20
  95. package/dist/function/throttle.mjs +0 -1
  96. package/dist/index.js +39 -42
  97. package/dist/object/index.js +15 -15
  98. package/dist/object/toCamelCaseKeys.mjs +3 -0
  99. package/dist/object/toSnakeCaseKeys.mjs +3 -0
  100. package/dist/predicate/index.js +4 -5
  101. package/dist/string/index.js +7 -8
  102. package/package.json +1 -1
  103. package/dist/_chunk/isPlainObject-Xaozpc.js +0 -93
  104. package/dist/_chunk/partialRight-B0_CSB.js +0 -50
  105. package/dist/_chunk/snakeCase-BtVEeB.js +0 -75
  106. package/dist/_chunk/toSnakeCaseKeys-BNpS71.js +0 -569
@@ -134,6 +134,48 @@ function once(func) {
134
134
  };
135
135
  }
136
136
 
137
+ function partial(func, ...partialArgs) {
138
+ return partialImpl(func, placeholderSymbol$1, ...partialArgs);
139
+ }
140
+ function partialImpl(func, placeholder, ...partialArgs) {
141
+ const partialed = function (...providedArgs) {
142
+ let providedArgsIndex = 0;
143
+ const substitutedArgs = partialArgs
144
+ .slice()
145
+ .map(arg => (arg === placeholder ? providedArgs[providedArgsIndex++] : arg));
146
+ const remainingArgs = providedArgs.slice(providedArgsIndex);
147
+ return func.apply(this, substitutedArgs.concat(remainingArgs));
148
+ };
149
+ if (func.prototype) {
150
+ partialed.prototype = Object.create(func.prototype);
151
+ }
152
+ return partialed;
153
+ }
154
+ const placeholderSymbol$1 = Symbol('partial.placeholder');
155
+ partial.placeholder = placeholderSymbol$1;
156
+
157
+ function partialRight(func, ...partialArgs) {
158
+ return partialRightImpl(func, placeholderSymbol, ...partialArgs);
159
+ }
160
+ function partialRightImpl(func, placeholder, ...partialArgs) {
161
+ const partialedRight = function (...providedArgs) {
162
+ const placeholderLength = partialArgs.filter(arg => arg === placeholder).length;
163
+ const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
164
+ const remainingArgs = providedArgs.slice(0, rangeLength);
165
+ let providedArgsIndex = rangeLength;
166
+ const substitutedArgs = partialArgs
167
+ .slice()
168
+ .map(arg => (arg === placeholder ? providedArgs[providedArgsIndex++] : arg));
169
+ return func.apply(this, remainingArgs.concat(substitutedArgs));
170
+ };
171
+ if (func.prototype) {
172
+ partialedRight.prototype = Object.create(func.prototype);
173
+ }
174
+ return partialedRight;
175
+ }
176
+ const placeholderSymbol = Symbol('partialRight.placeholder');
177
+ partialRight.placeholder = placeholderSymbol;
178
+
137
179
  function rest(func, startIndex = func.length - 1) {
138
180
  return function (...args) {
139
181
  const rest = args.slice(startIndex);
@@ -192,6 +234,10 @@ exports.identity = identity;
192
234
  exports.memoize = memoize;
193
235
  exports.negate = negate;
194
236
  exports.once = once;
237
+ exports.partial = partial;
238
+ exports.partialImpl = partialImpl;
239
+ exports.partialRight = partialRight;
240
+ exports.partialRightImpl = partialRightImpl;
195
241
  exports.rest = rest;
196
242
  exports.retry = retry;
197
243
  exports.unary = unary;
@@ -2,20 +2,6 @@
2
2
 
3
3
  const randomInt = require('./randomInt-CF7bZK.js');
4
4
 
5
- function at(arr, indices) {
6
- const result = new Array(indices.length);
7
- const length = arr.length;
8
- for (let i = 0; i < indices.length; i++) {
9
- let index = indices[i];
10
- index = Number.isInteger(index) ? index : Math.trunc(index) || 0;
11
- if (index < 0) {
12
- index += length;
13
- }
14
- result[i] = arr[index];
15
- }
16
- return result;
17
- }
18
-
19
5
  function chunk(arr, size) {
20
6
  if (!Number.isInteger(size) || size <= 0) {
21
7
  throw new Error('Size must be an integer greater than zero.');
@@ -129,10 +115,6 @@ function flatten(arr, depth = 1) {
129
115
  return result;
130
116
  }
131
117
 
132
- function flatMap(arr, iteratee, depth = 1) {
133
- return flatten(arr.map(item => iteratee(item)), depth);
134
- }
135
-
136
118
  function flattenDeep(arr) {
137
119
  return flatten(arr, Infinity);
138
120
  }
@@ -141,13 +123,6 @@ function flatMapDeep(arr, iteratee) {
141
123
  return flattenDeep(arr.map((item) => iteratee(item)));
142
124
  }
143
125
 
144
- function forEachRight(arr, callback) {
145
- for (let i = arr.length - 1; i >= 0; i--) {
146
- const element = arr[i];
147
- callback(element, i, arr);
148
- }
149
- }
150
-
151
126
  function groupBy(arr, getKeyFromItem) {
152
127
  const result = {};
153
128
  for (let i = 0; i < arr.length; i++) {
@@ -239,21 +214,6 @@ function minBy(items, getValue) {
239
214
  return minElement;
240
215
  }
241
216
 
242
- function partition(arr, isInTruthy) {
243
- const truthy = [];
244
- const falsy = [];
245
- for (let i = 0; i < arr.length; i++) {
246
- const item = arr[i];
247
- if (isInTruthy(item)) {
248
- truthy.push(item);
249
- }
250
- else {
251
- falsy.push(item);
252
- }
253
- }
254
- return [truthy, falsy];
255
- }
256
-
257
217
  function pull(arr, valuesToRemove) {
258
218
  const valuesSet = new Set(valuesToRemove);
259
219
  let resultIndex = 0;
@@ -271,15 +231,6 @@ function pull(arr, valuesToRemove) {
271
231
  return arr;
272
232
  }
273
233
 
274
- function pullAt(arr, indicesToRemove) {
275
- const removed = at(arr, indicesToRemove);
276
- const indices = new Set(indicesToRemove.slice().sort((x, y) => y - x));
277
- for (const index of indices) {
278
- arr.splice(index, 1);
279
- }
280
- return removed;
281
- }
282
-
283
234
  function remove(arr, shouldRemoveElement) {
284
235
  const originalArr = arr.slice();
285
236
  const removed = [];
@@ -334,12 +285,43 @@ function tail(arr) {
334
285
  return arr.slice(1);
335
286
  }
336
287
 
337
- function take(arr, count) {
288
+ function isSymbol(value) {
289
+ return typeof value === 'symbol' || value instanceof Symbol;
290
+ }
291
+
292
+ function toNumber(value) {
293
+ if (isSymbol(value)) {
294
+ return NaN;
295
+ }
296
+ return Number(value);
297
+ }
298
+
299
+ function toFinite(value) {
300
+ if (!value) {
301
+ return value === 0 ? value : 0;
302
+ }
303
+ value = toNumber(value);
304
+ if (value === Infinity || value === -Infinity) {
305
+ const sign = value < 0 ? -1 : 1;
306
+ return sign * Number.MAX_VALUE;
307
+ }
308
+ return value === value ? value : 0;
309
+ }
310
+
311
+ function toInteger(value) {
312
+ const finite = toFinite(value);
313
+ const remainder = finite % 1;
314
+ return remainder ? finite - remainder : finite;
315
+ }
316
+
317
+ function take(arr, count, guard) {
318
+ count = guard || count === undefined ? 1 : toInteger(count);
338
319
  return arr.slice(0, count);
339
320
  }
340
321
 
341
- function takeRight(arr, count = 1) {
342
- if (count <= 0) {
322
+ function takeRight(arr, count = 1, guard) {
323
+ count = guard || count === undefined ? 1 : toInteger(count);
324
+ if (count <= 0 || arr == null || arr.length === 0) {
343
325
  return [];
344
326
  }
345
327
  return arr.slice(-count);
@@ -480,7 +462,6 @@ function zip(...arrs) {
480
462
  return result;
481
463
  }
482
464
 
483
- exports.at = at;
484
465
  exports.chunk = chunk;
485
466
  exports.compact = compact;
486
467
  exports.countBy = countBy;
@@ -492,11 +473,9 @@ exports.dropRight = dropRight;
492
473
  exports.dropRightWhile = dropRightWhile;
493
474
  exports.dropWhile = dropWhile;
494
475
  exports.fill = fill;
495
- exports.flatMap = flatMap;
496
476
  exports.flatMapDeep = flatMapDeep;
497
477
  exports.flatten = flatten;
498
478
  exports.flattenDeep = flattenDeep;
499
- exports.forEachRight = forEachRight;
500
479
  exports.groupBy = groupBy;
501
480
  exports.head = head;
502
481
  exports.initial = initial;
@@ -505,13 +484,12 @@ exports.intersectionBy = intersectionBy;
505
484
  exports.intersectionWith = intersectionWith;
506
485
  exports.isSubset = isSubset;
507
486
  exports.isSubsetWith = isSubsetWith;
487
+ exports.isSymbol = isSymbol;
508
488
  exports.keyBy = keyBy;
509
489
  exports.last = last;
510
490
  exports.maxBy = maxBy;
511
491
  exports.minBy = minBy;
512
- exports.partition = partition;
513
492
  exports.pull = pull;
514
- exports.pullAt = pullAt;
515
493
  exports.remove = remove;
516
494
  exports.sample = sample;
517
495
  exports.sampleSize = sampleSize;
@@ -520,6 +498,9 @@ exports.tail = tail;
520
498
  exports.take = take;
521
499
  exports.takeRight = takeRight;
522
500
  exports.toFilled = toFilled;
501
+ exports.toFinite = toFinite;
502
+ exports.toInteger = toInteger;
503
+ exports.toNumber = toNumber;
523
504
  exports.union = union;
524
505
  exports.unionBy = unionBy;
525
506
  exports.unionWith = unionWith;
@@ -2,7 +2,32 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zip = require('../_chunk/zip-_HttSl.js');
5
+ const zip = require('../_chunk/zip-BJSrRi.js');
6
+
7
+ function at(arr, indices) {
8
+ const result = new Array(indices.length);
9
+ const length = arr.length;
10
+ for (let i = 0; i < indices.length; i++) {
11
+ let index = indices[i];
12
+ index = Number.isInteger(index) ? index : Math.trunc(index) || 0;
13
+ if (index < 0) {
14
+ index += length;
15
+ }
16
+ result[i] = arr[index];
17
+ }
18
+ return result;
19
+ }
20
+
21
+ function flatMap(arr, iteratee, depth = 1) {
22
+ return zip.flatten(arr.map(item => iteratee(item)), depth);
23
+ }
24
+
25
+ function forEachRight(arr, callback) {
26
+ for (let i = arr.length - 1; i >= 0; i--) {
27
+ const element = arr[i];
28
+ callback(element, i, arr);
29
+ }
30
+ }
6
31
 
7
32
  function compareValues(a, b, order) {
8
33
  if (a < b) {
@@ -32,6 +57,30 @@ function orderBy(arr, criteria, orders) {
32
57
  });
33
58
  }
34
59
 
60
+ function partition(arr, isInTruthy) {
61
+ const truthy = [];
62
+ const falsy = [];
63
+ for (let i = 0; i < arr.length; i++) {
64
+ const item = arr[i];
65
+ if (isInTruthy(item)) {
66
+ truthy.push(item);
67
+ }
68
+ else {
69
+ falsy.push(item);
70
+ }
71
+ }
72
+ return [truthy, falsy];
73
+ }
74
+
75
+ function pullAt(arr, indicesToRemove) {
76
+ const removed = at(arr, indicesToRemove);
77
+ const indices = new Set(indicesToRemove.slice().sort((x, y) => y - x));
78
+ for (const index of indices) {
79
+ arr.splice(index, 1);
80
+ }
81
+ return removed;
82
+ }
83
+
35
84
  function sortBy(arr, criteria) {
36
85
  return orderBy(arr, criteria, ['asc']);
37
86
  }
@@ -77,7 +126,6 @@ function zipWith(arr1, ...rest) {
77
126
  return result;
78
127
  }
79
128
 
80
- exports.at = zip.at;
81
129
  exports.chunk = zip.chunk;
82
130
  exports.compact = zip.compact;
83
131
  exports.countBy = zip.countBy;
@@ -89,11 +137,9 @@ exports.dropRight = zip.dropRight;
89
137
  exports.dropRightWhile = zip.dropRightWhile;
90
138
  exports.dropWhile = zip.dropWhile;
91
139
  exports.fill = zip.fill;
92
- exports.flatMap = zip.flatMap;
93
140
  exports.flatMapDeep = zip.flatMapDeep;
94
141
  exports.flatten = zip.flatten;
95
142
  exports.flattenDeep = zip.flattenDeep;
96
- exports.forEachRight = zip.forEachRight;
97
143
  exports.groupBy = zip.groupBy;
98
144
  exports.head = zip.head;
99
145
  exports.initial = zip.initial;
@@ -106,9 +152,7 @@ exports.keyBy = zip.keyBy;
106
152
  exports.last = zip.last;
107
153
  exports.maxBy = zip.maxBy;
108
154
  exports.minBy = zip.minBy;
109
- exports.partition = zip.partition;
110
155
  exports.pull = zip.pull;
111
- exports.pullAt = zip.pullAt;
112
156
  exports.remove = zip.remove;
113
157
  exports.sample = zip.sample;
114
158
  exports.sampleSize = zip.sampleSize;
@@ -131,7 +175,12 @@ exports.xor = zip.xor;
131
175
  exports.xorBy = zip.xorBy;
132
176
  exports.xorWith = zip.xorWith;
133
177
  exports.zip = zip.zip;
178
+ exports.at = at;
179
+ exports.flatMap = flatMap;
180
+ exports.forEachRight = forEachRight;
134
181
  exports.orderBy = orderBy;
182
+ exports.partition = partition;
183
+ exports.pullAt = pullAt;
135
184
  exports.sortBy = sortBy;
136
185
  exports.takeRightWhile = takeRightWhile;
137
186
  exports.takeWhile = takeWhile;
@@ -9,8 +9,6 @@
9
9
  * @returns {Array<T | undefined>} An array containing the elements that were removed from the original array.
10
10
  *
11
11
  * @example
12
- * import { pullAt } from './pullAt';
13
- *
14
12
  * const numbers = [10, 20, 30, 40, 50];
15
13
  * const removed = pullAt(numbers, [1, 3, 4]);
16
14
  * console.log(removed); // [20, 40, 50]
@@ -9,8 +9,6 @@
9
9
  * @returns {Array<T | undefined>} An array containing the elements that were removed from the original array.
10
10
  *
11
11
  * @example
12
- * import { pullAt } from './pullAt';
13
- *
14
12
  * const numbers = [10, 20, 30, 40, 50];
15
13
  * const removed = pullAt(numbers, [1, 3, 4]);
16
14
  * console.log(removed); // [20, 40, 50]
@@ -20,6 +20,6 @@
20
20
  * // Returns [1, 2, 3]
21
21
  * take([1, 2, 3], 5);
22
22
  */
23
- declare function take<T>(arr: readonly T[], count: number): T[];
23
+ declare function take<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
24
24
 
25
25
  export { take };
@@ -20,6 +20,6 @@
20
20
  * // Returns [1, 2, 3]
21
21
  * take([1, 2, 3], 5);
22
22
  */
23
- declare function take<T>(arr: readonly T[], count: number): T[];
23
+ declare function take<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
24
24
 
25
25
  export { take };
@@ -1,4 +1,7 @@
1
- function take(arr, count) {
1
+ import { toInteger } from '../compat/util/toInteger.mjs';
2
+
3
+ function take(arr, count, guard) {
4
+ count = guard || count === undefined ? 1 : toInteger(count);
2
5
  return arr.slice(0, count);
3
6
  }
4
7
 
@@ -19,6 +19,6 @@
19
19
  * // Returns [1, 2, 3]
20
20
  * takeRight([1, 2, 3], 5);
21
21
  */
22
- declare function takeRight<T>(arr: readonly T[], count?: number): T[];
22
+ declare function takeRight<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
23
23
 
24
24
  export { takeRight };
@@ -19,6 +19,6 @@
19
19
  * // Returns [1, 2, 3]
20
20
  * takeRight([1, 2, 3], 5);
21
21
  */
22
- declare function takeRight<T>(arr: readonly T[], count?: number): T[];
22
+ declare function takeRight<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
23
23
 
24
24
  export { takeRight };
@@ -1,5 +1,8 @@
1
- function takeRight(arr, count = 1) {
2
- if (count <= 0) {
1
+ import { toInteger } from '../compat/util/toInteger.mjs';
2
+
3
+ function takeRight(arr, count = 1, guard) {
4
+ count = guard || count === undefined ? 1 : toInteger(count);
5
+ if (count <= 0 || arr == null || arr.length === 0) {
3
6
  return [];
4
7
  }
5
8
  return arr.slice(-count);