es-toolkit 1.36.0 → 1.37.0-dev.1243

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 (69) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/_chunk/isPlainObject-DINLyA.js +281 -0
  3. package/dist/_chunk/isPlainObject-Xaozpc.js +93 -0
  4. package/dist/_chunk/{isPromise-CxqI1v.js → isWeakSet-403Sh5.js} +65 -243
  5. package/dist/_chunk/{range-HnEIT7.js → range-DSpBDL.js} +0 -21
  6. package/dist/_chunk/snakeCase-BwvoPi.js +30 -0
  7. package/dist/_chunk/{unary-EIEhcF.js → unary-DzPndU.js} +0 -39
  8. package/dist/_chunk/{reverseString-BixeGz.js → upperFirst-C7IztG.js} +9 -52
  9. package/dist/_chunk/{zip-BJSrRi.js → zip-CIqPLd.js} +0 -102
  10. package/dist/array/index.js +103 -15
  11. package/dist/browser.global.js +1 -1
  12. package/dist/browser.global.js.map +1 -1
  13. package/dist/compat/_internal/compareValues.mjs +0 -3
  14. package/dist/compat/array/initial.d.mts +16 -0
  15. package/dist/compat/array/initial.d.ts +16 -0
  16. package/dist/compat/array/initial.mjs +11 -0
  17. package/dist/compat/array/keyBy.d.mts +48 -0
  18. package/dist/compat/array/keyBy.d.ts +48 -0
  19. package/dist/compat/array/keyBy.mjs +21 -0
  20. package/dist/compat/array/sampleSize.d.mts +38 -0
  21. package/dist/compat/array/sampleSize.d.ts +38 -0
  22. package/dist/compat/array/sampleSize.mjs +18 -0
  23. package/dist/compat/array/shuffle.d.mts +22 -0
  24. package/dist/compat/array/shuffle.d.ts +22 -0
  25. package/dist/compat/array/shuffle.mjs +24 -0
  26. package/dist/compat/array/unzipWith.d.mts +78 -0
  27. package/dist/compat/array/unzipWith.d.ts +78 -0
  28. package/dist/compat/array/unzipWith.mjs +21 -0
  29. package/dist/compat/array/xor.d.mts +23 -0
  30. package/dist/compat/array/xor.d.ts +23 -0
  31. package/dist/compat/array/xor.mjs +30 -0
  32. package/dist/compat/array/xorBy.d.mts +108 -0
  33. package/dist/compat/array/xorBy.d.ts +108 -0
  34. package/dist/compat/array/xorBy.mjs +23 -0
  35. package/dist/compat/array/xorWith.d.mts +89 -0
  36. package/dist/compat/array/xorWith.d.ts +89 -0
  37. package/dist/compat/array/xorWith.mjs +21 -0
  38. package/dist/compat/compat.d.mts +25 -58
  39. package/dist/compat/compat.d.ts +25 -58
  40. package/dist/compat/compat.mjs +28 -63
  41. package/dist/compat/function/wrap.d.mts +27 -0
  42. package/dist/compat/function/wrap.d.ts +27 -0
  43. package/dist/compat/function/wrap.mjs +11 -0
  44. package/dist/compat/index.d.mts +25 -58
  45. package/dist/compat/index.d.ts +25 -58
  46. package/dist/compat/index.js +4688 -327
  47. package/dist/compat/index.mjs +28 -63
  48. package/dist/compat/object/omitBy.d.mts +22 -0
  49. package/dist/compat/object/omitBy.d.ts +22 -0
  50. package/dist/compat/object/omitBy.mjs +26 -0
  51. package/dist/compat/object/result.d.mts +33 -0
  52. package/dist/compat/object/result.d.ts +33 -0
  53. package/dist/compat/object/result.mjs +24 -0
  54. package/dist/compat/object/transform.d.mts +59 -0
  55. package/dist/compat/object/transform.d.ts +59 -0
  56. package/dist/compat/object/transform.mjs +30 -0
  57. package/dist/compat/util/toString.mjs +3 -0
  58. package/dist/function/index.js +39 -3
  59. package/dist/index.js +93 -92
  60. package/dist/math/index.js +22 -3
  61. package/dist/object/index.js +122 -15
  62. package/dist/object/toCamelCaseKeys.mjs +2 -12
  63. package/dist/object/toSnakeCaseKeys.mjs +1 -11
  64. package/dist/predicate/index.js +113 -30
  65. package/dist/string/index.js +37 -22
  66. package/dist/util/index.js +19 -4
  67. package/package.json +1 -1
  68. package/dist/_chunk/invariant-BfGFfr.js +0 -21
  69. package/dist/_chunk/toSnakeCaseKeys-DZO2eB.js +0 -4901
