es-toolkit 1.37.0 → 1.37.1
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.
- package/CHANGELOG.md +6 -0
- package/dist/_chunk/{toSnakeCaseKeys-kqZCyq.js → isPlainObject-DINLyA.js} +0 -98
- package/dist/_chunk/{isWeakSet-C2NpfO.js → isWeakSet-403Sh5.js} +0 -92
- package/dist/_chunk/{range-HnEIT7.js → range-DSpBDL.js} +0 -21
- package/dist/_chunk/{unary-EIEhcF.js → unary-DzPndU.js} +0 -39
- package/dist/_chunk/{upperFirst-DbrFSz.js → upperFirst-C7IztG.js} +0 -17
- package/dist/_chunk/{zip-DDfXXG.js → zip-CIqPLd.js} +0 -78
- package/dist/array/index.js +79 -12
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/initial.d.mts +16 -0
- package/dist/compat/array/initial.d.ts +16 -0
- package/dist/compat/array/initial.mjs +11 -0
- package/dist/compat/array/keyBy.d.mts +48 -0
- package/dist/compat/array/keyBy.d.ts +48 -0
- package/dist/compat/array/keyBy.mjs +21 -0
- package/dist/compat/array/shuffle.d.mts +22 -0
- package/dist/compat/array/shuffle.d.ts +22 -0
- package/dist/compat/array/shuffle.mjs +24 -0
- package/dist/compat/array/xorBy.d.mts +108 -0
- package/dist/compat/array/xorBy.d.ts +108 -0
- package/dist/compat/array/xorBy.mjs +23 -0
- package/dist/compat/array/xorWith.d.mts +89 -0
- package/dist/compat/array/xorWith.d.ts +89 -0
- package/dist/compat/array/xorWith.mjs +21 -0
- package/dist/compat/compat.d.mts +19 -54
- package/dist/compat/compat.d.ts +19 -54
- package/dist/compat/compat.mjs +22 -59
- package/dist/compat/function/wrap.d.mts +27 -0
- package/dist/compat/function/wrap.d.ts +27 -0
- package/dist/compat/function/wrap.mjs +11 -0
- package/dist/compat/index.d.mts +19 -54
- package/dist/compat/index.d.ts +19 -54
- package/dist/compat/index.js +172 -180
- package/dist/compat/index.mjs +22 -59
- package/dist/function/index.js +39 -3
- package/dist/index.js +56 -57
- package/dist/math/index.js +22 -3
- package/dist/object/index.js +108 -14
- package/dist/predicate/index.js +93 -11
- package/dist/string/index.js +18 -4
- package/dist/util/index.js +19 -4
- package/package.json +1 -1
- package/dist/_chunk/invariant-BfGFfr.js +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const isPlainObject$1 = require('./isPlainObject-Xaozpc.js');
|
|
4
|
-
const snakeCase = require('./snakeCase-BwvoPi.js');
|
|
5
4
|
|
|
6
5
|
function clone(obj) {
|
|
7
6
|
if (isPlainObject$1.isPrimitive(obj)) {
|
|
@@ -200,29 +199,6 @@ function findKey(obj, predicate) {
|
|
|
200
199
|
return keys.find(key => predicate(obj[key], key, obj));
|
|
201
200
|
}
|
|
202
201
|
|
|
203
|
-
function flattenObject(object, { delimiter = '.' } = {}) {
|
|
204
|
-
return flattenObjectImpl(object, '', delimiter);
|
|
205
|
-
}
|
|
206
|
-
function flattenObjectImpl(object, prefix = '', delimiter = '.') {
|
|
207
|
-
const result = {};
|
|
208
|
-
const keys = Object.keys(object);
|
|
209
|
-
for (let i = 0; i < keys.length; i++) {
|
|
210
|
-
const key = keys[i];
|
|
211
|
-
const value = object[key];
|
|
212
|
-
const prefixedKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
213
|
-
if (isPlainObject$1.isPlainObject(value) && Object.keys(value).length > 0) {
|
|
214
|
-
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (Array.isArray(value)) {
|
|
218
|
-
Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
result[prefixedKey] = value;
|
|
222
|
-
}
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
202
|
function invert(obj) {
|
|
227
203
|
const result = {};
|
|
228
204
|
const keys = Object.keys(obj);
|
|
@@ -256,35 +232,6 @@ function mapValues(object, getNewValue) {
|
|
|
256
232
|
return result;
|
|
257
233
|
}
|
|
258
234
|
|
|
259
|
-
function merge(target, source) {
|
|
260
|
-
const sourceKeys = Object.keys(source);
|
|
261
|
-
for (let i = 0; i < sourceKeys.length; i++) {
|
|
262
|
-
const key = sourceKeys[i];
|
|
263
|
-
const sourceValue = source[key];
|
|
264
|
-
const targetValue = target[key];
|
|
265
|
-
if (Array.isArray(sourceValue)) {
|
|
266
|
-
if (Array.isArray(targetValue)) {
|
|
267
|
-
target[key] = merge(targetValue, sourceValue);
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
target[key] = merge([], sourceValue);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else if (isPlainObject$1.isPlainObject(sourceValue)) {
|
|
274
|
-
if (isPlainObject$1.isPlainObject(targetValue)) {
|
|
275
|
-
target[key] = merge(targetValue, sourceValue);
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
target[key] = merge({}, sourceValue);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
else if (targetValue === undefined || sourceValue !== undefined) {
|
|
282
|
-
target[key] = sourceValue;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return target;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
235
|
function isObjectLike(value) {
|
|
289
236
|
return typeof value === 'object' && value !== null;
|
|
290
237
|
}
|
|
@@ -293,28 +240,6 @@ function isArray(value) {
|
|
|
293
240
|
return Array.isArray(value);
|
|
294
241
|
}
|
|
295
242
|
|
|
296
|
-
function toCamelCaseKeys(obj) {
|
|
297
|
-
if (isArray(obj)) {
|
|
298
|
-
return obj.map(item => toCamelCaseKeys(item));
|
|
299
|
-
}
|
|
300
|
-
if (isPlainObject$1.isPlainObject(obj)) {
|
|
301
|
-
const result = {};
|
|
302
|
-
const keys = Object.keys(obj);
|
|
303
|
-
for (let i = 0; i < keys.length; i++) {
|
|
304
|
-
const key = keys[i];
|
|
305
|
-
const camelKey = snakeCase.camelCase(key);
|
|
306
|
-
const camelCaseKeys = toCamelCaseKeys(obj[key]);
|
|
307
|
-
result[camelKey] = camelCaseKeys;
|
|
308
|
-
}
|
|
309
|
-
return result;
|
|
310
|
-
}
|
|
311
|
-
return obj;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function toMerged(target, source) {
|
|
315
|
-
return merge(cloneDeep(target), source);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
243
|
function isPlainObject(object) {
|
|
319
244
|
if (typeof object !== 'object') {
|
|
320
245
|
return false;
|
|
@@ -343,37 +268,14 @@ function isPlainObject(object) {
|
|
|
343
268
|
return Object.getPrototypeOf(object) === proto;
|
|
344
269
|
}
|
|
345
270
|
|
|
346
|
-
function toSnakeCaseKeys(obj) {
|
|
347
|
-
if (isArray(obj)) {
|
|
348
|
-
return obj.map(item => toSnakeCaseKeys(item));
|
|
349
|
-
}
|
|
350
|
-
if (isPlainObject(obj)) {
|
|
351
|
-
const result = {};
|
|
352
|
-
const keys = Object.keys(obj);
|
|
353
|
-
for (let i = 0; i < keys.length; i++) {
|
|
354
|
-
const key = keys[i];
|
|
355
|
-
const snakeKey = snakeCase.snakeCase(key);
|
|
356
|
-
const snakeCaseKeys = toSnakeCaseKeys(obj[key]);
|
|
357
|
-
result[snakeKey] = snakeCaseKeys;
|
|
358
|
-
}
|
|
359
|
-
return result;
|
|
360
|
-
}
|
|
361
|
-
return obj;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
271
|
exports.clone = clone;
|
|
365
272
|
exports.cloneDeep = cloneDeep;
|
|
366
273
|
exports.cloneDeepWith = cloneDeepWith;
|
|
367
274
|
exports.copyProperties = copyProperties;
|
|
368
275
|
exports.findKey = findKey;
|
|
369
|
-
exports.flattenObject = flattenObject;
|
|
370
276
|
exports.invert = invert;
|
|
371
277
|
exports.isArray = isArray;
|
|
372
278
|
exports.isObjectLike = isObjectLike;
|
|
373
279
|
exports.isPlainObject = isPlainObject;
|
|
374
280
|
exports.mapKeys = mapKeys;
|
|
375
281
|
exports.mapValues = mapValues;
|
|
376
|
-
exports.merge = merge;
|
|
377
|
-
exports.toCamelCaseKeys = toCamelCaseKeys;
|
|
378
|
-
exports.toMerged = toMerged;
|
|
379
|
-
exports.toSnakeCaseKeys = toSnakeCaseKeys;
|
|
@@ -7,17 +7,6 @@ function isArrayBuffer(value) {
|
|
|
7
7
|
return value instanceof ArrayBuffer;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function isBlob(x) {
|
|
11
|
-
if (typeof Blob === 'undefined') {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return x instanceof Blob;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isBrowser() {
|
|
18
|
-
return typeof window !== 'undefined' && window?.document != null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
10
|
function isBuffer(x) {
|
|
22
11
|
return typeof Buffer !== 'undefined' && Buffer.isBuffer(x);
|
|
23
12
|
}
|
|
@@ -212,69 +201,10 @@ function isEqual(a, b) {
|
|
|
212
201
|
return isEqualWith(a, b, noop.noop);
|
|
213
202
|
}
|
|
214
203
|
|
|
215
|
-
function isFile(x) {
|
|
216
|
-
if (typeof File === 'undefined') {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
return isBlob(x) && x instanceof File;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
204
|
function isFunction(value) {
|
|
223
205
|
return typeof value === 'function';
|
|
224
206
|
}
|
|
225
207
|
|
|
226
|
-
function isJSON(value) {
|
|
227
|
-
if (typeof value !== 'string') {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
JSON.parse(value);
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
catch {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function isJSONValue(value) {
|
|
240
|
-
switch (typeof value) {
|
|
241
|
-
case 'object': {
|
|
242
|
-
return value === null || isJSONArray(value) || isJSONObject(value);
|
|
243
|
-
}
|
|
244
|
-
case 'string':
|
|
245
|
-
case 'number':
|
|
246
|
-
case 'boolean': {
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
default: {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
function isJSONArray(value) {
|
|
255
|
-
if (!Array.isArray(value)) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
return value.every(item => isJSONValue(item));
|
|
259
|
-
}
|
|
260
|
-
function isJSONObject(obj) {
|
|
261
|
-
if (!isPlainObject.isPlainObject(obj)) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
const keys = Reflect.ownKeys(obj);
|
|
265
|
-
for (let i = 0; i < keys.length; i++) {
|
|
266
|
-
const key = keys[i];
|
|
267
|
-
const value = obj[key];
|
|
268
|
-
if (typeof key !== 'string') {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
if (!isJSONValue(value)) {
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return true;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
208
|
function isLength(value) {
|
|
279
209
|
return Number.isSafeInteger(value) && value >= 0;
|
|
280
210
|
}
|
|
@@ -287,22 +217,10 @@ function isNil(x) {
|
|
|
287
217
|
return x == null;
|
|
288
218
|
}
|
|
289
219
|
|
|
290
|
-
function isNode() {
|
|
291
|
-
return typeof process !== 'undefined' && process?.versions?.node != null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function isNotNil(x) {
|
|
295
|
-
return x != null;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
220
|
function isNull(x) {
|
|
299
221
|
return x === null;
|
|
300
222
|
}
|
|
301
223
|
|
|
302
|
-
function isPromise(value) {
|
|
303
|
-
return value instanceof Promise;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
224
|
function isRegExp(value) {
|
|
307
225
|
return value instanceof RegExp;
|
|
308
226
|
}
|
|
@@ -329,25 +247,15 @@ function isWeakSet(value) {
|
|
|
329
247
|
|
|
330
248
|
exports.eq = eq;
|
|
331
249
|
exports.isArrayBuffer = isArrayBuffer;
|
|
332
|
-
exports.isBlob = isBlob;
|
|
333
|
-
exports.isBrowser = isBrowser;
|
|
334
250
|
exports.isBuffer = isBuffer;
|
|
335
251
|
exports.isDate = isDate;
|
|
336
252
|
exports.isEqual = isEqual;
|
|
337
253
|
exports.isEqualWith = isEqualWith;
|
|
338
|
-
exports.isFile = isFile;
|
|
339
254
|
exports.isFunction = isFunction;
|
|
340
|
-
exports.isJSON = isJSON;
|
|
341
|
-
exports.isJSONArray = isJSONArray;
|
|
342
|
-
exports.isJSONObject = isJSONObject;
|
|
343
|
-
exports.isJSONValue = isJSONValue;
|
|
344
255
|
exports.isLength = isLength;
|
|
345
256
|
exports.isMap = isMap;
|
|
346
257
|
exports.isNil = isNil;
|
|
347
|
-
exports.isNode = isNode;
|
|
348
|
-
exports.isNotNil = isNotNil;
|
|
349
258
|
exports.isNull = isNull;
|
|
350
|
-
exports.isPromise = isPromise;
|
|
351
259
|
exports.isRegExp = isRegExp;
|
|
352
260
|
exports.isSet = isSet;
|
|
353
261
|
exports.isSymbol = isSymbol;
|
|
@@ -35,25 +35,6 @@ function meanBy(items, getValue) {
|
|
|
35
35
|
return mean(nums);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function median(nums) {
|
|
39
|
-
if (nums.length === 0) {
|
|
40
|
-
return NaN;
|
|
41
|
-
}
|
|
42
|
-
const sorted = nums.slice().sort((a, b) => a - b);
|
|
43
|
-
const middleIndex = Math.floor(sorted.length / 2);
|
|
44
|
-
if (sorted.length % 2 === 0) {
|
|
45
|
-
return (sorted[middleIndex - 1] + sorted[middleIndex]) / 2;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return sorted[middleIndex];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function medianBy(items, getValue) {
|
|
53
|
-
const nums = items.map(x => getValue(x));
|
|
54
|
-
return median(nums);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
38
|
function range(start, end, step = 1) {
|
|
58
39
|
if (end == null) {
|
|
59
40
|
end = start;
|
|
@@ -74,7 +55,5 @@ exports.clamp = clamp;
|
|
|
74
55
|
exports.inRange = inRange;
|
|
75
56
|
exports.mean = mean;
|
|
76
57
|
exports.meanBy = meanBy;
|
|
77
|
-
exports.median = median;
|
|
78
|
-
exports.medianBy = medianBy;
|
|
79
58
|
exports.range = range;
|
|
80
59
|
exports.sum = sum;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const delay = require('./delay-_VMfFa.js');
|
|
4
|
-
|
|
5
3
|
function after(n, func) {
|
|
6
4
|
if (!Number.isInteger(n) || n < 0) {
|
|
7
5
|
throw new Error(`n must be a non-negative integer.`);
|
|
@@ -21,8 +19,6 @@ function ary(func, n) {
|
|
|
21
19
|
};
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
async function asyncNoop() { }
|
|
25
|
-
|
|
26
22
|
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
27
23
|
let pendingThis = undefined;
|
|
28
24
|
let pendingArgs = null;
|
|
@@ -187,46 +183,12 @@ function rest(func, startIndex = func.length - 1) {
|
|
|
187
183
|
};
|
|
188
184
|
}
|
|
189
185
|
|
|
190
|
-
const DEFAULT_DELAY = 0;
|
|
191
|
-
const DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
|
|
192
|
-
async function retry(func, _options) {
|
|
193
|
-
let delay$1;
|
|
194
|
-
let retries;
|
|
195
|
-
let signal;
|
|
196
|
-
if (typeof _options === 'number') {
|
|
197
|
-
delay$1 = DEFAULT_DELAY;
|
|
198
|
-
retries = _options;
|
|
199
|
-
signal = undefined;
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
delay$1 = _options?.delay ?? DEFAULT_DELAY;
|
|
203
|
-
retries = _options?.retries ?? DEFAULT_RETRIES;
|
|
204
|
-
signal = _options?.signal;
|
|
205
|
-
}
|
|
206
|
-
let error;
|
|
207
|
-
for (let attempts = 0; attempts < retries; attempts++) {
|
|
208
|
-
if (signal?.aborted) {
|
|
209
|
-
throw error ?? new Error(`The retry operation was aborted due to an abort signal.`);
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
return await func();
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
error = err;
|
|
216
|
-
const currentDelay = typeof delay$1 === 'function' ? delay$1(attempts) : delay$1;
|
|
217
|
-
await delay.delay(currentDelay);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
186
|
function unary(func) {
|
|
224
187
|
return ary(func, 1);
|
|
225
188
|
}
|
|
226
189
|
|
|
227
190
|
exports.after = after;
|
|
228
191
|
exports.ary = ary;
|
|
229
|
-
exports.asyncNoop = asyncNoop;
|
|
230
192
|
exports.debounce = debounce;
|
|
231
193
|
exports.flow = flow;
|
|
232
194
|
exports.flowRight = flowRight;
|
|
@@ -239,5 +201,4 @@ exports.partialImpl = partialImpl;
|
|
|
239
201
|
exports.partialRight = partialRight;
|
|
240
202
|
exports.partialRightImpl = partialRightImpl;
|
|
241
203
|
exports.rest = rest;
|
|
242
|
-
exports.retry = retry;
|
|
243
204
|
exports.unary = unary;
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const snakeCase = require('./snakeCase-BwvoPi.js');
|
|
4
4
|
|
|
5
|
-
function constantCase(str) {
|
|
6
|
-
const words = snakeCase.words(str);
|
|
7
|
-
return words.map(word => word.toUpperCase()).join('_');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
5
|
const deburrMap = new Map(Object.entries({
|
|
11
6
|
Æ: 'Ae',
|
|
12
7
|
Ð: 'D',
|
|
@@ -84,15 +79,6 @@ function pad(str, length, chars = ' ') {
|
|
|
84
79
|
return str.padStart(Math.floor((length - str.length) / 2) + str.length, chars).padEnd(length, chars);
|
|
85
80
|
}
|
|
86
81
|
|
|
87
|
-
function pascalCase(str) {
|
|
88
|
-
const words = snakeCase.words(str);
|
|
89
|
-
return words.map(word => snakeCase.capitalize(word)).join('');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function reverseString(value) {
|
|
93
|
-
return [...value].reverse().join('');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
82
|
function trimEnd(str, chars) {
|
|
97
83
|
if (chars === undefined) {
|
|
98
84
|
return str.trimEnd();
|
|
@@ -172,7 +158,6 @@ function upperFirst(str) {
|
|
|
172
158
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
173
159
|
}
|
|
174
160
|
|
|
175
|
-
exports.constantCase = constantCase;
|
|
176
161
|
exports.deburr = deburr;
|
|
177
162
|
exports.escape = escape;
|
|
178
163
|
exports.escapeRegExp = escapeRegExp;
|
|
@@ -180,8 +165,6 @@ exports.kebabCase = kebabCase;
|
|
|
180
165
|
exports.lowerCase = lowerCase;
|
|
181
166
|
exports.lowerFirst = lowerFirst;
|
|
182
167
|
exports.pad = pad;
|
|
183
|
-
exports.pascalCase = pascalCase;
|
|
184
|
-
exports.reverseString = reverseString;
|
|
185
168
|
exports.trim = trim;
|
|
186
169
|
exports.trimEnd = trimEnd;
|
|
187
170
|
exports.trimStart = trimStart;
|
|
@@ -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,17 +291,6 @@ 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
|
}
|
|
@@ -354,10 +307,6 @@ function uniqBy(arr, mapper) {
|
|
|
354
307
|
return Array.from(map.values());
|
|
355
308
|
}
|
|
356
309
|
|
|
357
|
-
function unionBy(arr1, arr2, mapper) {
|
|
358
|
-
return uniqBy(arr1.concat(arr2), mapper);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
310
|
function uniqWith(arr, areItemsEqual) {
|
|
362
311
|
const result = [];
|
|
363
312
|
for (let i = 0; i < arr.length; i++) {
|
|
@@ -370,10 +319,6 @@ function uniqWith(arr, areItemsEqual) {
|
|
|
370
319
|
return result;
|
|
371
320
|
}
|
|
372
321
|
|
|
373
|
-
function unionWith(arr1, arr2, areItemsEqual) {
|
|
374
|
-
return uniqWith(arr1.concat(arr2), areItemsEqual);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
322
|
function unzip(zipped) {
|
|
378
323
|
let maxLen = 0;
|
|
379
324
|
for (let i = 0; i < zipped.length; i++) {
|
|
@@ -410,18 +355,6 @@ function without(array, ...values) {
|
|
|
410
355
|
return difference(array, values);
|
|
411
356
|
}
|
|
412
357
|
|
|
413
|
-
function xorBy(arr1, arr2, mapper) {
|
|
414
|
-
const union = unionBy(arr1, arr2, mapper);
|
|
415
|
-
const intersection = intersectionBy(arr1, arr2, mapper);
|
|
416
|
-
return differenceBy(union, intersection, mapper);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function xorWith(arr1, arr2, areElementsEqual) {
|
|
420
|
-
const union = unionWith(arr1, arr2, areElementsEqual);
|
|
421
|
-
const intersection = intersectionWith(arr1, arr2, areElementsEqual);
|
|
422
|
-
return differenceWith(union, intersection, areElementsEqual);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
358
|
function zip(...arrs) {
|
|
426
359
|
let rowCount = 0;
|
|
427
360
|
for (let i = 0; i < arrs.length; i++) {
|
|
@@ -443,7 +376,6 @@ function zip(...arrs) {
|
|
|
443
376
|
|
|
444
377
|
exports.chunk = chunk;
|
|
445
378
|
exports.compact = compact;
|
|
446
|
-
exports.countBy = countBy;
|
|
447
379
|
exports.difference = difference;
|
|
448
380
|
exports.differenceBy = differenceBy;
|
|
449
381
|
exports.differenceWith = differenceWith;
|
|
@@ -452,19 +384,14 @@ exports.dropRight = dropRight;
|
|
|
452
384
|
exports.dropRightWhile = dropRightWhile;
|
|
453
385
|
exports.dropWhile = dropWhile;
|
|
454
386
|
exports.fill = fill;
|
|
455
|
-
exports.flatMapDeep = flatMapDeep;
|
|
456
387
|
exports.flatten = flatten;
|
|
457
|
-
exports.flattenDeep = flattenDeep;
|
|
458
388
|
exports.groupBy = groupBy;
|
|
459
389
|
exports.head = head;
|
|
460
390
|
exports.initial = initial;
|
|
461
391
|
exports.intersection = intersection;
|
|
462
392
|
exports.intersectionBy = intersectionBy;
|
|
463
393
|
exports.intersectionWith = intersectionWith;
|
|
464
|
-
exports.isSubset = isSubset;
|
|
465
|
-
exports.isSubsetWith = isSubsetWith;
|
|
466
394
|
exports.isSymbol = isSymbol;
|
|
467
|
-
exports.keyBy = keyBy;
|
|
468
395
|
exports.last = last;
|
|
469
396
|
exports.maxBy = maxBy;
|
|
470
397
|
exports.minBy = minBy;
|
|
@@ -476,18 +403,13 @@ exports.shuffle = shuffle;
|
|
|
476
403
|
exports.tail = tail;
|
|
477
404
|
exports.take = take;
|
|
478
405
|
exports.takeRight = takeRight;
|
|
479
|
-
exports.toFilled = toFilled;
|
|
480
406
|
exports.toFinite = toFinite;
|
|
481
407
|
exports.toInteger = toInteger;
|
|
482
408
|
exports.toNumber = toNumber;
|
|
483
|
-
exports.unionBy = unionBy;
|
|
484
|
-
exports.unionWith = unionWith;
|
|
485
409
|
exports.uniq = uniq;
|
|
486
410
|
exports.uniqBy = uniqBy;
|
|
487
411
|
exports.uniqWith = uniqWith;
|
|
488
412
|
exports.unzip = unzip;
|
|
489
413
|
exports.windowed = windowed;
|
|
490
414
|
exports.without = without;
|
|
491
|
-
exports.xorBy = xorBy;
|
|
492
|
-
exports.xorWith = xorWith;
|
|
493
415
|
exports.zip = zip;
|