es-toolkit 1.35.0-dev.1202 → 1.35.0-dev.1206

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 (91) hide show
  1. package/dist/_chunk/{isPromise-ByAybB.js → isPromise-BqEEYJ.js} +126 -40
  2. package/dist/_chunk/{reverseString-D-wK2p.js → reverseString-BixeGz.js} +84 -13
  3. package/dist/_chunk/toSnakeCaseKeys-DCXJ3Q.js +4599 -0
  4. package/dist/_chunk/{unary-BsNWRM.js → unary-EIEhcF.js} +46 -0
  5. package/dist/_chunk/{zip-DxZJSH.js → zipWith-ChDTPy.js} +76 -0
  6. package/dist/array/index.js +57 -126
  7. package/dist/browser.global.js +1 -1
  8. package/dist/browser.global.js.map +1 -1
  9. package/dist/compat/compat.d.mts +301 -0
  10. package/dist/compat/compat.d.ts +301 -0
  11. package/dist/compat/compat.mjs +303 -0
  12. package/dist/compat/function/partial.d.mts +575 -0
  13. package/dist/compat/function/partial.d.ts +575 -0
  14. package/dist/compat/function/partial.mjs +8 -0
  15. package/dist/compat/function/partialRight.d.mts +651 -0
  16. package/dist/compat/function/partialRight.d.ts +651 -0
  17. package/dist/compat/function/partialRight.mjs +8 -0
  18. package/dist/compat/index.d.mts +10 -18
  19. package/dist/compat/index.d.ts +10 -18
  20. package/dist/compat/index.js +280 -4043
  21. package/dist/compat/index.mjs +12 -18
  22. package/dist/compat/toolkit.d.mts +9 -0
  23. package/dist/compat/toolkit.d.ts +9 -0
  24. package/dist/compat/toolkit.mjs +10 -0
  25. package/dist/function/index.js +3 -4
  26. package/dist/function/partial.d.mts +3 -3
  27. package/dist/function/partial.d.ts +3 -3
  28. package/dist/function/partial.mjs +17 -19
  29. package/dist/function/partialRight.d.mts +3 -3
  30. package/dist/function/partialRight.d.ts +3 -3
  31. package/dist/function/partialRight.mjs +18 -20
  32. package/dist/index.js +84 -87
  33. package/dist/object/index.js +15 -15
  34. package/dist/object/toCamelCaseKeys.mjs +3 -0
  35. package/dist/object/toSnakeCaseKeys.mjs +3 -0
  36. package/dist/predicate/index.js +4 -5
  37. package/dist/string/index.js +7 -8
  38. package/package.json +1 -1
  39. package/dist/_chunk/isPlainObject-Xaozpc.js +0 -93
  40. package/dist/_chunk/partialRight-B0_CSB.js +0 -50
  41. package/dist/_chunk/snakeCase-BtVEeB.js +0 -75
  42. package/dist/_chunk/toSnakeCaseKeys-BNpS71.js +0 -569
  43. package/dist/compat/_internal/copyArray.mjs +0 -12
  44. package/dist/compat/array/flatMap.d.mts +0 -20
  45. package/dist/compat/array/flatMap.d.ts +0 -20
  46. package/dist/compat/array/flatMap.mjs +0 -13
  47. package/dist/compat/array/forEachRight.d.mts +0 -106
  48. package/dist/compat/array/forEachRight.d.ts +0 -106
  49. package/dist/compat/array/forEachRight.mjs +0 -21
  50. package/dist/compat/array/partition.d.mts +0 -65
  51. package/dist/compat/array/partition.d.ts +0 -65
  52. package/dist/compat/array/partition.mjs +0 -24
  53. package/dist/compat/array/pullAllWith.d.mts +0 -59
  54. package/dist/compat/array/pullAllWith.d.ts +0 -59
  55. package/dist/compat/array/pullAllWith.mjs +0 -33
  56. package/dist/compat/array/pullAt.d.mts +0 -32
  57. package/dist/compat/array/pullAt.d.ts +0 -32
  58. package/dist/compat/array/pullAt.mjs +0 -34
  59. package/dist/compat/array/zipObject.d.mts +0 -49
  60. package/dist/compat/array/zipObject.d.ts +0 -49
  61. package/dist/compat/array/zipObject.mjs +0 -11
  62. package/dist/compat/array/zipWith.d.mts +0 -92
  63. package/dist/compat/array/zipWith.d.ts +0 -92
  64. package/dist/compat/array/zipWith.mjs +0 -20
  65. package/dist/compat/object/at.d.mts +0 -19
  66. package/dist/compat/object/at.d.ts +0 -19
  67. package/dist/compat/object/at.mjs +0 -27
  68. package/dist/compat/object/forIn.d.mts +0 -58
  69. package/dist/compat/object/forIn.d.ts +0 -58
  70. package/dist/compat/object/forIn.mjs +0 -16
  71. package/dist/compat/object/forInRight.d.mts +0 -58
  72. package/dist/compat/object/forInRight.d.ts +0 -58
  73. package/dist/compat/object/forInRight.mjs +0 -21
  74. package/dist/compat/object/forOwn.d.mts +0 -54
  75. package/dist/compat/object/forOwn.d.ts +0 -54
  76. package/dist/compat/object/forOwn.mjs +0 -19
  77. package/dist/compat/object/forOwnRight.d.mts +0 -54
  78. package/dist/compat/object/forOwnRight.d.ts +0 -54
  79. package/dist/compat/object/forOwnRight.mjs +0 -19
  80. package/dist/compat/object/hasIn.d.mts +0 -40
  81. package/dist/compat/object/hasIn.d.ts +0 -40
  82. package/dist/compat/object/hasIn.mjs +0 -34
  83. package/dist/compat/string/split.d.mts +0 -19
  84. package/dist/compat/string/split.d.ts +0 -19
  85. package/dist/compat/string/split.mjs +0 -7
  86. package/dist/compat/util/overEvery.d.mts +0 -67
  87. package/dist/compat/util/overEvery.d.ts +0 -67
  88. package/dist/compat/util/overEvery.mjs +0 -23
  89. package/dist/compat/util/overSome.d.mts +0 -69
  90. package/dist/compat/util/overSome.d.ts +0 -69
  91. package/dist/compat/util/overSome.mjs +0 -23