@@ -27,16 +27,6 @@ function compact(arr) {
27
27
  return result;
28
28
  }
29
29
 
30
- function countBy(arr, mapper) {
31
- const result = {};
32
- for (let i = 0; i < arr.length; i++) {
33
- const item = arr[i];
34
- const key = mapper(item);
35
- result[key] = (result[key] ?? 0) + 1;
36
- }
37
- return result;
38
- }
39
-
40
30
  function difference(firstArr, secondArr) {
41
31
  const secondSet = new Set(secondArr);
42
32
  return firstArr.filter(item => !secondSet.has(item));
@@ -115,14 +105,6 @@ function flatten(arr, depth = 1) {
115
105
  return result;
116
106
  }
117
107
 
118
- function flattenDeep(arr) {
119
- return flatten(arr, Infinity);
120
- }
121
-
122
- function flatMapDeep(arr, iteratee) {
123
- return flattenDeep(arr.map((item) => iteratee(item)));
124
- }
125
-
126
108
  function groupBy(arr, getKeyFromItem) {
127
109
  const result = {};
128
110
  for (let i = 0; i < arr.length; i++) {
@@ -164,24 +146,6 @@ function intersectionWith(firstArr, secondArr, areItemsEqual) {
164
146
  });
165
147
  }
166
148
 
167
- function isSubset(superset, subset) {
168
- return difference(subset, superset).length === 0;
169
- }
170
-
171
- function isSubsetWith(superset, subset, areItemsEqual) {
172
- return differenceWith(subset, superset, areItemsEqual).length === 0;
173
- }
174
-
175
- function keyBy(arr, getKeyFromItem) {
176
- const result = {};
177
- for (let i = 0; i < arr.length; i++) {
178
- const item = arr[i];
179
- const key = getKeyFromItem(item);
180
- result[key] = item;
181
- }
182
- return result;
183
- }
184
-
185
149
  function last(arr) {
186
150
  return arr[arr.length - 1];
187
151
  }
@@ -327,25 +291,10 @@ function takeRight(arr, count = 1, guard) {
327
291
  return arr.slice(-count);
328
292
  }
329
293
 
330
- function toFilled(arr, value, start = 0, end = arr.length) {
331
- const length = arr.length;
332
- const finalStart = Math.max(start >= 0 ? start : length + start, 0);
333
- const finalEnd = Math.min(end >= 0 ? end : length + end, length);
334
- const newArr = arr.slice();
335
- for (let i = finalStart; i < finalEnd; i++) {
336
- newArr[i] = value;
337
- }
338
- return newArr;
339
- }
340
-
341
294
  function uniq(arr) {
342
295
  return Array.from(new Set(arr));
343
296
  }
344
297
 
345
- function union(arr1, arr2) {
346
- return uniq(arr1.concat(arr2));
347
- }
348
-
349
298
  function uniqBy(arr, mapper) {
350
299
  const map = new Map();
351
300
  for (let i = 0; i < arr.length; i++) {
@@ -358,10 +307,6 @@ function uniqBy(arr, mapper) {
358
307
  return Array.from(map.values());
359
308
  }
360
309
 
361
- function unionBy(arr1, arr2, mapper) {
362
- return uniqBy(arr1.concat(arr2), mapper);
363
- }
364
-
365
310
  function uniqWith(arr, areItemsEqual) {
366
311
  const result = [];
367
312
  for (let i = 0; i < arr.length; i++) {
@@ -374,10 +319,6 @@ function uniqWith(arr, areItemsEqual) {
374
319
  return result;
375
320
  }
376
321
 
377
- function unionWith(arr1, arr2, areItemsEqual) {
378
- return uniqWith(arr1.concat(arr2), areItemsEqual);
379
- }
380
-
381
322
  function unzip(zipped) {
382
323
  let maxLen = 0;
383
324
  for (let i = 0; i < zipped.length; i++) {
@@ -395,19 +336,6 @@ function unzip(zipped) {
395
336
  return result;
396
337
  }
397
338
 
398
- function unzipWith(target, iteratee) {
399
- const maxLength = Math.max(...target.map(innerArray => innerArray.length));
400
- const result = new Array(maxLength);
401
- for (let i = 0; i < maxLength; i++) {
402
- const group = new Array(target.length);
403
- for (let j = 0; j < target.length; j++) {
404
- group[j] = target[j][i];
405
- }
406
- result[i] = iteratee(...group);
407
- }
408
- return result;
409
- }
410
-
411
339
  function windowed(arr, size, step = 1, { partialWindows = false } = {}) {
412
340
  if (size <= 0 || !Number.isInteger(size)) {
413
341
  throw new Error('Size must be a positive integer.');
@@ -427,22 +355,6 @@ function without(array, ...values) {
427
355
  return difference(array, values);
428
356
  }
429
357
 
430
- function xor(arr1, arr2) {
431
- return difference(union(arr1, arr2), intersection(arr1, arr2));
432
- }
433
-
434
- function xorBy(arr1, arr2, mapper) {
435
- const union = unionBy(arr1, arr2, mapper);
436
- const intersection = intersectionBy(arr1, arr2, mapper);
437
- return differenceBy(union, intersection, mapper);
438
- }
439
-
440
- function xorWith(arr1, arr2, areElementsEqual) {
441
- const union = unionWith(arr1, arr2, areElementsEqual);
442
- const intersection = intersectionWith(arr1, arr2, areElementsEqual);
443
- return differenceWith(union, intersection, areElementsEqual);
444
- }
445
-
446
358
  function zip(...arrs) {
447
359
  let rowCount = 0;
448
360
  for (let i = 0; i < arrs.length; i++) {
@@ -464,7 +376,6 @@ function zip(...arrs) {
464
376
 
465
377
  exports.chunk = chunk;
466
378
  exports.compact = compact;
467
- exports.countBy = countBy;
468
379
  exports.difference = difference;
469
380
  exports.differenceBy = differenceBy;
470
381
  exports.differenceWith = differenceWith;
@@ -473,19 +384,14 @@ exports.dropRight = dropRight;
473
384
  exports.dropRightWhile = dropRightWhile;
474
385
  exports.dropWhile = dropWhile;
475
386
  exports.fill = fill;
476
- exports.flatMapDeep = flatMapDeep;
477
387
  exports.flatten = flatten;
478
- exports.flattenDeep = flattenDeep;
479
388
  exports.groupBy = groupBy;
480
389
  exports.head = head;
481
390
  exports.initial = initial;
482
391
  exports.intersection = intersection;
483
392
  exports.intersectionBy = intersectionBy;
484
393
  exports.intersectionWith = intersectionWith;
485
- exports.isSubset = isSubset;
486
- exports.isSubsetWith = isSubsetWith;
487
394
  exports.isSymbol = isSymbol;
488
- exports.keyBy = keyBy;
489
395
  exports.last = last;
490
396
  exports.maxBy = maxBy;
491
397
  exports.minBy = minBy;
@@ -497,21 +403,13 @@ exports.shuffle = shuffle;
497
403
  exports.tail = tail;
498
404
  exports.take = take;
499
405
  exports.takeRight = takeRight;
500
- exports.toFilled = toFilled;
501
406
  exports.toFinite = toFinite;
502
407
  exports.toInteger = toInteger;
503
408
  exports.toNumber = toNumber;
504
- exports.union = union;
505
- exports.unionBy = unionBy;
506
- exports.unionWith = unionWith;
507
409
  exports.uniq = uniq;
508
410
  exports.uniqBy = uniqBy;
509
411
  exports.uniqWith = uniqWith;
510
412
  exports.unzip = unzip;
511
- exports.unzipWith = unzipWith;
512
413
  exports.windowed = windowed;
513
414
  exports.without = without;
514
- exports.xor = xor;
515
- exports.xorBy = xorBy;
516
- exports.xorWith = xorWith;
517
415
  exports.zip = zip;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zip = require('../_chunk/zip-BJSrRi.js');
5
+ const zip = require('../_chunk/zip-CIqPLd.js');
6
6
 
7
7
  function at(arr, indices) {
8
8
  const result = new Array(indices.length);
@@ -18,10 +18,28 @@ function at(arr, indices) {
18
18
  return result;
19
19
  }
20
20
 
21
+ function countBy(arr, mapper) {
22
+ const result = {};
23
+ for (let i = 0; i < arr.length; i++) {
24
+ const item = arr[i];
25
+ const key = mapper(item);
26
+ result[key] = (result[key] ?? 0) + 1;
27
+ }
28
+ return result;
29
+ }
30
+
21
31
  function flatMap(arr, iteratee, depth = 1) {
22
32
  return zip.flatten(arr.map(item => iteratee(item)), depth);
23
33
  }
24
34
 
35
+ function flattenDeep(arr) {
36
+ return zip.flatten(arr, Infinity);
37
+ }
38
+
39
+ function flatMapDeep(arr, iteratee) {
40
+ return flattenDeep(arr.map((item) => iteratee(item)));
41
+ }
42
+
25
43
  function forEachRight(arr, callback) {
26
44
  for (let i = arr.length - 1; i >= 0; i--) {
27
45
  const element = arr[i];
@@ -29,6 +47,24 @@ function forEachRight(arr, callback) {
29
47
  }
30
48
  }
31
49
 
50
+ function isSubset(superset, subset) {
51
+ return zip.difference(subset, superset).length === 0;
52
+ }
53
+
54
+ function isSubsetWith(superset, subset, areItemsEqual) {
55
+ return zip.differenceWith(subset, superset, areItemsEqual).length === 0;
56
+ }
57
+
58
+ function keyBy(arr, getKeyFromItem) {
59
+ const result = {};
60
+ for (let i = 0; i < arr.length; i++) {
61
+ const item = arr[i];
62
+ const key = getKeyFromItem(item);
63
+ result[key] = item;
64
+ }
65
+ return result;
66
+ }
67
+
32
68
  function compareValues(a, b, order) {
33
69
  if (a < b) {
34
70
  return order === 'asc' ? -1 : 1;
@@ -106,6 +142,58 @@ function takeWhile(arr, shouldContinueTaking) {
106
142
  return result;
107
143
  }
108
144
 
145
+ function toFilled(arr, value, start = 0, end = arr.length) {
146
+ const length = arr.length;
147
+ const finalStart = Math.max(start >= 0 ? start : length + start, 0);
148
+ const finalEnd = Math.min(end >= 0 ? end : length + end, length);
149
+ const newArr = arr.slice();
150
+ for (let i = finalStart; i < finalEnd; i++) {
151
+ newArr[i] = value;
152
+ }
153
+ return newArr;
154
+ }
155
+
156
+ function union(arr1, arr2) {
157
+ return zip.uniq(arr1.concat(arr2));
158
+ }
159
+
160
+ function unionBy(arr1, arr2, mapper) {
161
+ return zip.uniqBy(arr1.concat(arr2), mapper);
162
+ }
163
+
164
+ function unionWith(arr1, arr2, areItemsEqual) {
165
+ return zip.uniqWith(arr1.concat(arr2), areItemsEqual);
166
+ }
167
+
168
+ function unzipWith(target, iteratee) {
169
+ const maxLength = Math.max(...target.map(innerArray => innerArray.length));
170
+ const result = new Array(maxLength);
171
+ for (let i = 0; i < maxLength; i++) {
172
+ const group = new Array(target.length);
173
+ for (let j = 0; j < target.length; j++) {
174
+ group[j] = target[j][i];
175
+ }
176
+ result[i] = iteratee(...group);
177
+ }
178
+ return result;
179
+ }
180
+
181
+ function xor(arr1, arr2) {
182
+ return zip.difference(union(arr1, arr2), zip.intersection(arr1, arr2));
183
+ }
184
+
185
+ function xorBy(arr1, arr2, mapper) {
186
+ const union = unionBy(arr1, arr2, mapper);
187
+ const intersection = zip.intersectionBy(arr1, arr2, mapper);
188
+ return zip.differenceBy(union, intersection, mapper);
189
+ }
190
+
191
+ function xorWith(arr1, arr2, areElementsEqual) {
192
+ const union = unionWith(arr1, arr2, areElementsEqual);
193
+ const intersection = zip.intersectionWith(arr1, arr2, areElementsEqual);
194
+ return zip.differenceWith(union, intersection, areElementsEqual);
195
+ }
196
+
109
197
  function zipObject(keys, values) {
110
198
  const result = {};
111
199
  for (let i = 0; i < keys.length; i++) {
@@ -128,7 +216,6 @@ function zipWith(arr1, ...rest) {
128
216
 
129
217
  exports.chunk = zip.chunk;
130
218
  exports.compact = zip.compact;
131
- exports.countBy = zip.countBy;
132
219
  exports.difference = zip.difference;
133
220
  exports.differenceBy = zip.differenceBy;
134
221
  exports.differenceWith = zip.differenceWith;
@@ -137,18 +224,13 @@ exports.dropRight = zip.dropRight;
137
224
  exports.dropRightWhile = zip.dropRightWhile;
138
225
  exports.dropWhile = zip.dropWhile;
139
226
  exports.fill = zip.fill;
140
- exports.flatMapDeep = zip.flatMapDeep;
141
227
  exports.flatten = zip.flatten;
142
- exports.flattenDeep = zip.flattenDeep;
143
228
  exports.groupBy = zip.groupBy;
144
229
  exports.head = zip.head;
145
230
  exports.initial = zip.initial;
146
231
  exports.intersection = zip.intersection;
147
232
  exports.intersectionBy = zip.intersectionBy;
148
233
  exports.intersectionWith = zip.intersectionWith;
149
- exports.isSubset = zip.isSubset;
150
- exports.isSubsetWith = zip.isSubsetWith;
151
- exports.keyBy = zip.keyBy;
152
234
  exports.last = zip.last;
153
235
  exports.maxBy = zip.maxBy;
154
236
  exports.minBy = zip.minBy;
@@ -160,29 +242,35 @@ exports.shuffle = zip.shuffle;
160
242
  exports.tail = zip.tail;
161
243
  exports.take = zip.take;
162
244
  exports.takeRight = zip.takeRight;
163
- exports.toFilled = zip.toFilled;
164
- exports.union = zip.union;
165
- exports.unionBy = zip.unionBy;
166
- exports.unionWith = zip.unionWith;
167
245
  exports.uniq = zip.uniq;
168
246
  exports.uniqBy = zip.uniqBy;
169
247
  exports.uniqWith = zip.uniqWith;
170
248
  exports.unzip = zip.unzip;
171
- exports.unzipWith = zip.unzipWith;
172
249
  exports.windowed = zip.windowed;
173
250
  exports.without = zip.without;
174
- exports.xor = zip.xor;
175
- exports.xorBy = zip.xorBy;
176
- exports.xorWith = zip.xorWith;
177
251
  exports.zip = zip.zip;
178
252
  exports.at = at;
253
+ exports.countBy = countBy;
179
254
  exports.flatMap = flatMap;
255
+ exports.flatMapDeep = flatMapDeep;
256
+ exports.flattenDeep = flattenDeep;
180
257
  exports.forEachRight = forEachRight;
258
+ exports.isSubset = isSubset;
259
+ exports.isSubsetWith = isSubsetWith;
260
+ exports.keyBy = keyBy;
181
261
  exports.orderBy = orderBy;
182
262
  exports.partition = partition;
183
263
  exports.pullAt = pullAt;
184
264
  exports.sortBy = sortBy;
185
265
  exports.takeRightWhile = takeRightWhile;
186
266
  exports.takeWhile = takeWhile;
267
+ exports.toFilled = toFilled;
268
+ exports.union = union;
269
+ exports.unionBy = unionBy;
270
+ exports.unionWith = unionWith;
271
+ exports.unzipWith = unzipWith;
272
+ exports.xor = xor;
273
+ exports.xorBy = xorBy;
274
+ exports.xorWith = xorWith;
187
275
  exports.zipObject = zipObject;
188
276
  exports.zipWith = zipWith;