@domql/utils 2.5.143 → 2.5.147
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/array.js +12 -0
- package/dist/cjs/array.js +9 -0
- package/dist/cjs/object.js +49 -13
- package/object.js +51 -15
- package/package.json +2 -2
package/array.js
CHANGED
|
@@ -110,6 +110,7 @@ export const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
|
|
|
110
110
|
}
|
|
111
111
|
return newArray
|
|
112
112
|
}
|
|
113
|
+
|
|
113
114
|
export const arraysEqual = (arr1, arr2) => {
|
|
114
115
|
if (arr1.length !== arr2.length) {
|
|
115
116
|
return false
|
|
@@ -123,3 +124,14 @@ export const arraysEqual = (arr1, arr2) => {
|
|
|
123
124
|
|
|
124
125
|
return true
|
|
125
126
|
}
|
|
127
|
+
|
|
128
|
+
// Using filter and includes
|
|
129
|
+
export const filterArrays = (sourceArr, excludeArr) => {
|
|
130
|
+
return sourceArr.filter(item => !excludeArr.includes(item))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Using Set for better performance with large arrays
|
|
134
|
+
export const filterArraysFast = (sourceArr, excludeArr) => {
|
|
135
|
+
const excludeSet = new Set(excludeArr)
|
|
136
|
+
return sourceArr.filter(item => !excludeSet.has(item))
|
|
137
|
+
}
|
package/dist/cjs/array.js
CHANGED
|
@@ -23,6 +23,8 @@ __export(array_exports, {
|
|
|
23
23
|
arraysEqual: () => arraysEqual,
|
|
24
24
|
cutArrayAfterValue: () => cutArrayAfterValue,
|
|
25
25
|
cutArrayBeforeValue: () => cutArrayBeforeValue,
|
|
26
|
+
filterArrays: () => filterArrays,
|
|
27
|
+
filterArraysFast: () => filterArraysFast,
|
|
26
28
|
getFrequencyInArray: () => getFrequencyInArray,
|
|
27
29
|
joinArrays: () => joinArrays,
|
|
28
30
|
mergeAndCloneIfArray: () => mergeAndCloneIfArray,
|
|
@@ -131,3 +133,10 @@ const arraysEqual = (arr1, arr2) => {
|
|
|
131
133
|
}
|
|
132
134
|
return true;
|
|
133
135
|
};
|
|
136
|
+
const filterArrays = (sourceArr, excludeArr) => {
|
|
137
|
+
return sourceArr.filter((item) => !excludeArr.includes(item));
|
|
138
|
+
};
|
|
139
|
+
const filterArraysFast = (sourceArr, excludeArr) => {
|
|
140
|
+
const excludeSet = new Set(excludeArr);
|
|
141
|
+
return sourceArr.filter((item) => !excludeSet.has(item));
|
|
142
|
+
};
|
package/dist/cjs/object.js
CHANGED
|
@@ -35,9 +35,11 @@ __export(object_exports, {
|
|
|
35
35
|
diff: () => diff,
|
|
36
36
|
diffArrays: () => diffArrays,
|
|
37
37
|
diffObjects: () => diffObjects,
|
|
38
|
+
excludeKeysFromObject: () => excludeKeysFromObject,
|
|
38
39
|
exec: () => exec,
|
|
39
40
|
flattenRecursive: () => flattenRecursive,
|
|
40
41
|
hasOwnProperty: () => hasOwnProperty,
|
|
42
|
+
isCyclic: () => isCyclic,
|
|
41
43
|
isEmpty: () => isEmpty,
|
|
42
44
|
isEmptyObject: () => isEmptyObject,
|
|
43
45
|
isEqualDeep: () => isEqualDeep,
|
|
@@ -441,20 +443,27 @@ const deepDiff = (lhs, rhs) => {
|
|
|
441
443
|
return acc;
|
|
442
444
|
}, deletedValues);
|
|
443
445
|
};
|
|
444
|
-
const overwrite = (element, params,
|
|
445
|
-
const { ref } = element;
|
|
446
|
-
const
|
|
446
|
+
const overwrite = (element, params, opts = {}) => {
|
|
447
|
+
const { __ref: ref } = element;
|
|
448
|
+
const excl = opts.exclude || [];
|
|
449
|
+
const allowUnderscore = opts.preventUnderscore;
|
|
450
|
+
const preventCaching = opts.preventCaching;
|
|
447
451
|
for (const e in params) {
|
|
448
|
-
if (
|
|
452
|
+
if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
|
|
449
453
|
continue;
|
|
450
454
|
const elementProp = element[e];
|
|
451
455
|
const paramsProp = params[e];
|
|
452
|
-
if (paramsProp) {
|
|
453
|
-
|
|
454
|
-
ref
|
|
456
|
+
if (paramsProp !== void 0) {
|
|
457
|
+
element[e] = paramsProp;
|
|
458
|
+
if (ref && !preventCaching) {
|
|
459
|
+
ref.__cache[e] = elementProp;
|
|
460
|
+
}
|
|
461
|
+
if ((0, import_types.isObject)(opts.diff)) {
|
|
462
|
+
diff[e] = elementProp;
|
|
463
|
+
}
|
|
455
464
|
}
|
|
456
465
|
}
|
|
457
|
-
return
|
|
466
|
+
return element;
|
|
458
467
|
};
|
|
459
468
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
460
469
|
for (const e in params) {
|
|
@@ -464,23 +473,26 @@ const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
464
473
|
}
|
|
465
474
|
return obj;
|
|
466
475
|
};
|
|
467
|
-
const overwriteDeep = (obj, params,
|
|
476
|
+
const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
477
|
+
const excl = opts.exclude || [];
|
|
478
|
+
const forcedExclude = opts.preventForce ? [] : ["node", "window"];
|
|
468
479
|
if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
|
|
469
480
|
return params;
|
|
470
481
|
}
|
|
471
|
-
if (visited.has(obj))
|
|
482
|
+
if (visited.has(obj))
|
|
472
483
|
return visited.get(obj);
|
|
473
|
-
}
|
|
474
484
|
visited.set(obj, obj);
|
|
475
485
|
for (const e in params) {
|
|
476
|
-
if (
|
|
486
|
+
if (!Object.hasOwnProperty.call(params, e))
|
|
487
|
+
continue;
|
|
488
|
+
if (excl.includes(e) || forcedExclude && e.startsWith("__"))
|
|
477
489
|
continue;
|
|
478
490
|
const objProp = obj[e];
|
|
479
491
|
const paramsProp = params[e];
|
|
480
492
|
if ((0, import_node.isDOMNode)(paramsProp)) {
|
|
481
493
|
obj[e] = paramsProp;
|
|
482
494
|
} else if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
483
|
-
obj[e] = overwriteDeep(objProp, paramsProp,
|
|
495
|
+
obj[e] = overwriteDeep(objProp, paramsProp, opts, visited);
|
|
484
496
|
} else if (paramsProp !== void 0) {
|
|
485
497
|
obj[e] = paramsProp;
|
|
486
498
|
}
|
|
@@ -643,3 +655,27 @@ const detectInfiniteLoop = (arr) => {
|
|
|
643
655
|
}
|
|
644
656
|
}
|
|
645
657
|
};
|
|
658
|
+
const isCyclic = (obj) => {
|
|
659
|
+
const seenObjects = [];
|
|
660
|
+
function detect(obj2) {
|
|
661
|
+
if (obj2 && typeof obj2 === "object") {
|
|
662
|
+
if (seenObjects.indexOf(obj2) !== -1) {
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
seenObjects.push(obj2);
|
|
666
|
+
for (const key in obj2) {
|
|
667
|
+
if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
668
|
+
console.log(obj2, "cycle at " + key);
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
return detect(obj);
|
|
676
|
+
};
|
|
677
|
+
const excludeKeysFromObject = (obj, excludedKeys) => {
|
|
678
|
+
const result = { ...obj };
|
|
679
|
+
excludedKeys.forEach((key) => delete result[key]);
|
|
680
|
+
return result;
|
|
681
|
+
};
|
package/object.js
CHANGED
|
@@ -502,23 +502,30 @@ export const deepDiff = (lhs, rhs) => {
|
|
|
502
502
|
/**
|
|
503
503
|
* Overwrites object properties with another
|
|
504
504
|
*/
|
|
505
|
-
export const overwrite = (element, params,
|
|
506
|
-
const { ref } = element
|
|
507
|
-
const
|
|
505
|
+
export const overwrite = (element, params, opts = {}) => {
|
|
506
|
+
const { __ref: ref } = element
|
|
507
|
+
const excl = opts.exclude || []
|
|
508
|
+
const allowUnderscore = opts.preventUnderscore
|
|
509
|
+
const preventCaching = opts.preventCaching
|
|
508
510
|
|
|
509
511
|
for (const e in params) {
|
|
510
|
-
if (
|
|
512
|
+
if (excl.includes(e) || (!allowUnderscore && e.startsWith('__'))) continue
|
|
511
513
|
|
|
512
514
|
const elementProp = element[e]
|
|
513
515
|
const paramsProp = params[e]
|
|
514
516
|
|
|
515
|
-
if (paramsProp) {
|
|
516
|
-
|
|
517
|
-
ref
|
|
517
|
+
if (paramsProp !== undefined) {
|
|
518
|
+
element[e] = paramsProp
|
|
519
|
+
if (ref && !preventCaching) {
|
|
520
|
+
ref.__cache[e] = elementProp
|
|
521
|
+
}
|
|
522
|
+
if (isObject(opts.diff)) {
|
|
523
|
+
diff[e] = elementProp
|
|
524
|
+
}
|
|
518
525
|
}
|
|
519
526
|
}
|
|
520
527
|
|
|
521
|
-
return
|
|
528
|
+
return element
|
|
522
529
|
}
|
|
523
530
|
|
|
524
531
|
export const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
@@ -532,19 +539,20 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
532
539
|
/**
|
|
533
540
|
* Overwrites DEEPLY object properties with another
|
|
534
541
|
*/
|
|
535
|
-
export const overwriteDeep = (obj, params,
|
|
542
|
+
export const overwriteDeep = (obj, params, opts = {}, visited = new WeakMap()) => {
|
|
543
|
+
const excl = opts.exclude || []
|
|
544
|
+
const forcedExclude = opts.preventForce ? [] : ['node', 'window']
|
|
545
|
+
|
|
536
546
|
if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
|
|
537
547
|
return params
|
|
538
548
|
}
|
|
539
549
|
|
|
540
|
-
if (visited.has(obj))
|
|
541
|
-
return visited.get(obj)
|
|
542
|
-
}
|
|
543
|
-
|
|
550
|
+
if (visited.has(obj)) return visited.get(obj)
|
|
544
551
|
visited.set(obj, obj)
|
|
545
552
|
|
|
546
553
|
for (const e in params) {
|
|
547
|
-
if (
|
|
554
|
+
if (!Object.hasOwnProperty.call(params, e)) continue
|
|
555
|
+
if (excl.includes(e) || (forcedExclude && e.startsWith('__'))) continue
|
|
548
556
|
|
|
549
557
|
const objProp = obj[e]
|
|
550
558
|
const paramsProp = params[e]
|
|
@@ -552,7 +560,7 @@ export const overwriteDeep = (obj, params, excludeFrom = [], visited = new WeakM
|
|
|
552
560
|
if (isDOMNode(paramsProp)) {
|
|
553
561
|
obj[e] = paramsProp
|
|
554
562
|
} else if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
|
555
|
-
obj[e] = overwriteDeep(objProp, paramsProp,
|
|
563
|
+
obj[e] = overwriteDeep(objProp, paramsProp, opts, visited)
|
|
556
564
|
} else if (paramsProp !== undefined) {
|
|
557
565
|
obj[e] = paramsProp
|
|
558
566
|
}
|
|
@@ -795,3 +803,31 @@ export const detectInfiniteLoop = arr => {
|
|
|
795
803
|
}
|
|
796
804
|
}
|
|
797
805
|
}
|
|
806
|
+
|
|
807
|
+
export const isCyclic = (obj) => {
|
|
808
|
+
const seenObjects = []
|
|
809
|
+
|
|
810
|
+
function detect (obj) {
|
|
811
|
+
if (obj && typeof obj === 'object') {
|
|
812
|
+
if (seenObjects.indexOf(obj) !== -1) {
|
|
813
|
+
return true
|
|
814
|
+
}
|
|
815
|
+
seenObjects.push(obj)
|
|
816
|
+
for (const key in obj) {
|
|
817
|
+
if (Object.hasOwnProperty.call(obj, key) && detect(obj[key])) {
|
|
818
|
+
console.log(obj, 'cycle at ' + key)
|
|
819
|
+
return true
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return false
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
return detect(obj)
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
export const excludeKeysFromObject = (obj, excludedKeys) => {
|
|
830
|
+
const result = { ...obj }
|
|
831
|
+
excludedKeys.forEach(key => delete result[key])
|
|
832
|
+
return result
|
|
833
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.147",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "yarn build:cjs",
|
|
26
26
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "51d1a003e3d4eae96daa9eeed10e63bde2152f9d",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|