@stemy/ngx-utils 12.2.2 → 12.2.3
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/bundles/stemy-ngx-utils.umd.js +36 -24
- package/bundles/stemy-ngx-utils.umd.js.map +1 -1
- package/esm2015/ngx-utils/utils/object.utils.js +36 -25
- package/fesm2015/stemy-ngx-utils.js +35 -24
- package/fesm2015/stemy-ngx-utils.js.map +1 -1
- package/ngx-utils/utils/object.utils.d.ts +1 -1
- package/package.json +1 -1
- package/stemy-ngx-utils.metadata.json +1 -1
|
@@ -349,7 +349,11 @@
|
|
|
349
349
|
Object.getOwnPropertyNames(obj).forEach(function (p) { return props.add(p); });
|
|
350
350
|
return Array.from(props);
|
|
351
351
|
};
|
|
352
|
-
ObjectUtils.equals = function (a, b) {
|
|
352
|
+
ObjectUtils.equals = function (a, b, visited) {
|
|
353
|
+
if (visited === void 0) { visited = null; }
|
|
354
|
+
visited = visited || new Set();
|
|
355
|
+
if (visited.has(a) && visited.has(b))
|
|
356
|
+
return true;
|
|
353
357
|
if (a === b)
|
|
354
358
|
return true;
|
|
355
359
|
if (a === null || b === null)
|
|
@@ -359,12 +363,14 @@
|
|
|
359
363
|
var at = typeof a, bt = typeof b;
|
|
360
364
|
var length, key, keySet;
|
|
361
365
|
if (at == bt && at == "object") {
|
|
366
|
+
visited.add(a);
|
|
367
|
+
visited.add(b);
|
|
362
368
|
if (Array.isArray(a)) {
|
|
363
369
|
if (!Array.isArray(b))
|
|
364
370
|
return false;
|
|
365
371
|
if ((length = a.length) == b.length) {
|
|
366
372
|
for (key = 0; key < length; key++) {
|
|
367
|
-
if (!ObjectUtils.equals(a[key], b[key]))
|
|
373
|
+
if (!ObjectUtils.equals(a[key], b[key], visited))
|
|
368
374
|
return false;
|
|
369
375
|
}
|
|
370
376
|
return true;
|
|
@@ -377,7 +383,7 @@
|
|
|
377
383
|
keySet = Object.create(null);
|
|
378
384
|
for (key in a) {
|
|
379
385
|
if (a.hasOwnProperty(key)) {
|
|
380
|
-
if (!ObjectUtils.equals(a[key], b[key])) {
|
|
386
|
+
if (!ObjectUtils.equals(a[key], b[key], visited)) {
|
|
381
387
|
return false;
|
|
382
388
|
}
|
|
383
389
|
keySet[key] = true;
|
|
@@ -474,13 +480,13 @@
|
|
|
474
480
|
return isNaN(key) || isArray ? target : Object.values(target);
|
|
475
481
|
};
|
|
476
482
|
ObjectUtils.filter = function (obj, predicate) {
|
|
477
|
-
return ObjectUtils.copyRecursive(null, obj, predicate);
|
|
483
|
+
return ObjectUtils.copyRecursive(null, obj, predicate, new Map());
|
|
478
484
|
};
|
|
479
485
|
ObjectUtils.copy = function (obj) {
|
|
480
|
-
return ObjectUtils.copyRecursive(null, obj);
|
|
486
|
+
return ObjectUtils.copyRecursive(null, obj, null, new Map());
|
|
481
487
|
};
|
|
482
488
|
ObjectUtils.assign = function (target, source, predicate) {
|
|
483
|
-
return ObjectUtils.copyRecursive(target, source, predicate);
|
|
489
|
+
return ObjectUtils.copyRecursive(target, source, predicate, new Map());
|
|
484
490
|
};
|
|
485
491
|
ObjectUtils.getType = function (obj) {
|
|
486
492
|
var regex = new RegExp("\\s([a-zA-Z]+)");
|
|
@@ -567,28 +573,34 @@
|
|
|
567
573
|
var str = ObjectUtils.isDefined(obj) ? obj.toString() : "";
|
|
568
574
|
return str.length >= width ? str : new Array(width - str.length + 1).join(chr) + str;
|
|
569
575
|
};
|
|
570
|
-
ObjectUtils.copyRecursive = function (target, source, predicate) {
|
|
576
|
+
ObjectUtils.copyRecursive = function (target, source, predicate, copies) {
|
|
571
577
|
predicate = predicate || defaultPredicate;
|
|
572
578
|
if (ObjectUtils.isPrimitive(source) || ObjectUtils.isDate(source) || ObjectUtils.isBlob(source) || ObjectUtils.isFunction(source))
|
|
573
579
|
return source;
|
|
574
|
-
if (
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
580
|
+
if (!copies.has(source)) {
|
|
581
|
+
if (ObjectUtils.isArray(source)) {
|
|
582
|
+
target = ObjectUtils.isArray(target) ? Array.from(target) : [];
|
|
583
|
+
copies.set(source, target);
|
|
584
|
+
source.forEach(function (item, index) {
|
|
585
|
+
if (!predicate(item, index, target, source))
|
|
586
|
+
return;
|
|
587
|
+
if (target.length > index)
|
|
588
|
+
target[index] = ObjectUtils.copyRecursive(target[index], item, predicate, copies);
|
|
589
|
+
else
|
|
590
|
+
target.push(ObjectUtils.copyRecursive(null, item, predicate, copies));
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
target = Object.assign({}, target);
|
|
595
|
+
copies.set(source, target);
|
|
596
|
+
Object.keys(source).forEach(function (key) {
|
|
597
|
+
if (!predicate(source[key], key, target, source))
|
|
598
|
+
return;
|
|
599
|
+
target[key] = ObjectUtils.copyRecursive(target[key], source[key], predicate, copies);
|
|
600
|
+
});
|
|
601
|
+
}
|
|
585
602
|
}
|
|
586
|
-
return
|
|
587
|
-
if (!predicate(source[key], key, result, source))
|
|
588
|
-
return result;
|
|
589
|
-
result[key] = ObjectUtils.copyRecursive(result[key], source[key], predicate);
|
|
590
|
-
return result;
|
|
591
|
-
}, Object.assign({}, target));
|
|
603
|
+
return copies.get(source);
|
|
592
604
|
};
|
|
593
605
|
return ObjectUtils;
|
|
594
606
|
}());
|