@web-ts-toolkit/utils 0.42.2 → 0.44.0
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/README.md +138 -7
- package/index.d.mts +398 -8
- package/index.d.ts +398 -8
- package/index.js +352 -82
- package/index.mjs +351 -82
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -85,11 +86,24 @@ function addLeadingSlash(value) {
|
|
|
85
86
|
return value.startsWith("/") ? value : `/${value}`;
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
// src/dictionary.ts
|
|
90
|
+
function defineOwnDataProperty(target, key, value) {
|
|
91
|
+
Object.defineProperty(target, key, {
|
|
92
|
+
value,
|
|
93
|
+
writable: true,
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function hasOwnDataProperty(target, key) {
|
|
99
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
100
|
+
}
|
|
101
|
+
|
|
88
102
|
// src/arrayToRecord.ts
|
|
89
103
|
function arrayToRecord(arr) {
|
|
90
104
|
const obj = {};
|
|
91
105
|
for (let x = 0; x < arr.length; x++) {
|
|
92
|
-
obj
|
|
106
|
+
defineOwnDataProperty(obj, arr[x], true);
|
|
93
107
|
}
|
|
94
108
|
return obj;
|
|
95
109
|
}
|
|
@@ -118,10 +132,16 @@ function isPlainObject(value) {
|
|
|
118
132
|
return prototype === null || prototype === Object.prototype;
|
|
119
133
|
}
|
|
120
134
|
function normalizePathPart(part) {
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
return part;
|
|
136
|
+
}
|
|
137
|
+
function isArrayIndexKey(key) {
|
|
138
|
+
if (typeof key === "number") {
|
|
139
|
+
return Number.isInteger(key) && key >= 0 && key < 4294967295;
|
|
140
|
+
}
|
|
141
|
+
if (!/^(0|[1-9]\d*)$/.test(key)) {
|
|
142
|
+
return false;
|
|
123
143
|
}
|
|
124
|
-
return
|
|
144
|
+
return Number(key) < 4294967295;
|
|
125
145
|
}
|
|
126
146
|
function toPath(path) {
|
|
127
147
|
if (Array.isArray(path)) {
|
|
@@ -139,6 +159,17 @@ function toPath(path) {
|
|
|
139
159
|
});
|
|
140
160
|
return result.length > 0 ? result : [input];
|
|
141
161
|
}
|
|
162
|
+
function hasOwnKey(target, key) {
|
|
163
|
+
return Object.prototype.hasOwnProperty.call(target, key);
|
|
164
|
+
}
|
|
165
|
+
function defineOwnValue(target, key, value) {
|
|
166
|
+
Object.defineProperty(target, key, {
|
|
167
|
+
value,
|
|
168
|
+
writable: true,
|
|
169
|
+
enumerable: true,
|
|
170
|
+
configurable: true
|
|
171
|
+
});
|
|
172
|
+
}
|
|
142
173
|
function hasUnsafePathPart(parts) {
|
|
143
174
|
for (let index = 0; index < parts.length; index++) {
|
|
144
175
|
const part = parts[index];
|
|
@@ -189,13 +220,16 @@ function setPath(target, path, value) {
|
|
|
189
220
|
for (let index = 0; index < parts.length - 1; index++) {
|
|
190
221
|
const key = parts[index];
|
|
191
222
|
const nextKey = parts[index + 1];
|
|
192
|
-
const existing = current[key];
|
|
223
|
+
const existing = hasOwnKey(current, key) ? current[key] : void 0;
|
|
193
224
|
if (!isObject(existing)) {
|
|
194
|
-
|
|
225
|
+
const container = isArrayIndexKey(nextKey) ? [] : {};
|
|
226
|
+
defineOwnValue(current, key, container);
|
|
227
|
+
current = container;
|
|
228
|
+
} else {
|
|
229
|
+
current = existing;
|
|
195
230
|
}
|
|
196
|
-
current = current[key];
|
|
197
231
|
}
|
|
198
|
-
current
|
|
232
|
+
defineOwnValue(current, parts[parts.length - 1], value);
|
|
199
233
|
return target;
|
|
200
234
|
}
|
|
201
235
|
function deletePath(target, path) {
|
|
@@ -209,6 +243,9 @@ function deletePath(target, path) {
|
|
|
209
243
|
let current = target;
|
|
210
244
|
for (let index = 0; index < parts.length - 1; index++) {
|
|
211
245
|
const key = parts[index];
|
|
246
|
+
if (!hasOwnKey(current, key)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
212
249
|
const nextValue = current[key];
|
|
213
250
|
if (!isObject(nextValue)) {
|
|
214
251
|
return;
|
|
@@ -220,19 +257,14 @@ function deletePath(target, path) {
|
|
|
220
257
|
function sameValueZero(left, right) {
|
|
221
258
|
return left === right || left !== left && right !== right;
|
|
222
259
|
}
|
|
223
|
-
function arrayIncludes(array, value) {
|
|
224
|
-
for (let index = 0; index < array.length; index++) {
|
|
225
|
-
if (sameValueZero(array[index], value)) {
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
260
|
function baseUniq(array) {
|
|
261
|
+
const seen = /* @__PURE__ */ new Set();
|
|
232
262
|
const result = [];
|
|
233
263
|
for (let index = 0; index < array.length; index++) {
|
|
234
|
-
|
|
235
|
-
|
|
264
|
+
const value = array[index];
|
|
265
|
+
if (!seen.has(value)) {
|
|
266
|
+
seen.add(value);
|
|
267
|
+
result.push(value);
|
|
236
268
|
}
|
|
237
269
|
}
|
|
238
270
|
return result;
|
|
@@ -287,14 +319,29 @@ function compareAscending(left, right) {
|
|
|
287
319
|
return leftString > rightString ? 1 : -1;
|
|
288
320
|
}
|
|
289
321
|
function cloneValue(value) {
|
|
290
|
-
if (
|
|
291
|
-
|
|
292
|
-
return structuredClone(value);
|
|
293
|
-
} catch {
|
|
294
|
-
}
|
|
322
|
+
if (isExoticRoot(value)) {
|
|
323
|
+
throw exoticTypeError(value);
|
|
295
324
|
}
|
|
296
|
-
|
|
297
|
-
|
|
325
|
+
return cloneInner(value, /* @__PURE__ */ new Map());
|
|
326
|
+
}
|
|
327
|
+
function isExoticRoot(value) {
|
|
328
|
+
if (value === null || typeof value !== "object") {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (value instanceof Date || value instanceof RegExp || Array.isArray(value)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
return !isPlainObject(value) && !isInheritedPlainLike(value);
|
|
335
|
+
}
|
|
336
|
+
function exoticTypeError(value) {
|
|
337
|
+
const name = typeof value.constructor?.name === "string" && value.constructor.name.length > 0 ? value.constructor.name : typeof value;
|
|
338
|
+
return new TypeError(
|
|
339
|
+
`cloneDeep: unsupported value of type ${name}; only plain objects, arrays, Date, and RegExp can be cloned`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
function cloneInner(value, seen) {
|
|
343
|
+
if (value === null || typeof value !== "object") {
|
|
344
|
+
return value;
|
|
298
345
|
}
|
|
299
346
|
if (value instanceof Date) {
|
|
300
347
|
return new Date(value.getTime());
|
|
@@ -302,55 +349,205 @@ function cloneValue(value) {
|
|
|
302
349
|
if (value instanceof RegExp) {
|
|
303
350
|
return new RegExp(value.source, value.flags);
|
|
304
351
|
}
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
352
|
+
if (Array.isArray(value)) {
|
|
353
|
+
if (seen.has(value)) {
|
|
354
|
+
return seen.get(value);
|
|
355
|
+
}
|
|
356
|
+
const result = [];
|
|
357
|
+
seen.set(value, result);
|
|
358
|
+
for (let index = 0; index < value.length; index++) {
|
|
359
|
+
if (hasOwnKey(value, index)) {
|
|
360
|
+
defineOwnValue(result, index, cloneInner(value[index], seen));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
copyOwnEnumerableExtras(value, result, seen);
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
if (isPlainObject(value) || isInheritedPlainLike(value)) {
|
|
367
|
+
if (seen.has(value)) {
|
|
368
|
+
return seen.get(value);
|
|
369
|
+
}
|
|
370
|
+
const source = value;
|
|
371
|
+
const prototype = Object.getPrototypeOf(source);
|
|
372
|
+
const result = Object.create(prototype);
|
|
373
|
+
seen.set(source, result);
|
|
374
|
+
const keys2 = ownEnumerableKeys(source);
|
|
308
375
|
for (let index = 0; index < keys2.length; index++) {
|
|
309
376
|
const key = keys2[index];
|
|
310
|
-
|
|
377
|
+
const child = source[key];
|
|
378
|
+
defineOwnValue(result, key, cloneInner(child, seen));
|
|
311
379
|
}
|
|
312
380
|
return result;
|
|
313
381
|
}
|
|
314
382
|
return value;
|
|
315
383
|
}
|
|
384
|
+
function isInheritedPlainLike(value) {
|
|
385
|
+
let current = value;
|
|
386
|
+
while (current !== null) {
|
|
387
|
+
const prototype = Object.getPrototypeOf(current);
|
|
388
|
+
if (prototype === null || prototype === Object.prototype) {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
const constructor = prototype.constructor;
|
|
392
|
+
if (constructor !== void 0 && constructor !== Object) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
current = prototype;
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
function ownEnumerableKeys(source) {
|
|
400
|
+
const keys2 = Object.keys(source);
|
|
401
|
+
const symbols = Object.getOwnPropertySymbols(source);
|
|
402
|
+
for (let index = 0; index < symbols.length; index++) {
|
|
403
|
+
if (Object.prototype.propertyIsEnumerable.call(source, symbols[index])) {
|
|
404
|
+
keys2.push(symbols[index]);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return keys2;
|
|
408
|
+
}
|
|
409
|
+
function copyOwnEnumerableExtras(source, target, seen) {
|
|
410
|
+
const keys2 = ownEnumerableKeys(source);
|
|
411
|
+
for (let index = 0; index < keys2.length; index++) {
|
|
412
|
+
const key = keys2[index];
|
|
413
|
+
if (typeof key === "string" && /^(0|[1-9]\d*)$/.test(key)) {
|
|
414
|
+
const numeric = Number(key);
|
|
415
|
+
if (Number.isInteger(numeric) && numeric >= 0 && numeric < source.length) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (hasOwnKey(target, key)) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
defineOwnValue(target, key, cloneInner(source[key], seen));
|
|
423
|
+
}
|
|
424
|
+
}
|
|
316
425
|
function deepEqual(left, right) {
|
|
426
|
+
return deepEqualInner(left, right, /* @__PURE__ */ new Map());
|
|
427
|
+
}
|
|
428
|
+
function pairsHas(pairs, left, right) {
|
|
429
|
+
return pairs.get(left)?.has(right) ?? false;
|
|
430
|
+
}
|
|
431
|
+
function pairsAdd(pairs, left, right) {
|
|
432
|
+
let set2 = pairs.get(left);
|
|
433
|
+
if (set2 === void 0) {
|
|
434
|
+
set2 = /* @__PURE__ */ new Set();
|
|
435
|
+
pairs.set(left, set2);
|
|
436
|
+
}
|
|
437
|
+
set2.add(right);
|
|
438
|
+
}
|
|
439
|
+
function pairsDelete(pairs, left, right) {
|
|
440
|
+
const set2 = pairs.get(left);
|
|
441
|
+
if (set2 === void 0) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
set2.delete(right);
|
|
445
|
+
if (set2.size === 0) {
|
|
446
|
+
pairs.delete(left);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function isComparableObject(value) {
|
|
450
|
+
return typeof value === "object" && value !== null && (isPlainObject(value) || isInheritedPlainLike(value));
|
|
451
|
+
}
|
|
452
|
+
function isExtraArrayKey(key, length) {
|
|
453
|
+
if (typeof key === "symbol") {
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
if (/^(0|[1-9]\d*)$/.test(key)) {
|
|
457
|
+
const numeric = Number(key);
|
|
458
|
+
if (Number.isInteger(numeric) && numeric >= 0 && numeric < length) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return true;
|
|
463
|
+
}
|
|
464
|
+
function deepEqualInner(left, right, pairs) {
|
|
317
465
|
if (sameValueZero(left, right)) {
|
|
318
466
|
return true;
|
|
319
467
|
}
|
|
320
|
-
if (left instanceof Date
|
|
321
|
-
return left.getTime()
|
|
468
|
+
if (left instanceof Date || right instanceof Date) {
|
|
469
|
+
return left instanceof Date && right instanceof Date && sameValueZero(left.getTime(), right.getTime());
|
|
322
470
|
}
|
|
323
|
-
if (left instanceof RegExp
|
|
324
|
-
return left.source === right.source && left.flags === right.flags;
|
|
471
|
+
if (left instanceof RegExp || right instanceof RegExp) {
|
|
472
|
+
return left instanceof RegExp && right instanceof RegExp && left.source === right.source && left.flags === right.flags;
|
|
325
473
|
}
|
|
326
474
|
if (Array.isArray(left) || Array.isArray(right)) {
|
|
327
475
|
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) {
|
|
328
476
|
return false;
|
|
329
477
|
}
|
|
330
|
-
|
|
331
|
-
|
|
478
|
+
if (pairsHas(pairs, left, right)) {
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
pairsAdd(pairs, left, right);
|
|
482
|
+
try {
|
|
483
|
+
for (let index = 0; index < left.length; index++) {
|
|
484
|
+
const leftHas = hasOwnKey(left, index);
|
|
485
|
+
const rightHas = hasOwnKey(right, index);
|
|
486
|
+
if (leftHas !== rightHas) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
if (leftHas && !deepEqualInner(left[index], right[index], pairs)) {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const leftExtras = ownEnumerableKeys(left).filter((key) => isExtraArrayKey(key, left.length));
|
|
494
|
+
const rightExtras = ownEnumerableKeys(right).filter((key) => isExtraArrayKey(key, right.length));
|
|
495
|
+
if (leftExtras.length !== rightExtras.length) {
|
|
332
496
|
return false;
|
|
333
497
|
}
|
|
498
|
+
for (let index = 0; index < leftExtras.length; index++) {
|
|
499
|
+
const key = leftExtras[index];
|
|
500
|
+
if (!hasOwnKey(right, key)) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
if (!deepEqualInner(
|
|
504
|
+
left[key],
|
|
505
|
+
right[key],
|
|
506
|
+
pairs
|
|
507
|
+
)) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return true;
|
|
512
|
+
} finally {
|
|
513
|
+
pairsDelete(pairs, left, right);
|
|
334
514
|
}
|
|
335
|
-
return true;
|
|
336
515
|
}
|
|
337
|
-
if (!
|
|
516
|
+
if (!isComparableObject(left) || !isComparableObject(right)) {
|
|
338
517
|
return false;
|
|
339
518
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
343
|
-
return false;
|
|
519
|
+
if (pairsHas(pairs, left, right)) {
|
|
520
|
+
return true;
|
|
344
521
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
522
|
+
pairsAdd(pairs, left, right);
|
|
523
|
+
try {
|
|
524
|
+
const leftKeys = ownEnumerableKeys(left);
|
|
525
|
+
const rightKeys = ownEnumerableKeys(right);
|
|
526
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
348
527
|
return false;
|
|
349
528
|
}
|
|
529
|
+
for (let index = 0; index < leftKeys.length; index++) {
|
|
530
|
+
const key = leftKeys[index];
|
|
531
|
+
if (!hasOwnKey(right, key)) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (!deepEqualInner(
|
|
535
|
+
left[key],
|
|
536
|
+
right[key],
|
|
537
|
+
pairs
|
|
538
|
+
)) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return true;
|
|
543
|
+
} finally {
|
|
544
|
+
pairsDelete(pairs, left, right);
|
|
350
545
|
}
|
|
351
|
-
return true;
|
|
352
546
|
}
|
|
353
547
|
function partialMatch(object, source) {
|
|
548
|
+
return partialMatchInner(object, source, /* @__PURE__ */ new Map());
|
|
549
|
+
}
|
|
550
|
+
function partialMatchInner(object, source, pairs) {
|
|
354
551
|
if (sameValueZero(object, source)) {
|
|
355
552
|
return true;
|
|
356
553
|
}
|
|
@@ -358,27 +555,70 @@ function partialMatch(object, source) {
|
|
|
358
555
|
if (!Array.isArray(object) || object.length < source.length) {
|
|
359
556
|
return false;
|
|
360
557
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
558
|
+
if (pairsHas(pairs, source, object)) {
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
pairsAdd(pairs, source, object);
|
|
562
|
+
try {
|
|
563
|
+
for (let index = 0; index < source.length; index++) {
|
|
564
|
+
if (!hasOwnKey(source, index)) {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
if (!hasOwnKey(object, index)) {
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
if (!partialMatchInner(object[index], source[index], pairs)) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const sourceExtras = ownEnumerableKeys(source).filter((key) => isExtraArrayKey(key, source.length));
|
|
575
|
+
for (let index = 0; index < sourceExtras.length; index++) {
|
|
576
|
+
const key = sourceExtras[index];
|
|
577
|
+
if (!hasOwnKey(object, key)) {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
if (!partialMatchInner(
|
|
581
|
+
object[key],
|
|
582
|
+
source[key],
|
|
583
|
+
pairs
|
|
584
|
+
)) {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
364
587
|
}
|
|
588
|
+
return true;
|
|
589
|
+
} finally {
|
|
590
|
+
pairsDelete(pairs, source, object);
|
|
365
591
|
}
|
|
366
|
-
return true;
|
|
367
592
|
}
|
|
368
|
-
if (isPlainObject(source)) {
|
|
593
|
+
if (isPlainObject(source) || typeof source === "object" && source !== null && isInheritedPlainLike(source)) {
|
|
369
594
|
if (!isObject(object)) {
|
|
370
595
|
return false;
|
|
371
596
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
597
|
+
if (pairsHas(pairs, source, object)) {
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
pairsAdd(pairs, source, object);
|
|
601
|
+
try {
|
|
602
|
+
const keys2 = ownEnumerableKeys(source);
|
|
603
|
+
for (let index = 0; index < keys2.length; index++) {
|
|
604
|
+
const key = keys2[index];
|
|
605
|
+
if (!hasOwnKey(object, key)) {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
if (!partialMatchInner(
|
|
609
|
+
object[key],
|
|
610
|
+
source[key],
|
|
611
|
+
pairs
|
|
612
|
+
)) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
377
615
|
}
|
|
616
|
+
return true;
|
|
617
|
+
} finally {
|
|
618
|
+
pairsDelete(pairs, source, object);
|
|
378
619
|
}
|
|
379
|
-
return true;
|
|
380
620
|
}
|
|
381
|
-
return
|
|
621
|
+
return deepEqualInner(object, source, pairs);
|
|
382
622
|
}
|
|
383
623
|
|
|
384
624
|
// src/cloneDeep.ts
|
|
@@ -400,7 +640,8 @@ function difference(array, ...values) {
|
|
|
400
640
|
return [];
|
|
401
641
|
}
|
|
402
642
|
const excluded = values.flatMap((value) => Array.isArray(value) ? value : []);
|
|
403
|
-
|
|
643
|
+
const excludedSet = new Set(excluded);
|
|
644
|
+
return array.filter((item) => !excludedSet.has(item));
|
|
404
645
|
}
|
|
405
646
|
|
|
406
647
|
// src/eachRight.ts
|
|
@@ -501,10 +742,23 @@ function flattenDeep(array) {
|
|
|
501
742
|
return [];
|
|
502
743
|
}
|
|
503
744
|
const result = [];
|
|
504
|
-
|
|
505
|
-
|
|
745
|
+
const stack = [{ values: array, index: 0 }];
|
|
746
|
+
const ancestors = /* @__PURE__ */ new Set([array]);
|
|
747
|
+
while (stack.length > 0) {
|
|
748
|
+
const frame = stack[stack.length - 1];
|
|
749
|
+
if (frame.index >= frame.values.length) {
|
|
750
|
+
stack.pop();
|
|
751
|
+
ancestors.delete(frame.values);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const value = frame.values[frame.index];
|
|
755
|
+
frame.index += 1;
|
|
506
756
|
if (Array.isArray(value)) {
|
|
507
|
-
|
|
757
|
+
if (ancestors.has(value)) {
|
|
758
|
+
throw new TypeError("flattenDeep: cyclic array reference is not supported");
|
|
759
|
+
}
|
|
760
|
+
ancestors.add(value);
|
|
761
|
+
stack.push({ values: value, index: 0 });
|
|
508
762
|
} else {
|
|
509
763
|
result.push(value);
|
|
510
764
|
}
|
|
@@ -552,7 +806,12 @@ function groupBy(collection, iteratee) {
|
|
|
552
806
|
for (let index = 0; index < collection.length; index++) {
|
|
553
807
|
const value = collection[index];
|
|
554
808
|
const key = String(callback(value, index, collection));
|
|
555
|
-
(result[key]
|
|
809
|
+
let bucket = hasOwnDataProperty(result, key) ? result[key] : void 0;
|
|
810
|
+
if (bucket === void 0) {
|
|
811
|
+
bucket = [];
|
|
812
|
+
defineOwnDataProperty(result, key, bucket);
|
|
813
|
+
}
|
|
814
|
+
bucket.push(value);
|
|
556
815
|
}
|
|
557
816
|
return result;
|
|
558
817
|
}
|
|
@@ -561,7 +820,12 @@ function groupBy(collection, iteratee) {
|
|
|
561
820
|
const key = keys2[index];
|
|
562
821
|
const value = collection[key];
|
|
563
822
|
const group = String(callback(value, key, collection));
|
|
564
|
-
(result[group]
|
|
823
|
+
let bucket = hasOwnDataProperty(result, group) ? result[group] : void 0;
|
|
824
|
+
if (bucket === void 0) {
|
|
825
|
+
bucket = [];
|
|
826
|
+
defineOwnDataProperty(result, group, bucket);
|
|
827
|
+
}
|
|
828
|
+
bucket.push(value);
|
|
565
829
|
}
|
|
566
830
|
return result;
|
|
567
831
|
}
|
|
@@ -581,7 +845,8 @@ function intersection(...arrays) {
|
|
|
581
845
|
return [];
|
|
582
846
|
}
|
|
583
847
|
const uniqueValues = baseUniq(first);
|
|
584
|
-
|
|
848
|
+
const restSets = rest.map((array) => Array.isArray(array) ? new Set(array) : null);
|
|
849
|
+
return uniqueValues.filter((value) => restSets.every((set2) => set2 !== null && set2.has(value)));
|
|
585
850
|
}
|
|
586
851
|
|
|
587
852
|
// src/intersectionBy.ts
|
|
@@ -596,17 +861,16 @@ function intersectionBy(...args) {
|
|
|
596
861
|
}
|
|
597
862
|
const [first, ...rest] = sources;
|
|
598
863
|
const result = [];
|
|
599
|
-
const seen =
|
|
864
|
+
const seen = /* @__PURE__ */ new Set();
|
|
865
|
+
const restSets = rest.map((array) => new Set(array.map((value) => callback(value))));
|
|
600
866
|
for (let index = 0; index < first.length; index++) {
|
|
601
867
|
const item = first[index];
|
|
602
868
|
const computed = callback(item);
|
|
603
|
-
if (seen.
|
|
869
|
+
if (seen.has(computed)) {
|
|
604
870
|
continue;
|
|
605
871
|
}
|
|
606
|
-
if (
|
|
607
|
-
|
|
608
|
-
)) {
|
|
609
|
-
seen.push(computed);
|
|
872
|
+
if (restSets.every((set2) => set2.has(computed))) {
|
|
873
|
+
seen.add(computed);
|
|
610
874
|
result.push(item);
|
|
611
875
|
}
|
|
612
876
|
}
|
|
@@ -620,7 +884,7 @@ function isArray(value) {
|
|
|
620
884
|
|
|
621
885
|
// src/isBoolean.ts
|
|
622
886
|
function isBoolean(value) {
|
|
623
|
-
return
|
|
887
|
+
return typeof value === "boolean";
|
|
624
888
|
}
|
|
625
889
|
|
|
626
890
|
// src/isEmpty.ts
|
|
@@ -670,7 +934,7 @@ function isNil(value) {
|
|
|
670
934
|
|
|
671
935
|
// src/isNumber.ts
|
|
672
936
|
function isNumber(value) {
|
|
673
|
-
return typeof value === "number"
|
|
937
|
+
return typeof value === "number";
|
|
674
938
|
}
|
|
675
939
|
|
|
676
940
|
// src/isObject.ts
|
|
@@ -690,7 +954,7 @@ function isPromise(value) {
|
|
|
690
954
|
|
|
691
955
|
// src/isString.ts
|
|
692
956
|
function isString(value) {
|
|
693
|
-
return typeof value === "string"
|
|
957
|
+
return typeof value === "string";
|
|
694
958
|
}
|
|
695
959
|
|
|
696
960
|
// src/isUndefined.ts
|
|
@@ -744,7 +1008,8 @@ function mapKeys(object, iteratee) {
|
|
|
744
1008
|
const keys2 = Object.keys(object);
|
|
745
1009
|
for (let index = 0; index < keys2.length; index++) {
|
|
746
1010
|
const key = keys2[index];
|
|
747
|
-
|
|
1011
|
+
const mappedKey = String(iteratee(object[key], key, object));
|
|
1012
|
+
defineOwnDataProperty(result, mappedKey, object[key]);
|
|
748
1013
|
}
|
|
749
1014
|
return result;
|
|
750
1015
|
}
|
|
@@ -758,7 +1023,7 @@ function mapValues(object, iteratee) {
|
|
|
758
1023
|
const keys2 = Object.keys(object);
|
|
759
1024
|
for (let index = 0; index < keys2.length; index++) {
|
|
760
1025
|
const key = keys2[index];
|
|
761
|
-
result
|
|
1026
|
+
defineOwnDataProperty(result, key, iteratee(object[key], key, object));
|
|
762
1027
|
}
|
|
763
1028
|
return result;
|
|
764
1029
|
}
|
|
@@ -782,6 +1047,9 @@ function omit(object, paths) {
|
|
|
782
1047
|
return {};
|
|
783
1048
|
}
|
|
784
1049
|
const result = cloneDeep(object);
|
|
1050
|
+
if (result === object) {
|
|
1051
|
+
throw new TypeError("omit: unsupported object type; input cannot be cloned without aliasing");
|
|
1052
|
+
}
|
|
785
1053
|
const pathList = Array.isArray(paths) ? paths : [paths];
|
|
786
1054
|
for (let index = 0; index < pathList.length; index++) {
|
|
787
1055
|
deletePath(result, pathList[index]);
|
|
@@ -800,7 +1068,7 @@ function omitBy(object, predicate) {
|
|
|
800
1068
|
const key = keys2[index];
|
|
801
1069
|
const value = object[key];
|
|
802
1070
|
if (!predicate(value, key, object)) {
|
|
803
|
-
result
|
|
1071
|
+
defineOwnDataProperty(result, key, value);
|
|
804
1072
|
}
|
|
805
1073
|
}
|
|
806
1074
|
return result;
|
|
@@ -816,7 +1084,9 @@ function orderBy(collection, iteratees = [], orders = []) {
|
|
|
816
1084
|
if (!Array.isArray(collection)) {
|
|
817
1085
|
return [];
|
|
818
1086
|
}
|
|
819
|
-
const callbacks = (iteratees.length > 0 ? iteratees : [void 0]).map(
|
|
1087
|
+
const callbacks = (iteratees.length > 0 ? iteratees : [void 0]).map(
|
|
1088
|
+
(iteratee) => getIteratee(iteratee)
|
|
1089
|
+
);
|
|
820
1090
|
return [...collection].map((value, index) => ({ value, index })).sort((left, right) => {
|
|
821
1091
|
for (let index = 0; index < callbacks.length; index++) {
|
|
822
1092
|
const callback = callbacks[index];
|
|
@@ -862,7 +1132,7 @@ function pickBy(object, predicate) {
|
|
|
862
1132
|
const key = keys2[index];
|
|
863
1133
|
const value = object[key];
|
|
864
1134
|
if (predicate(value, key, object)) {
|
|
865
|
-
result
|
|
1135
|
+
defineOwnDataProperty(result, key, value);
|
|
866
1136
|
}
|
|
867
1137
|
}
|
|
868
1138
|
return result;
|
|
@@ -968,7 +1238,7 @@ function toStringRecord(value) {
|
|
|
968
1238
|
const entries = Object.entries(value);
|
|
969
1239
|
for (let index = 0; index < entries.length; index++) {
|
|
970
1240
|
const [key, entryValue] = entries[index];
|
|
971
|
-
result
|
|
1241
|
+
defineOwnDataProperty(result, key, String(entryValue));
|
|
972
1242
|
}
|
|
973
1243
|
return entries.length > 0 ? result : void 0;
|
|
974
1244
|
}
|
|
@@ -988,14 +1258,14 @@ function uniqBy(array, iteratee) {
|
|
|
988
1258
|
}
|
|
989
1259
|
const callback = getIteratee(iteratee);
|
|
990
1260
|
const result = [];
|
|
991
|
-
const seen =
|
|
1261
|
+
const seen = /* @__PURE__ */ new Set();
|
|
992
1262
|
for (let index = 0; index < array.length; index++) {
|
|
993
1263
|
const value = array[index];
|
|
994
1264
|
const computed = callback(value, index, array);
|
|
995
|
-
if (seen.
|
|
1265
|
+
if (seen.has(computed)) {
|
|
996
1266
|
continue;
|
|
997
1267
|
}
|
|
998
|
-
seen.
|
|
1268
|
+
seen.add(computed);
|
|
999
1269
|
result.push(value);
|
|
1000
1270
|
}
|
|
1001
1271
|
return result;
|