@@ -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,6 +2,20 @@
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
+
5
19
  function chunk(arr, size) {
6
20
  if (!Number.isInteger(size) || size <= 0) {
7
21
  throw new Error('Size must be an integer greater than zero.');
@@ -115,6 +129,10 @@ function flatten(arr, depth = 1) {
115
129
  return result;
116
130
  }
117
131
 
132
+ function flatMap(arr, iteratee, depth = 1) {
133
+ return flatten(arr.map(item => iteratee(item)), depth);
134
+ }
135
+
118
136
  function flattenDeep(arr) {
119
137
  return flatten(arr, Infinity);
120
138
  }
@@ -123,6 +141,13 @@ function flatMapDeep(arr, iteratee) {
123
141
  return flattenDeep(arr.map((item) => iteratee(item)));
124
142
  }
125
143
 
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
+
126
151
  function groupBy(arr, getKeyFromItem) {
127
152
  const result = {};
128
153
  for (let i = 0; i < arr.length; i++) {
@@ -214,6 +239,21 @@ function minBy(items, getValue) {
214
239
  return minElement;
215
240
  }
216
241
 
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
+
217
257
  function pull(arr, valuesToRemove) {
218
258
  const valuesSet = new Set(valuesToRemove);
219
259
  let resultIndex = 0;
@@ -231,6 +271,15 @@ function pull(arr, valuesToRemove) {
231
271
  return arr;
232
272
  }
233
273
 
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
+
234
283
  function remove(arr, shouldRemoveElement) {
235
284
  const originalArr = arr.slice();
236
285
  const removed = [];
@@ -431,6 +480,27 @@ function zip(...arrs) {
431
480
  return result;
432
481
  }
433
482
 
483
+ function zipObject(keys, values) {
484
+ const result = {};
485
+ for (let i = 0; i < keys.length; i++) {
486
+ result[keys[i]] = values[i];
487
+ }
488
+ return result;
489
+ }
490
+
491
+ function zipWith(arr1, ...rest) {
492
+ const arrs = [arr1, ...rest.slice(0, -1)];
493
+ const combine = rest[rest.length - 1];
494
+ const maxIndex = Math.max(...arrs.map(arr => arr.length));
495
+ const result = Array(maxIndex);
496
+ for (let i = 0; i < maxIndex; i++) {
497
+ const elements = arrs.map(arr => arr[i]);
498
+ result[i] = combine(...elements);
499
+ }
500
+ return result;
501
+ }
502
+
503
+ exports.at = at;
434
504
  exports.chunk = chunk;
435
505
  exports.compact = compact;
436
506
  exports.countBy = countBy;
@@ -442,9 +512,11 @@ exports.dropRight = dropRight;
442
512
  exports.dropRightWhile = dropRightWhile;
443
513
  exports.dropWhile = dropWhile;
444
514
  exports.fill = fill;
515
+ exports.flatMap = flatMap;
445
516
  exports.flatMapDeep = flatMapDeep;
446
517
  exports.flatten = flatten;
447
518
  exports.flattenDeep = flattenDeep;
519
+ exports.forEachRight = forEachRight;
448
520
  exports.groupBy = groupBy;
449
521
  exports.head = head;
450
522
  exports.initial = initial;
@@ -457,7 +529,9 @@ exports.keyBy = keyBy;
457
529
  exports.last = last;
458
530
  exports.maxBy = maxBy;
459
531
  exports.minBy = minBy;
532
+ exports.partition = partition;
460
533
  exports.pull = pull;
534
+ exports.pullAt = pullAt;
461
535
  exports.remove = remove;
462
536
  exports.sample = sample;
463
537
  exports.sampleSize = sampleSize;
@@ -480,3 +554,5 @@ exports.xor = xor;
480
554
  exports.xorBy = xorBy;
481
555
  exports.xorWith = xorWith;
482
556
  exports.zip = zip;
557
+ exports.zipObject = zipObject;
558
+ exports.zipWith = zipWith;
@@ -2,32 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zip = require('../_chunk/zip-DxZJSH.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
- }
5
+ const zipWith = require('../_chunk/zipWith-ChDTPy.js');
31
6
 
32
7
  function compareValues(a, b, order) {
33
8
  if (a < b) {
@@ -57,30 +32,6 @@ function orderBy(arr, criteria, orders) {
57
32
  });
58
33
  }
59
34
 
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
-
84
35
  function sortBy(arr, criteria) {
85
36
  return orderBy(arr, criteria, ['asc']);
86
37
  }
@@ -106,83 +57,63 @@ function takeWhile(arr, shouldContinueTaking) {
106
57
  return result;
107
58
  }
108
59
 
109
- function zipObject(keys, values) {
110
- const result = {};
111
- for (let i = 0; i < keys.length; i++) {
112
- result[keys[i]] = values[i];
113
- }
114
- return result;
115
- }
116
-
117
- function zipWith(arr1, ...rest) {
118
- const arrs = [arr1, ...rest.slice(0, -1)];
119
- const combine = rest[rest.length - 1];
120
- const maxIndex = Math.max(...arrs.map(arr => arr.length));
121
- const result = Array(maxIndex);
122
- for (let i = 0; i < maxIndex; i++) {
123
- const elements = arrs.map(arr => arr[i]);
124
- result[i] = combine(...elements);
125
- }
126
- return result;
127
- }
128
-
129
- exports.chunk = zip.chunk;
130
- exports.compact = zip.compact;
131
- exports.countBy = zip.countBy;
132
- exports.difference = zip.difference;
133
- exports.differenceBy = zip.differenceBy;
134
- exports.differenceWith = zip.differenceWith;
135
- exports.drop = zip.drop;
136
- exports.dropRight = zip.dropRight;
137
- exports.dropRightWhile = zip.dropRightWhile;
138
- exports.dropWhile = zip.dropWhile;
139
- exports.fill = zip.fill;
140
- exports.flatMapDeep = zip.flatMapDeep;
141
- exports.flatten = zip.flatten;
142
- exports.flattenDeep = zip.flattenDeep;
143
- exports.groupBy = zip.groupBy;
144
- exports.head = zip.head;
145
- exports.initial = zip.initial;
146
- exports.intersection = zip.intersection;
147
- exports.intersectionBy = zip.intersectionBy;
148
- exports.intersectionWith = zip.intersectionWith;
149
- exports.isSubset = zip.isSubset;
150
- exports.isSubsetWith = zip.isSubsetWith;
151
- exports.keyBy = zip.keyBy;
152
- exports.last = zip.last;
153
- exports.maxBy = zip.maxBy;
154
- exports.minBy = zip.minBy;
155
- exports.pull = zip.pull;
156
- exports.remove = zip.remove;
157
- exports.sample = zip.sample;
158
- exports.sampleSize = zip.sampleSize;
159
- exports.shuffle = zip.shuffle;
160
- exports.tail = zip.tail;
161
- exports.take = zip.take;
162
- 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
- exports.uniq = zip.uniq;
168
- exports.uniqBy = zip.uniqBy;
169
- exports.uniqWith = zip.uniqWith;
170
- exports.unzip = zip.unzip;
171
- exports.unzipWith = zip.unzipWith;
172
- exports.windowed = zip.windowed;
173
- exports.without = zip.without;
174
- exports.xor = zip.xor;
175
- exports.xorBy = zip.xorBy;
176
- exports.xorWith = zip.xorWith;
177
- exports.zip = zip.zip;
178
- exports.at = at;
179
- exports.flatMap = flatMap;
180
- exports.forEachRight = forEachRight;
60
+ exports.at = zipWith.at;
61
+ exports.chunk = zipWith.chunk;
62
+ exports.compact = zipWith.compact;
63
+ exports.countBy = zipWith.countBy;
64
+ exports.difference = zipWith.difference;
65
+ exports.differenceBy = zipWith.differenceBy;
66
+ exports.differenceWith = zipWith.differenceWith;
67
+ exports.drop = zipWith.drop;
68
+ exports.dropRight = zipWith.dropRight;
69
+ exports.dropRightWhile = zipWith.dropRightWhile;
70
+ exports.dropWhile = zipWith.dropWhile;
71
+ exports.fill = zipWith.fill;
72
+ exports.flatMap = zipWith.flatMap;
73
+ exports.flatMapDeep = zipWith.flatMapDeep;
74
+ exports.flatten = zipWith.flatten;
75
+ exports.flattenDeep = zipWith.flattenDeep;
76
+ exports.forEachRight = zipWith.forEachRight;
77
+ exports.groupBy = zipWith.groupBy;
78
+ exports.head = zipWith.head;
79
+ exports.initial = zipWith.initial;
80
+ exports.intersection = zipWith.intersection;
81
+ exports.intersectionBy = zipWith.intersectionBy;
82
+ exports.intersectionWith = zipWith.intersectionWith;
83
+ exports.isSubset = zipWith.isSubset;
84
+ exports.isSubsetWith = zipWith.isSubsetWith;
85
+ exports.keyBy = zipWith.keyBy;
86
+ exports.last = zipWith.last;
87
+ exports.maxBy = zipWith.maxBy;
88
+ exports.minBy = zipWith.minBy;
89
+ exports.partition = zipWith.partition;
90
+ exports.pull = zipWith.pull;
91
+ exports.pullAt = zipWith.pullAt;
92
+ exports.remove = zipWith.remove;
93
+ exports.sample = zipWith.sample;
94
+ exports.sampleSize = zipWith.sampleSize;
95
+ exports.shuffle = zipWith.shuffle;
96
+ exports.tail = zipWith.tail;
97
+ exports.take = zipWith.take;
98
+ exports.takeRight = zipWith.takeRight;
99
+ exports.toFilled = zipWith.toFilled;
100
+ exports.union = zipWith.union;
101
+ exports.unionBy = zipWith.unionBy;
102
+ exports.unionWith = zipWith.unionWith;
103
+ exports.uniq = zipWith.uniq;
104
+ exports.uniqBy = zipWith.uniqBy;
105
+ exports.uniqWith = zipWith.uniqWith;
106
+ exports.unzip = zipWith.unzip;
107
+ exports.unzipWith = zipWith.unzipWith;
108
+ exports.windowed = zipWith.windowed;
109
+ exports.without = zipWith.without;
110
+ exports.xor = zipWith.xor;
111
+ exports.xorBy = zipWith.xorBy;
112
+ exports.xorWith = zipWith.xorWith;
113
+ exports.zip = zipWith.zip;
114
+ exports.zipObject = zipWith.zipObject;
115
+ exports.zipWith = zipWith.zipWith;
181
116
  exports.orderBy = orderBy;
182
- exports.partition = partition;
183
- exports.pullAt = pullAt;
184
117
  exports.sortBy = sortBy;
185
118
  exports.takeRightWhile = takeRightWhile;
186
119
  exports.takeWhile = takeWhile;
187
- exports.zipObject = zipObject;
188
- exports.zipWith = zipWith;