@domql/utils 2.5.116 → 2.5.117
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/dist/cjs/node.js +4 -0
- package/dist/cjs/object.js +27 -20
- package/node.js +9 -0
- package/object.js +59 -22
- package/package.json +2 -2
package/dist/cjs/node.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
+
isDOMNode: () => isDOMNode,
|
|
21
22
|
isHtmlElement: () => isHtmlElement,
|
|
22
23
|
isNode: () => isNode
|
|
23
24
|
});
|
|
@@ -29,3 +30,6 @@ const isNode = (obj) => {
|
|
|
29
30
|
const isHtmlElement = (obj) => {
|
|
30
31
|
return (typeof HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
31
32
|
};
|
|
33
|
+
const isDOMNode = (obj) => {
|
|
34
|
+
return typeof import_globals.window !== "undefined" && (obj instanceof import_globals.window.Node || obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
35
|
+
};
|
package/dist/cjs/object.js
CHANGED
|
@@ -58,6 +58,7 @@ var import_globals = require("./globals.js");
|
|
|
58
58
|
var import_types = require("./types.js");
|
|
59
59
|
var import_array = require("./array.js");
|
|
60
60
|
var import_string = require("./string.js");
|
|
61
|
+
var import_node = require("./node.js");
|
|
61
62
|
const exec = (param, element, state, context) => {
|
|
62
63
|
if ((0, import_types.isFunction)(param)) {
|
|
63
64
|
return param(
|
|
@@ -136,27 +137,28 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
136
137
|
const mergeArrayExclude = (arr, excl = []) => {
|
|
137
138
|
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
138
139
|
};
|
|
139
|
-
const deepClone = (obj,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
140
|
+
const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
141
|
+
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj))
|
|
142
|
+
return obj;
|
|
143
|
+
if (visited.has(obj))
|
|
144
|
+
return visited.get(obj);
|
|
145
|
+
const clone2 = (0, import_types.isArray)(obj) ? [] : {};
|
|
146
|
+
visited.set(obj, clone2);
|
|
147
|
+
for (const key in obj) {
|
|
148
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
|
|
149
|
+
const value = obj[key];
|
|
150
|
+
if ((0, import_node.isDOMNode)(value)) {
|
|
151
|
+
clone2[key] = value;
|
|
152
|
+
} else if (key === "extend" && (0, import_types.isArray)(value)) {
|
|
153
|
+
clone2[key] = (0, import_array.mergeArray)(value, exclude);
|
|
154
|
+
} else if ((0, import_types.isObjectLike)(value)) {
|
|
155
|
+
clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
|
|
156
|
+
} else {
|
|
157
|
+
clone2[key] = value;
|
|
158
|
+
}
|
|
153
159
|
}
|
|
154
|
-
if ((0, import_types.isObjectLike)(objProp)) {
|
|
155
|
-
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined);
|
|
156
|
-
} else
|
|
157
|
-
o[prop] = objProp;
|
|
158
160
|
}
|
|
159
|
-
return
|
|
161
|
+
return clone2;
|
|
160
162
|
};
|
|
161
163
|
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
|
|
162
164
|
const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
|
|
@@ -472,6 +474,8 @@ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
|
472
474
|
return true;
|
|
473
475
|
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2))
|
|
474
476
|
return false;
|
|
477
|
+
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2))
|
|
478
|
+
return obj1 === obj2;
|
|
475
479
|
const stack = [[obj1, obj2]];
|
|
476
480
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
477
481
|
while (stack.length > 0) {
|
|
@@ -488,7 +492,10 @@ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
|
488
492
|
return false;
|
|
489
493
|
const value1 = current1[key];
|
|
490
494
|
const value2 = current2[key];
|
|
491
|
-
if ((0,
|
|
495
|
+
if ((0, import_node.isDOMNode)(value1) || (0, import_node.isDOMNode)(value2)) {
|
|
496
|
+
if (value1 !== value2)
|
|
497
|
+
return false;
|
|
498
|
+
} else if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) {
|
|
492
499
|
if (value1 !== value2) {
|
|
493
500
|
stack.push([value1, value2]);
|
|
494
501
|
}
|
package/node.js
CHANGED
|
@@ -18,3 +18,12 @@ export const isHtmlElement = obj => {
|
|
|
18
18
|
: obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
|
|
19
19
|
) || false
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
export const isDOMNode = (obj) => {
|
|
23
|
+
return typeof window !== 'undefined' && (
|
|
24
|
+
obj instanceof window.Node ||
|
|
25
|
+
obj instanceof window.Window ||
|
|
26
|
+
obj === window ||
|
|
27
|
+
obj === document
|
|
28
|
+
)
|
|
29
|
+
}
|
package/object.js
CHANGED
|
@@ -4,6 +4,7 @@ import { window } from './globals.js'
|
|
|
4
4
|
import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined, isDate, isNull } from './types.js'
|
|
5
5
|
import { mergeAndCloneIfArray, mergeArray } from './array.js'
|
|
6
6
|
import { stringIncludesAny } from './string.js'
|
|
7
|
+
import { isDOMNode } from './node.js'
|
|
7
8
|
|
|
8
9
|
export const exec = (param, element, state, context) => {
|
|
9
10
|
if (isFunction(param)) {
|
|
@@ -95,29 +96,62 @@ export const mergeArrayExclude = (arr, excl = []) => {
|
|
|
95
96
|
/**
|
|
96
97
|
* Deep cloning of object
|
|
97
98
|
*/
|
|
98
|
-
export const deepClone = (obj,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
export const deepClone = (obj, exclude = [], cleanUndefined = false, visited = new WeakMap()) => {
|
|
100
|
+
// Handle non-object types, null, and ignored types
|
|
101
|
+
if (!isObjectLike(obj) || isDOMNode(obj)) return obj
|
|
102
|
+
|
|
103
|
+
// Check for circular references
|
|
104
|
+
if (visited.has(obj)) return visited.get(obj)
|
|
105
|
+
|
|
106
|
+
// Create a new object or array
|
|
107
|
+
const clone = isArray(obj) ? [] : {}
|
|
108
|
+
|
|
109
|
+
// Store the clone in the WeakMap to handle circular references
|
|
110
|
+
visited.set(obj, clone)
|
|
111
|
+
|
|
112
|
+
// Iterate over the properties of the object
|
|
113
|
+
for (const key in obj) {
|
|
114
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
|
|
115
|
+
const value = obj[key]
|
|
116
|
+
|
|
117
|
+
if (isDOMNode(value)) {
|
|
118
|
+
// Skip cloning for DOM nodes
|
|
119
|
+
clone[key] = value
|
|
120
|
+
} else if (key === 'extend' && isArray(value)) {
|
|
121
|
+
clone[key] = mergeArray(value, exclude)
|
|
122
|
+
} else if (isObjectLike(value)) {
|
|
123
|
+
clone[key] = deepClone(value, exclude, cleanUndefined, visited)
|
|
124
|
+
} else {
|
|
125
|
+
clone[key] = value
|
|
126
|
+
}
|
|
112
127
|
}
|
|
113
|
-
if (isObjectLike(objProp)) {
|
|
114
|
-
// queueMicrotask(() => {
|
|
115
|
-
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
116
|
-
// })
|
|
117
|
-
} else o[prop] = objProp
|
|
118
128
|
}
|
|
119
|
-
|
|
129
|
+
|
|
130
|
+
return clone
|
|
120
131
|
}
|
|
132
|
+
// export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
133
|
+
// const o = isArray(obj) ? [] : {}
|
|
134
|
+
// for (const prop in obj) {
|
|
135
|
+
// if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue
|
|
136
|
+
// // if (prop === 'node' || prop === 'parent' || prop === 'root' || prop === '__element') {
|
|
137
|
+
// // console.warn('recursive clonning is called', obj)
|
|
138
|
+
// // continue
|
|
139
|
+
// // }
|
|
140
|
+
// if (prop === '__proto__') continue
|
|
141
|
+
// if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
142
|
+
// let objProp = obj[prop]
|
|
143
|
+
// if (cleanUndefined && isUndefined(objProp)) continue
|
|
144
|
+
// if (prop === 'extend' && isArray(objProp)) {
|
|
145
|
+
// objProp = mergeArray(objProp)
|
|
146
|
+
// }
|
|
147
|
+
// if (isObjectLike(objProp)) {
|
|
148
|
+
// // queueMicrotask(() => {
|
|
149
|
+
// o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
150
|
+
// // })
|
|
151
|
+
// } else o[prop] = objProp
|
|
152
|
+
// }
|
|
153
|
+
// return o
|
|
154
|
+
// }
|
|
121
155
|
|
|
122
156
|
/**
|
|
123
157
|
* Deep cloning of object
|
|
@@ -541,6 +575,7 @@ export const isEqualDeep = (param, element, visited = new Set()) => {
|
|
|
541
575
|
export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
542
576
|
if (obj1 === obj2) return true
|
|
543
577
|
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false
|
|
578
|
+
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2
|
|
544
579
|
|
|
545
580
|
const stack = [[obj1, obj2]]
|
|
546
581
|
const visited = new WeakSet()
|
|
@@ -562,7 +597,9 @@ export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
|
562
597
|
const value1 = current1[key]
|
|
563
598
|
const value2 = current2[key]
|
|
564
599
|
|
|
565
|
-
if (
|
|
600
|
+
if (isDOMNode(value1) || isDOMNode(value2)) {
|
|
601
|
+
if (value1 !== value2) return false
|
|
602
|
+
} else if (isObjectLike(value1) && isObjectLike(value2)) {
|
|
566
603
|
if (value1 !== value2) {
|
|
567
604
|
stack.push([value1, value2])
|
|
568
605
|
}
|
|
@@ -573,7 +610,7 @@ export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
|
573
610
|
}
|
|
574
611
|
|
|
575
612
|
return true
|
|
576
|
-
}
|
|
613
|
+
}
|
|
577
614
|
|
|
578
615
|
export const removeFromObject = (obj, props) => {
|
|
579
616
|
if (props === undefined || props === null) return obj
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.117",
|
|
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": "
|
|
26
|
+
"gitHead": "56be344ba28e3cb51c146c1b74fe3c0e21341879",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|