@domql/utils 2.5.117 → 2.5.119

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 CHANGED
@@ -67,26 +67,6 @@ export const cutArrayAfterValue = (arr, value) => {
67
67
  return arr
68
68
  }
69
69
 
70
- export const createNestedObject = (arr, lastValue) => {
71
- const nestedObject = {}
72
-
73
- if (arr.length === 0) {
74
- return lastValue
75
- }
76
-
77
- arr.reduce((obj, value, index) => {
78
- if (!obj[value]) {
79
- obj[value] = {}
80
- }
81
- if (index === arr.length - 1 && lastValue) {
82
- obj[value] = lastValue
83
- }
84
- return obj[value]
85
- }, nestedObject)
86
-
87
- return nestedObject
88
- }
89
-
90
70
  export const removeValueFromArray = (arr, value) => {
91
71
  const index = arr.indexOf(value)
92
72
  if (index > -1) {
package/dist/cjs/array.js CHANGED
@@ -21,7 +21,6 @@ __export(array_exports, {
21
21
  addItemAfterEveryElement: () => addItemAfterEveryElement,
22
22
  arrayContainsOtherArray: () => arrayContainsOtherArray,
23
23
  arraysEqual: () => arraysEqual,
24
- createNestedObject: () => createNestedObject,
25
24
  cutArrayAfterValue: () => cutArrayAfterValue,
26
25
  cutArrayBeforeValue: () => cutArrayBeforeValue,
27
26
  getFrequencyInArray: () => getFrequencyInArray,
@@ -88,22 +87,6 @@ const cutArrayAfterValue = (arr, value) => {
88
87
  }
89
88
  return arr;
90
89
  };
91
- const createNestedObject = (arr, lastValue) => {
92
- const nestedObject = {};
93
- if (arr.length === 0) {
94
- return lastValue;
95
- }
96
- arr.reduce((obj, value, index) => {
97
- if (!obj[value]) {
98
- obj[value] = {};
99
- }
100
- if (index === arr.length - 1 && lastValue) {
101
- obj[value] = lastValue;
102
- }
103
- return obj[value];
104
- }, nestedObject);
105
- return nestedObject;
106
- };
107
90
  const removeValueFromArray = (arr, value) => {
108
91
  const index = arr.indexOf(value);
109
92
  if (index > -1) {
@@ -20,6 +20,7 @@ var object_exports = {};
20
20
  __export(object_exports, {
21
21
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
22
22
  clone: () => clone,
23
+ createNestedObject: () => createNestedObject,
23
24
  createObjectWithoutPrototype: () => createObjectWithoutPrototype,
24
25
  deepClone: () => deepClone,
25
26
  deepCloneExclude: () => deepCloneExclude,
@@ -51,6 +52,7 @@ __export(object_exports, {
51
52
  overwriteDeep: () => overwriteDeep,
52
53
  overwriteShallow: () => overwriteShallow,
53
54
  removeFromObject: () => removeFromObject,
55
+ removeNestedKeyByPath: () => removeNestedKeyByPath,
54
56
  stringToObject: () => stringToObject
55
57
  });
56
58
  module.exports = __toCommonJS(object_exports);
@@ -413,16 +415,23 @@ const overwriteShallow = (obj, params, excludeFrom = []) => {
413
415
  }
414
416
  return obj;
415
417
  };
416
- const overwriteDeep = (obj, params, excludeFrom = []) => {
418
+ const overwriteDeep = (obj, params, excludeFrom = [], visited = /* @__PURE__ */ new WeakMap()) => {
419
+ if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
420
+ return params;
421
+ }
422
+ if (visited.has(obj)) {
423
+ return visited.get(obj);
424
+ }
425
+ visited.set(obj, obj);
417
426
  for (const e in params) {
418
- if (e === "__ref")
419
- continue;
420
- if (excludeFrom.includes(e) || e.startsWith("__"))
427
+ if (e === "__ref" || excludeFrom.includes(e) || e.startsWith("__"))
421
428
  continue;
422
429
  const objProp = obj[e];
423
430
  const paramsProp = params[e];
424
- if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
425
- overwriteDeep(objProp, paramsProp);
431
+ if ((0, import_node.isDOMNode)(paramsProp)) {
432
+ obj[e] = paramsProp;
433
+ } else if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
434
+ obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited);
426
435
  } else if (paramsProp !== void 0) {
427
436
  obj[e] = paramsProp;
428
437
  }
@@ -578,3 +587,35 @@ const getExtendsInElement = (obj) => {
578
587
  traverse(obj);
579
588
  return result;
580
589
  };
590
+ const createNestedObject = (arr, lastValue) => {
591
+ const nestedObject = {};
592
+ if (arr.length === 0) {
593
+ return lastValue;
594
+ }
595
+ arr.reduce((obj, value, index) => {
596
+ if (!obj[value]) {
597
+ obj[value] = {};
598
+ }
599
+ if (index === arr.length - 1 && lastValue) {
600
+ obj[value] = lastValue;
601
+ }
602
+ return obj[value];
603
+ }, nestedObject);
604
+ return nestedObject;
605
+ };
606
+ const removeNestedKeyByPath = (obj, path) => {
607
+ if (!Array.isArray(path)) {
608
+ throw new Error("Path must be an array.");
609
+ }
610
+ let current = obj;
611
+ for (let i = 0; i < path.length - 1; i++) {
612
+ if (current[path[i]] === void 0) {
613
+ return;
614
+ }
615
+ current = current[path[i]];
616
+ }
617
+ const lastKey = path[path.length - 1];
618
+ if (current && Object.hasOwnProperty.call(current, lastKey)) {
619
+ delete current[lastKey];
620
+ }
621
+ };
package/object.js CHANGED
@@ -460,18 +460,32 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
460
460
  /**
461
461
  * Overwrites DEEPLY object properties with another
462
462
  */
463
- export const overwriteDeep = (obj, params, excludeFrom = []) => {
463
+ export const overwriteDeep = (obj, params, excludeFrom = [], visited = new WeakMap()) => {
464
+ if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
465
+ return params
466
+ }
467
+
468
+ if (visited.has(obj)) {
469
+ return visited.get(obj)
470
+ }
471
+
472
+ visited.set(obj, obj)
473
+
464
474
  for (const e in params) {
465
- if (e === '__ref') continue
466
- if (excludeFrom.includes(e) || e.startsWith('__')) continue
475
+ if (e === '__ref' || excludeFrom.includes(e) || e.startsWith('__')) continue
476
+
467
477
  const objProp = obj[e]
468
478
  const paramsProp = params[e]
469
- if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
470
- overwriteDeep(objProp, paramsProp)
479
+
480
+ if (isDOMNode(paramsProp)) {
481
+ obj[e] = paramsProp
482
+ } else if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
483
+ obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited)
471
484
  } else if (paramsProp !== undefined) {
472
485
  obj[e] = paramsProp
473
486
  }
474
487
  }
488
+
475
489
  return obj
476
490
  }
477
491
 
@@ -700,3 +714,43 @@ export const getExtendsInElement = (obj) => {
700
714
  traverse(obj)
701
715
  return result
702
716
  }
717
+
718
+ export const createNestedObject = (arr, lastValue) => {
719
+ const nestedObject = {}
720
+
721
+ if (arr.length === 0) {
722
+ return lastValue
723
+ }
724
+
725
+ arr.reduce((obj, value, index) => {
726
+ if (!obj[value]) {
727
+ obj[value] = {}
728
+ }
729
+ if (index === arr.length - 1 && lastValue) {
730
+ obj[value] = lastValue
731
+ }
732
+ return obj[value]
733
+ }, nestedObject)
734
+
735
+ return nestedObject
736
+ }
737
+
738
+ export const removeNestedKeyByPath = (obj, path) => {
739
+ if (!Array.isArray(path)) {
740
+ throw new Error('Path must be an array.')
741
+ }
742
+
743
+ let current = obj
744
+
745
+ for (let i = 0; i < path.length - 1; i++) {
746
+ if (current[path[i]] === undefined) {
747
+ return // Path does not exist, so nothing to remove.
748
+ }
749
+ current = current[path[i]]
750
+ }
751
+
752
+ const lastKey = path[path.length - 1]
753
+ if (current && Object.hasOwnProperty.call(current, lastKey)) {
754
+ delete current[lastKey]
755
+ }
756
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.117",
3
+ "version": "2.5.119",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -23,7 +23,7 @@
23
23
  "build": "yarn build:cjs",
24
24
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
25
25
  },
26
- "gitHead": "56be344ba28e3cb51c146c1b74fe3c0e21341879",
26
+ "gitHead": "930d02cd05b1fa9cbfe3da9b1eea3f1baafdab6b",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }