@domql/utils 2.5.114 → 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 +49 -43
- package/node.js +9 -0
- package/object.js +82 -46
- 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) ? [] : {};
|
|
@@ -467,33 +469,37 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
467
469
|
}
|
|
468
470
|
return true;
|
|
469
471
|
};
|
|
470
|
-
const deepContains = (obj1, obj2) => {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
472
|
+
const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
473
|
+
if (obj1 === obj2)
|
|
474
|
+
return true;
|
|
475
|
+
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2))
|
|
476
|
+
return false;
|
|
477
|
+
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2))
|
|
478
|
+
return obj1 === obj2;
|
|
479
|
+
const stack = [[obj1, obj2]];
|
|
480
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
481
|
+
while (stack.length > 0) {
|
|
482
|
+
const [current1, current2] = stack.pop();
|
|
483
|
+
if (visited.has(current1))
|
|
484
|
+
continue;
|
|
485
|
+
visited.add(current1);
|
|
486
|
+
const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key));
|
|
487
|
+
const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key));
|
|
488
|
+
if (keys1.length !== keys2.length)
|
|
475
489
|
return false;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
490
|
+
for (const key of keys1) {
|
|
491
|
+
if (!Object.prototype.hasOwnProperty.call(current2, key))
|
|
492
|
+
return false;
|
|
493
|
+
const value1 = current1[key];
|
|
494
|
+
const value2 = current2[key];
|
|
495
|
+
if ((0, import_node.isDOMNode)(value1) || (0, import_node.isDOMNode)(value2)) {
|
|
496
|
+
if (value1 !== value2)
|
|
480
497
|
return false;
|
|
498
|
+
} else if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) {
|
|
499
|
+
if (value1 !== value2) {
|
|
500
|
+
stack.push([value1, value2]);
|
|
481
501
|
}
|
|
482
|
-
|
|
483
|
-
stack.push({ obj1: obj12[i], obj2: obj22[i] });
|
|
484
|
-
}
|
|
485
|
-
} else if ((0, import_types.isObjectLike)(obj12) && obj22 !== null) {
|
|
486
|
-
for (const key in obj12) {
|
|
487
|
-
if (Object.prototype.hasOwnProperty.call(obj12, key)) {
|
|
488
|
-
if (!Object.prototype.hasOwnProperty.call(obj22, key)) {
|
|
489
|
-
return false;
|
|
490
|
-
}
|
|
491
|
-
stack.push({ obj1: obj12[key], obj2: obj22[key] });
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
} else {
|
|
496
|
-
if (obj12 !== obj22) {
|
|
502
|
+
} else if (value1 !== value2) {
|
|
497
503
|
return false;
|
|
498
504
|
}
|
|
499
505
|
}
|
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
|
|
@@ -538,36 +572,38 @@ export const isEqualDeep = (param, element, visited = new Set()) => {
|
|
|
538
572
|
return true
|
|
539
573
|
}
|
|
540
574
|
|
|
541
|
-
export const deepContains = (obj1, obj2) => {
|
|
542
|
-
|
|
575
|
+
export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
576
|
+
if (obj1 === obj2) return true
|
|
577
|
+
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false
|
|
578
|
+
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2
|
|
543
579
|
|
|
544
|
-
|
|
545
|
-
|
|
580
|
+
const stack = [[obj1, obj2]]
|
|
581
|
+
const visited = new WeakSet()
|
|
546
582
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
583
|
+
while (stack.length > 0) {
|
|
584
|
+
const [current1, current2] = stack.pop()
|
|
550
585
|
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
586
|
+
if (visited.has(current1)) continue
|
|
587
|
+
visited.add(current1)
|
|
588
|
+
|
|
589
|
+
const keys1 = Object.keys(current1).filter(key => !ignoredKeys.includes(key))
|
|
590
|
+
const keys2 = Object.keys(current2).filter(key => !ignoredKeys.includes(key))
|
|
591
|
+
|
|
592
|
+
if (keys1.length !== keys2.length) return false
|
|
593
|
+
|
|
594
|
+
for (const key of keys1) {
|
|
595
|
+
if (!Object.prototype.hasOwnProperty.call(current2, key)) return false
|
|
596
|
+
|
|
597
|
+
const value1 = current1[key]
|
|
598
|
+
const value2 = current2[key]
|
|
599
|
+
|
|
600
|
+
if (isDOMNode(value1) || isDOMNode(value2)) {
|
|
601
|
+
if (value1 !== value2) return false
|
|
602
|
+
} else if (isObjectLike(value1) && isObjectLike(value2)) {
|
|
603
|
+
if (value1 !== value2) {
|
|
604
|
+
stack.push([value1, value2])
|
|
567
605
|
}
|
|
568
|
-
}
|
|
569
|
-
} else {
|
|
570
|
-
if (obj1 !== obj2) {
|
|
606
|
+
} else if (value1 !== value2) {
|
|
571
607
|
return false
|
|
572
608
|
}
|
|
573
609
|
}
|
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
|
}
|