@domql/utils 2.5.187 → 3.0.0
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 +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +30 -16
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +16 -226
- package/dist/cjs/cookie.js +19 -24
- package/dist/cjs/element.js +137 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/function.js +2 -4
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +25 -15
- package/dist/cjs/key.js +6 -1
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/log.js +1 -2
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +89 -237
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -16
- package/dist/cjs/types.js +2 -4
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +30 -16
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +17 -245
- package/dist/esm/cookie.js +19 -24
- package/dist/esm/element.js +135 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/function.js +2 -4
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +6 -1
- package/dist/esm/keys.js +158 -0
- package/dist/esm/log.js +1 -2
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +90 -239
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -16
- package/dist/esm/types.js +2 -4
- package/dist/esm/update.js +22 -0
- package/element.js +149 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +121 -235
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
package/dist/cjs/object.js
CHANGED
|
@@ -24,18 +24,12 @@ __export(object_exports, {
|
|
|
24
24
|
deepClone: () => deepClone,
|
|
25
25
|
deepContains: () => deepContains,
|
|
26
26
|
deepDestringify: () => deepDestringify,
|
|
27
|
-
deepDiff: () => deepDiff,
|
|
28
27
|
deepMerge: () => deepMerge,
|
|
29
28
|
deepStringify: () => deepStringify,
|
|
30
|
-
deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
|
|
31
|
-
detachFunctionsFromObject: () => detachFunctionsFromObject,
|
|
32
29
|
detectInfiniteLoop: () => detectInfiniteLoop,
|
|
33
|
-
diff: () => diff,
|
|
34
|
-
diffArrays: () => diffArrays,
|
|
35
|
-
diffObjects: () => diffObjects,
|
|
36
30
|
excludeKeysFromObject: () => excludeKeysFromObject,
|
|
37
31
|
exec: () => exec,
|
|
38
|
-
|
|
32
|
+
execPromise: () => execPromise,
|
|
39
33
|
getInObjectByPath: () => getInObjectByPath,
|
|
40
34
|
hasFunction: () => hasFunction,
|
|
41
35
|
hasOwnProperty: () => hasOwnProperty,
|
|
@@ -46,8 +40,6 @@ __export(object_exports, {
|
|
|
46
40
|
makeObjectWithoutPrototype: () => makeObjectWithoutPrototype,
|
|
47
41
|
map: () => map,
|
|
48
42
|
merge: () => merge,
|
|
49
|
-
mergeArrayExclude: () => mergeArrayExclude,
|
|
50
|
-
mergeIfExisted: () => mergeIfExisted,
|
|
51
43
|
objectToString: () => objectToString,
|
|
52
44
|
overwrite: () => overwrite,
|
|
53
45
|
overwriteDeep: () => overwriteDeep,
|
|
@@ -63,6 +55,7 @@ var import_types = require("./types.js");
|
|
|
63
55
|
var import_array = require("./array.js");
|
|
64
56
|
var import_string = require("./string.js");
|
|
65
57
|
var import_node = require("./node.js");
|
|
58
|
+
var import_keys = require("./keys.js");
|
|
66
59
|
const ENV = "development";
|
|
67
60
|
const exec = (param, element, state, context) => {
|
|
68
61
|
if ((0, import_types.isFunction)(param)) {
|
|
@@ -75,6 +68,17 @@ const exec = (param, element, state, context) => {
|
|
|
75
68
|
}
|
|
76
69
|
return param;
|
|
77
70
|
};
|
|
71
|
+
const execPromise = async (param, element, state, context) => {
|
|
72
|
+
if ((0, import_types.isFunction)(param)) {
|
|
73
|
+
return await param.call(
|
|
74
|
+
element,
|
|
75
|
+
element,
|
|
76
|
+
state || element.state,
|
|
77
|
+
context || element.context
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return param;
|
|
81
|
+
};
|
|
78
82
|
const map = (obj, extention, element) => {
|
|
79
83
|
for (const e in extention) {
|
|
80
84
|
obj[e] = exec(extention[e], element);
|
|
@@ -83,8 +87,9 @@ const map = (obj, extention, element) => {
|
|
|
83
87
|
const merge = (element, obj, excludeFrom = []) => {
|
|
84
88
|
for (const e in obj) {
|
|
85
89
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
|
|
86
|
-
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
90
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
|
|
87
91
|
continue;
|
|
92
|
+
}
|
|
88
93
|
const elementProp = element[e];
|
|
89
94
|
const objProp = obj[e];
|
|
90
95
|
if (elementProp === void 0) {
|
|
@@ -93,11 +98,12 @@ const merge = (element, obj, excludeFrom = []) => {
|
|
|
93
98
|
}
|
|
94
99
|
return element;
|
|
95
100
|
};
|
|
96
|
-
const deepMerge = (element, extend, excludeFrom =
|
|
101
|
+
const deepMerge = (element, extend, excludeFrom = import_keys.METHODS_EXL) => {
|
|
97
102
|
for (const e in extend) {
|
|
98
103
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
|
|
99
|
-
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
104
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
|
|
100
105
|
continue;
|
|
106
|
+
}
|
|
101
107
|
const elementProp = element[e];
|
|
102
108
|
const extendProp = extend[e];
|
|
103
109
|
if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
|
|
@@ -112,15 +118,13 @@ const clone = (obj, excludeFrom = []) => {
|
|
|
112
118
|
const o = {};
|
|
113
119
|
for (const prop in obj) {
|
|
114
120
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
115
|
-
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
121
|
+
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) {
|
|
116
122
|
continue;
|
|
123
|
+
}
|
|
117
124
|
o[prop] = obj[prop];
|
|
118
125
|
}
|
|
119
126
|
return o;
|
|
120
127
|
};
|
|
121
|
-
const mergeArrayExclude = (arr, exclude = []) => {
|
|
122
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
|
|
123
|
-
};
|
|
124
128
|
const deepClone = (obj, options = {}) => {
|
|
125
129
|
const {
|
|
126
130
|
exclude = [],
|
|
@@ -128,7 +132,7 @@ const deepClone = (obj, options = {}) => {
|
|
|
128
132
|
cleanNull = false,
|
|
129
133
|
window: targetWindow,
|
|
130
134
|
visited = /* @__PURE__ */ new WeakMap(),
|
|
131
|
-
|
|
135
|
+
handleExtends = false
|
|
132
136
|
} = options;
|
|
133
137
|
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
|
|
134
138
|
return obj;
|
|
@@ -139,19 +143,20 @@ const deepClone = (obj, options = {}) => {
|
|
|
139
143
|
const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
|
|
140
144
|
visited.set(obj, clone2);
|
|
141
145
|
for (const key in obj) {
|
|
142
|
-
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
143
|
-
|
|
144
|
-
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
146
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
147
|
+
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") {
|
|
145
148
|
continue;
|
|
149
|
+
}
|
|
146
150
|
const value = obj[key];
|
|
147
|
-
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
|
|
151
|
+
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value)) {
|
|
148
152
|
continue;
|
|
153
|
+
}
|
|
149
154
|
if ((0, import_node.isDOMNode)(value)) {
|
|
150
155
|
clone2[key] = value;
|
|
151
156
|
continue;
|
|
152
157
|
}
|
|
153
|
-
if (
|
|
154
|
-
clone2[key] = (0, import_array.
|
|
158
|
+
if (handleExtends && key === "extends" && (0, import_types.isArray)(value)) {
|
|
159
|
+
clone2[key] = (0, import_array.unstackArrayOfObjects)(value, exclude);
|
|
155
160
|
continue;
|
|
156
161
|
}
|
|
157
162
|
if ((0, import_types.isFunction)(value) && targetWindow) {
|
|
@@ -172,7 +177,11 @@ const deepClone = (obj, options = {}) => {
|
|
|
172
177
|
const deepStringify = (obj, stringified = {}) => {
|
|
173
178
|
var _a, _b;
|
|
174
179
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
175
|
-
|
|
180
|
+
;
|
|
181
|
+
(obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn(
|
|
182
|
+
"Trying to clone element or state at",
|
|
183
|
+
obj
|
|
184
|
+
);
|
|
176
185
|
obj = (_b = obj.parse) == null ? void 0 : _b.call(obj);
|
|
177
186
|
}
|
|
178
187
|
for (const prop in obj) {
|
|
@@ -200,39 +209,6 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
200
209
|
}
|
|
201
210
|
return stringified;
|
|
202
211
|
};
|
|
203
|
-
const MAX_DEPTH = 100;
|
|
204
|
-
const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
|
|
205
|
-
if (depth > MAX_DEPTH) {
|
|
206
|
-
console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
|
|
207
|
-
return "[MAX_DEPTH_EXCEEDED]";
|
|
208
|
-
}
|
|
209
|
-
for (const prop in obj) {
|
|
210
|
-
const currentPath = path ? `${path}.${prop}` : prop;
|
|
211
|
-
const objProp = obj[prop];
|
|
212
|
-
if ((0, import_types.isFunction)(objProp)) {
|
|
213
|
-
stringified[prop] = objProp.toString();
|
|
214
|
-
} else if ((0, import_types.isObject)(objProp)) {
|
|
215
|
-
stringified[prop] = {};
|
|
216
|
-
deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
|
|
217
|
-
} else if ((0, import_types.isArray)(objProp)) {
|
|
218
|
-
stringified[prop] = [];
|
|
219
|
-
objProp.forEach((v, i) => {
|
|
220
|
-
const itemPath = `${currentPath}[${i}]`;
|
|
221
|
-
if ((0, import_types.isObject)(v)) {
|
|
222
|
-
stringified[prop][i] = {};
|
|
223
|
-
deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
|
|
224
|
-
} else if ((0, import_types.isFunction)(v)) {
|
|
225
|
-
stringified[prop][i] = v.toString();
|
|
226
|
-
} else {
|
|
227
|
-
stringified[prop][i] = v;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
} else {
|
|
231
|
-
stringified[prop] = objProp;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return stringified;
|
|
235
|
-
};
|
|
236
212
|
const objectToString = (obj = {}, indent = 0) => {
|
|
237
213
|
if (obj === null || typeof obj !== "object") {
|
|
238
214
|
return String(obj);
|
|
@@ -243,7 +219,22 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
243
219
|
const spaces = " ".repeat(indent);
|
|
244
220
|
let str = "{\n";
|
|
245
221
|
for (const [key, value] of Object.entries(obj)) {
|
|
246
|
-
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, [
|
|
222
|
+
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, [
|
|
223
|
+
"&",
|
|
224
|
+
"*",
|
|
225
|
+
"-",
|
|
226
|
+
":",
|
|
227
|
+
"%",
|
|
228
|
+
"{",
|
|
229
|
+
"}",
|
|
230
|
+
">",
|
|
231
|
+
"<",
|
|
232
|
+
"@",
|
|
233
|
+
".",
|
|
234
|
+
"/",
|
|
235
|
+
"!",
|
|
236
|
+
" "
|
|
237
|
+
]);
|
|
247
238
|
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
248
239
|
str += `${spaces} ${stringedKey}: `;
|
|
249
240
|
if ((0, import_types.isArray)(value)) {
|
|
@@ -273,42 +264,12 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
273
264
|
str += `${spaces}}`;
|
|
274
265
|
return str;
|
|
275
266
|
};
|
|
276
|
-
const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
277
|
-
for (const prop in obj) {
|
|
278
|
-
const objProp = obj[prop];
|
|
279
|
-
if ((0, import_types.isFunction)(objProp))
|
|
280
|
-
continue;
|
|
281
|
-
else if ((0, import_types.isObject)(objProp)) {
|
|
282
|
-
detached[prop] = {};
|
|
283
|
-
deepStringify(objProp, detached[prop]);
|
|
284
|
-
} else if ((0, import_types.isArray)(objProp)) {
|
|
285
|
-
detached[prop] = [];
|
|
286
|
-
objProp.forEach((v, i) => {
|
|
287
|
-
if ((0, import_types.isFunction)(v))
|
|
288
|
-
return;
|
|
289
|
-
if ((0, import_types.isObject)(v)) {
|
|
290
|
-
detached[prop][i] = {};
|
|
291
|
-
detachFunctionsFromObject(v, detached[prop][i]);
|
|
292
|
-
} else {
|
|
293
|
-
detached[prop][i] = v;
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
} else {
|
|
297
|
-
detached[prop] = objProp;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return detached;
|
|
301
|
-
};
|
|
302
267
|
const hasFunction = (str) => {
|
|
303
|
-
if (!str)
|
|
304
|
-
return false;
|
|
268
|
+
if (!str) return false;
|
|
305
269
|
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
306
|
-
if (trimmed === "")
|
|
307
|
-
|
|
308
|
-
if (trimmed === "
|
|
309
|
-
return false;
|
|
310
|
-
if (trimmed === "[]")
|
|
311
|
-
return false;
|
|
270
|
+
if (trimmed === "") return false;
|
|
271
|
+
if (trimmed === "{}") return false;
|
|
272
|
+
if (trimmed === "[]") return false;
|
|
312
273
|
const patterns = [
|
|
313
274
|
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
314
275
|
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
@@ -326,8 +287,7 @@ const hasFunction = (str) => {
|
|
|
326
287
|
const deepDestringify = (obj, destringified = {}) => {
|
|
327
288
|
for (const prop in obj) {
|
|
328
289
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
329
|
-
if (!hasOwnProperty2)
|
|
330
|
-
continue;
|
|
290
|
+
if (!hasOwnProperty2) continue;
|
|
331
291
|
const objProp = obj[prop];
|
|
332
292
|
if ((0, import_types.isString)(objProp)) {
|
|
333
293
|
if (hasFunction(objProp)) {
|
|
@@ -335,8 +295,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
335
295
|
const evalProp = import_globals.window.eval(`(${objProp})`);
|
|
336
296
|
destringified[prop] = evalProp;
|
|
337
297
|
} catch (e) {
|
|
338
|
-
if (e)
|
|
339
|
-
destringified[prop] = objProp;
|
|
298
|
+
if (e) destringified[prop] = objProp;
|
|
340
299
|
}
|
|
341
300
|
} else {
|
|
342
301
|
destringified[prop] = objProp;
|
|
@@ -350,8 +309,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
350
309
|
const evalProp = import_globals.window.eval(`(${arrProp})`);
|
|
351
310
|
destringified[prop].push(evalProp);
|
|
352
311
|
} catch (e) {
|
|
353
|
-
if (e)
|
|
354
|
-
destringified[prop].push(arrProp);
|
|
312
|
+
if (e) destringified[prop].push(arrProp);
|
|
355
313
|
}
|
|
356
314
|
} else {
|
|
357
315
|
destringified[prop].push(arrProp);
|
|
@@ -374,110 +332,28 @@ const stringToObject = (str, opts = { verbose: true }) => {
|
|
|
374
332
|
try {
|
|
375
333
|
return str ? import_globals.window.eval("(" + str + ")") : {};
|
|
376
334
|
} catch (e) {
|
|
377
|
-
if (opts.verbose)
|
|
378
|
-
console.warn(e);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
const diffObjects = (original, objToDiff, cache) => {
|
|
382
|
-
for (const e in objToDiff) {
|
|
383
|
-
if (e === "ref")
|
|
384
|
-
continue;
|
|
385
|
-
const originalProp = original[e];
|
|
386
|
-
const objToDiffProp = objToDiff[e];
|
|
387
|
-
if ((0, import_types.isObject)(originalProp) && (0, import_types.isObject)(objToDiffProp)) {
|
|
388
|
-
cache[e] = {};
|
|
389
|
-
diff(originalProp, objToDiffProp, cache[e]);
|
|
390
|
-
} else if (objToDiffProp !== void 0) {
|
|
391
|
-
cache[e] = objToDiffProp;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return cache;
|
|
395
|
-
};
|
|
396
|
-
const diffArrays = (original, objToDiff, cache) => {
|
|
397
|
-
if (original.length !== objToDiff.length) {
|
|
398
|
-
cache = objToDiff;
|
|
399
|
-
} else {
|
|
400
|
-
const diffArr = [];
|
|
401
|
-
for (let i = 0; i < original.length; i++) {
|
|
402
|
-
const diffObj = diff(original[i], objToDiff[i]);
|
|
403
|
-
if (Object.keys(diffObj).length > 0) {
|
|
404
|
-
diffArr.push(diffObj);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
if (diffArr.length > 0) {
|
|
408
|
-
cache = diffArr;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return cache;
|
|
412
|
-
};
|
|
413
|
-
const diff = (original, objToDiff, cache = {}) => {
|
|
414
|
-
if ((0, import_types.isArray)(original) && (0, import_types.isArray)(objToDiff)) {
|
|
415
|
-
cache = [];
|
|
416
|
-
diffArrays(original, objToDiff, cache);
|
|
417
|
-
} else {
|
|
418
|
-
diffObjects(original, objToDiff, cache);
|
|
335
|
+
if (opts.verbose) console.warn(e);
|
|
419
336
|
}
|
|
420
|
-
return cache;
|
|
421
337
|
};
|
|
422
338
|
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
423
339
|
const isEmpty = (o) => Object.keys(o).length === 0;
|
|
424
340
|
const isEmptyObject = (o) => (0, import_types.isObject)(o) && isEmpty(o);
|
|
425
341
|
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
426
|
-
const deepDiff = (lhs, rhs) => {
|
|
427
|
-
if (lhs === rhs)
|
|
428
|
-
return {};
|
|
429
|
-
if (!(0, import_types.isObjectLike)(lhs) || !(0, import_types.isObjectLike)(rhs))
|
|
430
|
-
return rhs;
|
|
431
|
-
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
432
|
-
if (!hasOwnProperty(rhs, key)) {
|
|
433
|
-
acc[key] = void 0;
|
|
434
|
-
}
|
|
435
|
-
return acc;
|
|
436
|
-
}, makeObjectWithoutPrototype());
|
|
437
|
-
if ((0, import_types.isDate)(lhs) || (0, import_types.isDate)(rhs)) {
|
|
438
|
-
if (lhs.valueOf() === rhs.valueOf())
|
|
439
|
-
return {};
|
|
440
|
-
return rhs;
|
|
441
|
-
}
|
|
442
|
-
return Object.keys(rhs).reduce((acc, key) => {
|
|
443
|
-
if (!hasOwnProperty(lhs, key)) {
|
|
444
|
-
acc[key] = rhs[key];
|
|
445
|
-
return acc;
|
|
446
|
-
}
|
|
447
|
-
const difference = diff(lhs[key], rhs[key]);
|
|
448
|
-
if (isEmptyObject(difference) && !(0, import_types.isDate)(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
|
|
449
|
-
return acc;
|
|
450
|
-
}
|
|
451
|
-
acc[key] = difference;
|
|
452
|
-
return acc;
|
|
453
|
-
}, deletedValues);
|
|
454
|
-
};
|
|
455
342
|
const overwrite = (element, params, opts = {}) => {
|
|
456
|
-
const { __ref: ref } = element;
|
|
457
343
|
const excl = opts.exclude || [];
|
|
458
344
|
const allowUnderscore = opts.preventUnderscore;
|
|
459
|
-
const preventCaching = opts.preventCaching;
|
|
460
345
|
for (const e in params) {
|
|
461
|
-
if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
|
|
462
|
-
continue;
|
|
463
|
-
const elementProp = element[e];
|
|
346
|
+
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue;
|
|
464
347
|
const paramsProp = params[e];
|
|
465
348
|
if (paramsProp !== void 0) {
|
|
466
349
|
element[e] = paramsProp;
|
|
467
|
-
if (ref && !preventCaching) {
|
|
468
|
-
ref.__cache[e] = elementProp;
|
|
469
|
-
}
|
|
470
|
-
if ((0, import_types.isObject)(opts.diff)) {
|
|
471
|
-
diff[e] = elementProp;
|
|
472
|
-
}
|
|
473
350
|
}
|
|
474
351
|
}
|
|
475
352
|
return element;
|
|
476
353
|
};
|
|
477
354
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
478
355
|
for (const e in params) {
|
|
479
|
-
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
480
|
-
continue;
|
|
356
|
+
if (excludeFrom.includes(e) || e.startsWith("__")) continue;
|
|
481
357
|
obj[e] = params[e];
|
|
482
358
|
}
|
|
483
359
|
return obj;
|
|
@@ -488,14 +364,11 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
|
|
|
488
364
|
if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
|
|
489
365
|
return params;
|
|
490
366
|
}
|
|
491
|
-
if (visited.has(obj))
|
|
492
|
-
return visited.get(obj);
|
|
367
|
+
if (visited.has(obj)) return visited.get(obj);
|
|
493
368
|
visited.set(obj, obj);
|
|
494
369
|
for (const e in params) {
|
|
495
|
-
if (!Object.hasOwnProperty.call(params, e))
|
|
496
|
-
|
|
497
|
-
if (excl.includes(e) || forcedExclude && e.startsWith("__"))
|
|
498
|
-
continue;
|
|
370
|
+
if (!Object.hasOwnProperty.call(params, e)) continue;
|
|
371
|
+
if (excl.includes(e) || forcedExclude && e.startsWith("__")) continue;
|
|
499
372
|
const objProp = obj[e];
|
|
500
373
|
const paramsProp = params[e];
|
|
501
374
|
if ((0, import_node.isDOMNode)(paramsProp)) {
|
|
@@ -508,20 +381,6 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
|
|
|
508
381
|
}
|
|
509
382
|
return obj;
|
|
510
383
|
};
|
|
511
|
-
const mergeIfExisted = (a, b) => {
|
|
512
|
-
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
|
|
513
|
-
return deepMerge(a, b);
|
|
514
|
-
return a || b;
|
|
515
|
-
};
|
|
516
|
-
const flattenRecursive = (param, prop, stack = []) => {
|
|
517
|
-
const objectized = (0, import_array.mergeAndCloneIfArray)(param);
|
|
518
|
-
stack.push(objectized);
|
|
519
|
-
const extendOfExtend = objectized[prop];
|
|
520
|
-
if (extendOfExtend)
|
|
521
|
-
flattenRecursive(extendOfExtend, prop, stack);
|
|
522
|
-
delete objectized[prop];
|
|
523
|
-
return stack;
|
|
524
|
-
};
|
|
525
384
|
const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
526
385
|
if (typeof param !== "object" || typeof element !== "object" || param === null || element === null) {
|
|
527
386
|
return param === element;
|
|
@@ -549,51 +408,41 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
549
408
|
return true;
|
|
550
409
|
};
|
|
551
410
|
const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
552
|
-
if (obj1 === obj2)
|
|
553
|
-
|
|
554
|
-
if (
|
|
555
|
-
return false;
|
|
556
|
-
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2))
|
|
557
|
-
return obj1 === obj2;
|
|
558
|
-
const stack = [[obj1, obj2]];
|
|
411
|
+
if (obj1 === obj2) return true;
|
|
412
|
+
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return obj1 === obj2;
|
|
413
|
+
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) return obj1 === obj2;
|
|
559
414
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if ((0, import_node.isDOMNode)(value1) || (0, import_node.isDOMNode)(value2)) {
|
|
575
|
-
if (value1 !== value2)
|
|
576
|
-
return false;
|
|
577
|
-
} else if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) {
|
|
578
|
-
if (value1 !== value2) {
|
|
579
|
-
stack.push([value1, value2]);
|
|
580
|
-
}
|
|
581
|
-
} else if (value1 !== value2) {
|
|
415
|
+
function checkContains(target, source) {
|
|
416
|
+
if (visited.has(source)) return true;
|
|
417
|
+
visited.add(source);
|
|
418
|
+
for (const key in source) {
|
|
419
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
420
|
+
if (ignoredKeys.includes(key)) continue;
|
|
421
|
+
if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
|
|
422
|
+
const sourceValue = source[key];
|
|
423
|
+
const targetValue = target[key];
|
|
424
|
+
if ((0, import_node.isDOMNode)(sourceValue) || (0, import_node.isDOMNode)(targetValue)) {
|
|
425
|
+
if (sourceValue !== targetValue) return false;
|
|
426
|
+
} else if ((0, import_types.isObjectLike)(sourceValue) && (0, import_types.isObjectLike)(targetValue)) {
|
|
427
|
+
if (!checkContains(targetValue, sourceValue)) return false;
|
|
428
|
+
} else if (sourceValue !== targetValue) {
|
|
582
429
|
return false;
|
|
583
430
|
}
|
|
584
431
|
}
|
|
432
|
+
return true;
|
|
585
433
|
}
|
|
586
|
-
return
|
|
434
|
+
return checkContains(obj1, obj2);
|
|
587
435
|
};
|
|
588
436
|
const removeFromObject = (obj, props) => {
|
|
589
|
-
if (props === void 0 || props === null)
|
|
590
|
-
return obj;
|
|
437
|
+
if (props === void 0 || props === null) return obj;
|
|
591
438
|
if ((0, import_types.is)(props)("string", "number")) {
|
|
592
439
|
delete obj[props];
|
|
593
440
|
} else if ((0, import_types.isArray)(props)) {
|
|
594
441
|
props.forEach((prop) => delete obj[prop]);
|
|
595
442
|
} else {
|
|
596
|
-
throw new Error(
|
|
443
|
+
throw new Error(
|
|
444
|
+
"Invalid input: props must be a string or an array of strings"
|
|
445
|
+
);
|
|
597
446
|
}
|
|
598
447
|
return obj;
|
|
599
448
|
};
|
|
@@ -685,7 +534,10 @@ const detectInfiniteLoop = (arr) => {
|
|
|
685
534
|
}
|
|
686
535
|
if (repeatCount >= maxRepeats * 2) {
|
|
687
536
|
if (ENV === "test" || ENV === "development") {
|
|
688
|
-
console.warn(
|
|
537
|
+
console.warn(
|
|
538
|
+
"Warning: Potential infinite loop detected due to repeated sequence:",
|
|
539
|
+
pattern
|
|
540
|
+
);
|
|
689
541
|
}
|
|
690
542
|
return true;
|
|
691
543
|
}
|