@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/esm/object.js
CHANGED
|
@@ -26,12 +26,12 @@ import {
|
|
|
26
26
|
isString,
|
|
27
27
|
is,
|
|
28
28
|
isUndefined,
|
|
29
|
-
isDate,
|
|
30
29
|
isNull
|
|
31
30
|
} from "./types.js";
|
|
32
|
-
import {
|
|
31
|
+
import { unstackArrayOfObjects } from "./array.js";
|
|
33
32
|
import { stringIncludesAny } from "./string.js";
|
|
34
33
|
import { isDOMNode } from "./node.js";
|
|
34
|
+
import { METHODS_EXL } from "./keys.js";
|
|
35
35
|
const ENV = "development";
|
|
36
36
|
const exec = (param, element, state, context) => {
|
|
37
37
|
if (isFunction(param)) {
|
|
@@ -44,6 +44,17 @@ const exec = (param, element, state, context) => {
|
|
|
44
44
|
}
|
|
45
45
|
return param;
|
|
46
46
|
};
|
|
47
|
+
const execPromise = async (param, element, state, context) => {
|
|
48
|
+
if (isFunction(param)) {
|
|
49
|
+
return await param.call(
|
|
50
|
+
element,
|
|
51
|
+
element,
|
|
52
|
+
state || element.state,
|
|
53
|
+
context || element.context
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return param;
|
|
57
|
+
};
|
|
47
58
|
const map = (obj, extention, element) => {
|
|
48
59
|
for (const e in extention) {
|
|
49
60
|
obj[e] = exec(extention[e], element);
|
|
@@ -52,8 +63,9 @@ const map = (obj, extention, element) => {
|
|
|
52
63
|
const merge = (element, obj, excludeFrom = []) => {
|
|
53
64
|
for (const e in obj) {
|
|
54
65
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
|
|
55
|
-
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
66
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
|
|
56
67
|
continue;
|
|
68
|
+
}
|
|
57
69
|
const elementProp = element[e];
|
|
58
70
|
const objProp = obj[e];
|
|
59
71
|
if (elementProp === void 0) {
|
|
@@ -62,11 +74,12 @@ const merge = (element, obj, excludeFrom = []) => {
|
|
|
62
74
|
}
|
|
63
75
|
return element;
|
|
64
76
|
};
|
|
65
|
-
const deepMerge = (element, extend, excludeFrom =
|
|
77
|
+
const deepMerge = (element, extend, excludeFrom = METHODS_EXL) => {
|
|
66
78
|
for (const e in extend) {
|
|
67
79
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
|
|
68
|
-
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
80
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
|
|
69
81
|
continue;
|
|
82
|
+
}
|
|
70
83
|
const elementProp = element[e];
|
|
71
84
|
const extendProp = extend[e];
|
|
72
85
|
if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
|
|
@@ -81,15 +94,13 @@ const clone = (obj, excludeFrom = []) => {
|
|
|
81
94
|
const o = {};
|
|
82
95
|
for (const prop in obj) {
|
|
83
96
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
84
|
-
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
97
|
+
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) {
|
|
85
98
|
continue;
|
|
99
|
+
}
|
|
86
100
|
o[prop] = obj[prop];
|
|
87
101
|
}
|
|
88
102
|
return o;
|
|
89
103
|
};
|
|
90
|
-
const mergeArrayExclude = (arr, exclude = []) => {
|
|
91
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
|
|
92
|
-
};
|
|
93
104
|
const deepClone = (obj, options = {}) => {
|
|
94
105
|
const {
|
|
95
106
|
exclude = [],
|
|
@@ -97,7 +108,7 @@ const deepClone = (obj, options = {}) => {
|
|
|
97
108
|
cleanNull = false,
|
|
98
109
|
window: targetWindow,
|
|
99
110
|
visited = /* @__PURE__ */ new WeakMap(),
|
|
100
|
-
|
|
111
|
+
handleExtends = false
|
|
101
112
|
} = options;
|
|
102
113
|
if (!isObjectLike(obj) || isDOMNode(obj)) {
|
|
103
114
|
return obj;
|
|
@@ -108,19 +119,20 @@ const deepClone = (obj, options = {}) => {
|
|
|
108
119
|
const clone2 = targetWindow ? isArray(obj) ? new targetWindow.Array() : new targetWindow.Object() : isArray(obj) ? [] : {};
|
|
109
120
|
visited.set(obj, clone2);
|
|
110
121
|
for (const key in obj) {
|
|
111
|
-
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
112
|
-
|
|
113
|
-
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
122
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
123
|
+
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") {
|
|
114
124
|
continue;
|
|
125
|
+
}
|
|
115
126
|
const value = obj[key];
|
|
116
|
-
if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value))
|
|
127
|
+
if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value)) {
|
|
117
128
|
continue;
|
|
129
|
+
}
|
|
118
130
|
if (isDOMNode(value)) {
|
|
119
131
|
clone2[key] = value;
|
|
120
132
|
continue;
|
|
121
133
|
}
|
|
122
|
-
if (
|
|
123
|
-
clone2[key] =
|
|
134
|
+
if (handleExtends && key === "extends" && isArray(value)) {
|
|
135
|
+
clone2[key] = unstackArrayOfObjects(value, exclude);
|
|
124
136
|
continue;
|
|
125
137
|
}
|
|
126
138
|
if (isFunction(value) && targetWindow) {
|
|
@@ -140,7 +152,11 @@ const deepClone = (obj, options = {}) => {
|
|
|
140
152
|
const deepStringify = (obj, stringified = {}) => {
|
|
141
153
|
var _a, _b;
|
|
142
154
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
143
|
-
|
|
155
|
+
;
|
|
156
|
+
(obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn(
|
|
157
|
+
"Trying to clone element or state at",
|
|
158
|
+
obj
|
|
159
|
+
);
|
|
144
160
|
obj = (_b = obj.parse) == null ? void 0 : _b.call(obj);
|
|
145
161
|
}
|
|
146
162
|
for (const prop in obj) {
|
|
@@ -168,39 +184,6 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
168
184
|
}
|
|
169
185
|
return stringified;
|
|
170
186
|
};
|
|
171
|
-
const MAX_DEPTH = 100;
|
|
172
|
-
const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
|
|
173
|
-
if (depth > MAX_DEPTH) {
|
|
174
|
-
console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
|
|
175
|
-
return "[MAX_DEPTH_EXCEEDED]";
|
|
176
|
-
}
|
|
177
|
-
for (const prop in obj) {
|
|
178
|
-
const currentPath = path ? `${path}.${prop}` : prop;
|
|
179
|
-
const objProp = obj[prop];
|
|
180
|
-
if (isFunction(objProp)) {
|
|
181
|
-
stringified[prop] = objProp.toString();
|
|
182
|
-
} else if (isObject(objProp)) {
|
|
183
|
-
stringified[prop] = {};
|
|
184
|
-
deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
|
|
185
|
-
} else if (isArray(objProp)) {
|
|
186
|
-
stringified[prop] = [];
|
|
187
|
-
objProp.forEach((v, i) => {
|
|
188
|
-
const itemPath = `${currentPath}[${i}]`;
|
|
189
|
-
if (isObject(v)) {
|
|
190
|
-
stringified[prop][i] = {};
|
|
191
|
-
deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
|
|
192
|
-
} else if (isFunction(v)) {
|
|
193
|
-
stringified[prop][i] = v.toString();
|
|
194
|
-
} else {
|
|
195
|
-
stringified[prop][i] = v;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
stringified[prop] = objProp;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return stringified;
|
|
203
|
-
};
|
|
204
187
|
const objectToString = (obj = {}, indent = 0) => {
|
|
205
188
|
if (obj === null || typeof obj !== "object") {
|
|
206
189
|
return String(obj);
|
|
@@ -211,7 +194,22 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
211
194
|
const spaces = " ".repeat(indent);
|
|
212
195
|
let str = "{\n";
|
|
213
196
|
for (const [key, value] of Object.entries(obj)) {
|
|
214
|
-
const keyNotAllowdChars = stringIncludesAny(key, [
|
|
197
|
+
const keyNotAllowdChars = stringIncludesAny(key, [
|
|
198
|
+
"&",
|
|
199
|
+
"*",
|
|
200
|
+
"-",
|
|
201
|
+
":",
|
|
202
|
+
"%",
|
|
203
|
+
"{",
|
|
204
|
+
"}",
|
|
205
|
+
">",
|
|
206
|
+
"<",
|
|
207
|
+
"@",
|
|
208
|
+
".",
|
|
209
|
+
"/",
|
|
210
|
+
"!",
|
|
211
|
+
" "
|
|
212
|
+
]);
|
|
215
213
|
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
216
214
|
str += `${spaces} ${stringedKey}: `;
|
|
217
215
|
if (isArray(value)) {
|
|
@@ -241,42 +239,12 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
241
239
|
str += `${spaces}}`;
|
|
242
240
|
return str;
|
|
243
241
|
};
|
|
244
|
-
const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
245
|
-
for (const prop in obj) {
|
|
246
|
-
const objProp = obj[prop];
|
|
247
|
-
if (isFunction(objProp))
|
|
248
|
-
continue;
|
|
249
|
-
else if (isObject(objProp)) {
|
|
250
|
-
detached[prop] = {};
|
|
251
|
-
deepStringify(objProp, detached[prop]);
|
|
252
|
-
} else if (isArray(objProp)) {
|
|
253
|
-
detached[prop] = [];
|
|
254
|
-
objProp.forEach((v, i) => {
|
|
255
|
-
if (isFunction(v))
|
|
256
|
-
return;
|
|
257
|
-
if (isObject(v)) {
|
|
258
|
-
detached[prop][i] = {};
|
|
259
|
-
detachFunctionsFromObject(v, detached[prop][i]);
|
|
260
|
-
} else {
|
|
261
|
-
detached[prop][i] = v;
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
detached[prop] = objProp;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return detached;
|
|
269
|
-
};
|
|
270
242
|
const hasFunction = (str) => {
|
|
271
|
-
if (!str)
|
|
272
|
-
return false;
|
|
243
|
+
if (!str) return false;
|
|
273
244
|
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
274
|
-
if (trimmed === "")
|
|
275
|
-
|
|
276
|
-
if (trimmed === "
|
|
277
|
-
return false;
|
|
278
|
-
if (trimmed === "[]")
|
|
279
|
-
return false;
|
|
245
|
+
if (trimmed === "") return false;
|
|
246
|
+
if (trimmed === "{}") return false;
|
|
247
|
+
if (trimmed === "[]") return false;
|
|
280
248
|
const patterns = [
|
|
281
249
|
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
282
250
|
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
@@ -294,8 +262,7 @@ const hasFunction = (str) => {
|
|
|
294
262
|
const deepDestringify = (obj, destringified = {}) => {
|
|
295
263
|
for (const prop in obj) {
|
|
296
264
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
297
|
-
if (!hasOwnProperty2)
|
|
298
|
-
continue;
|
|
265
|
+
if (!hasOwnProperty2) continue;
|
|
299
266
|
const objProp = obj[prop];
|
|
300
267
|
if (isString(objProp)) {
|
|
301
268
|
if (hasFunction(objProp)) {
|
|
@@ -303,8 +270,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
303
270
|
const evalProp = window.eval(`(${objProp})`);
|
|
304
271
|
destringified[prop] = evalProp;
|
|
305
272
|
} catch (e) {
|
|
306
|
-
if (e)
|
|
307
|
-
destringified[prop] = objProp;
|
|
273
|
+
if (e) destringified[prop] = objProp;
|
|
308
274
|
}
|
|
309
275
|
} else {
|
|
310
276
|
destringified[prop] = objProp;
|
|
@@ -318,8 +284,7 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
318
284
|
const evalProp = window.eval(`(${arrProp})`);
|
|
319
285
|
destringified[prop].push(evalProp);
|
|
320
286
|
} catch (e) {
|
|
321
|
-
if (e)
|
|
322
|
-
destringified[prop].push(arrProp);
|
|
287
|
+
if (e) destringified[prop].push(arrProp);
|
|
323
288
|
}
|
|
324
289
|
} else {
|
|
325
290
|
destringified[prop].push(arrProp);
|
|
@@ -342,110 +307,28 @@ const stringToObject = (str, opts = { verbose: true }) => {
|
|
|
342
307
|
try {
|
|
343
308
|
return str ? window.eval("(" + str + ")") : {};
|
|
344
309
|
} catch (e) {
|
|
345
|
-
if (opts.verbose)
|
|
346
|
-
console.warn(e);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
const diffObjects = (original, objToDiff, cache) => {
|
|
350
|
-
for (const e in objToDiff) {
|
|
351
|
-
if (e === "ref")
|
|
352
|
-
continue;
|
|
353
|
-
const originalProp = original[e];
|
|
354
|
-
const objToDiffProp = objToDiff[e];
|
|
355
|
-
if (isObject(originalProp) && isObject(objToDiffProp)) {
|
|
356
|
-
cache[e] = {};
|
|
357
|
-
diff(originalProp, objToDiffProp, cache[e]);
|
|
358
|
-
} else if (objToDiffProp !== void 0) {
|
|
359
|
-
cache[e] = objToDiffProp;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return cache;
|
|
363
|
-
};
|
|
364
|
-
const diffArrays = (original, objToDiff, cache) => {
|
|
365
|
-
if (original.length !== objToDiff.length) {
|
|
366
|
-
cache = objToDiff;
|
|
367
|
-
} else {
|
|
368
|
-
const diffArr = [];
|
|
369
|
-
for (let i = 0; i < original.length; i++) {
|
|
370
|
-
const diffObj = diff(original[i], objToDiff[i]);
|
|
371
|
-
if (Object.keys(diffObj).length > 0) {
|
|
372
|
-
diffArr.push(diffObj);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (diffArr.length > 0) {
|
|
376
|
-
cache = diffArr;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return cache;
|
|
380
|
-
};
|
|
381
|
-
const diff = (original, objToDiff, cache = {}) => {
|
|
382
|
-
if (isArray(original) && isArray(objToDiff)) {
|
|
383
|
-
cache = [];
|
|
384
|
-
diffArrays(original, objToDiff, cache);
|
|
385
|
-
} else {
|
|
386
|
-
diffObjects(original, objToDiff, cache);
|
|
310
|
+
if (opts.verbose) console.warn(e);
|
|
387
311
|
}
|
|
388
|
-
return cache;
|
|
389
312
|
};
|
|
390
313
|
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
391
314
|
const isEmpty = (o) => Object.keys(o).length === 0;
|
|
392
315
|
const isEmptyObject = (o) => isObject(o) && isEmpty(o);
|
|
393
316
|
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
394
|
-
const deepDiff = (lhs, rhs) => {
|
|
395
|
-
if (lhs === rhs)
|
|
396
|
-
return {};
|
|
397
|
-
if (!isObjectLike(lhs) || !isObjectLike(rhs))
|
|
398
|
-
return rhs;
|
|
399
|
-
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
400
|
-
if (!hasOwnProperty(rhs, key)) {
|
|
401
|
-
acc[key] = void 0;
|
|
402
|
-
}
|
|
403
|
-
return acc;
|
|
404
|
-
}, makeObjectWithoutPrototype());
|
|
405
|
-
if (isDate(lhs) || isDate(rhs)) {
|
|
406
|
-
if (lhs.valueOf() === rhs.valueOf())
|
|
407
|
-
return {};
|
|
408
|
-
return rhs;
|
|
409
|
-
}
|
|
410
|
-
return Object.keys(rhs).reduce((acc, key) => {
|
|
411
|
-
if (!hasOwnProperty(lhs, key)) {
|
|
412
|
-
acc[key] = rhs[key];
|
|
413
|
-
return acc;
|
|
414
|
-
}
|
|
415
|
-
const difference = diff(lhs[key], rhs[key]);
|
|
416
|
-
if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
|
|
417
|
-
return acc;
|
|
418
|
-
}
|
|
419
|
-
acc[key] = difference;
|
|
420
|
-
return acc;
|
|
421
|
-
}, deletedValues);
|
|
422
|
-
};
|
|
423
317
|
const overwrite = (element, params, opts = {}) => {
|
|
424
|
-
const { __ref: ref } = element;
|
|
425
318
|
const excl = opts.exclude || [];
|
|
426
319
|
const allowUnderscore = opts.preventUnderscore;
|
|
427
|
-
const preventCaching = opts.preventCaching;
|
|
428
320
|
for (const e in params) {
|
|
429
|
-
if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
|
|
430
|
-
continue;
|
|
431
|
-
const elementProp = element[e];
|
|
321
|
+
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue;
|
|
432
322
|
const paramsProp = params[e];
|
|
433
323
|
if (paramsProp !== void 0) {
|
|
434
324
|
element[e] = paramsProp;
|
|
435
|
-
if (ref && !preventCaching) {
|
|
436
|
-
ref.__cache[e] = elementProp;
|
|
437
|
-
}
|
|
438
|
-
if (isObject(opts.diff)) {
|
|
439
|
-
diff[e] = elementProp;
|
|
440
|
-
}
|
|
441
325
|
}
|
|
442
326
|
}
|
|
443
327
|
return element;
|
|
444
328
|
};
|
|
445
329
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
446
330
|
for (const e in params) {
|
|
447
|
-
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
448
|
-
continue;
|
|
331
|
+
if (excludeFrom.includes(e) || e.startsWith("__")) continue;
|
|
449
332
|
obj[e] = params[e];
|
|
450
333
|
}
|
|
451
334
|
return obj;
|
|
@@ -456,14 +339,11 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
|
|
|
456
339
|
if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
|
|
457
340
|
return params;
|
|
458
341
|
}
|
|
459
|
-
if (visited.has(obj))
|
|
460
|
-
return visited.get(obj);
|
|
342
|
+
if (visited.has(obj)) return visited.get(obj);
|
|
461
343
|
visited.set(obj, obj);
|
|
462
344
|
for (const e in params) {
|
|
463
|
-
if (!Object.hasOwnProperty.call(params, e))
|
|
464
|
-
|
|
465
|
-
if (excl.includes(e) || forcedExclude && e.startsWith("__"))
|
|
466
|
-
continue;
|
|
345
|
+
if (!Object.hasOwnProperty.call(params, e)) continue;
|
|
346
|
+
if (excl.includes(e) || forcedExclude && e.startsWith("__")) continue;
|
|
467
347
|
const objProp = obj[e];
|
|
468
348
|
const paramsProp = params[e];
|
|
469
349
|
if (isDOMNode(paramsProp)) {
|
|
@@ -476,20 +356,6 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
|
|
|
476
356
|
}
|
|
477
357
|
return obj;
|
|
478
358
|
};
|
|
479
|
-
const mergeIfExisted = (a, b) => {
|
|
480
|
-
if (isObjectLike(a) && isObjectLike(b))
|
|
481
|
-
return deepMerge(a, b);
|
|
482
|
-
return a || b;
|
|
483
|
-
};
|
|
484
|
-
const flattenRecursive = (param, prop, stack = []) => {
|
|
485
|
-
const objectized = mergeAndCloneIfArray(param);
|
|
486
|
-
stack.push(objectized);
|
|
487
|
-
const extendOfExtend = objectized[prop];
|
|
488
|
-
if (extendOfExtend)
|
|
489
|
-
flattenRecursive(extendOfExtend, prop, stack);
|
|
490
|
-
delete objectized[prop];
|
|
491
|
-
return stack;
|
|
492
|
-
};
|
|
493
359
|
const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
494
360
|
if (typeof param !== "object" || typeof element !== "object" || param === null || element === null) {
|
|
495
361
|
return param === element;
|
|
@@ -517,51 +383,41 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
517
383
|
return true;
|
|
518
384
|
};
|
|
519
385
|
const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
520
|
-
if (obj1 === obj2)
|
|
521
|
-
|
|
522
|
-
if (
|
|
523
|
-
return false;
|
|
524
|
-
if (isDOMNode(obj1) || isDOMNode(obj2))
|
|
525
|
-
return obj1 === obj2;
|
|
526
|
-
const stack = [[obj1, obj2]];
|
|
386
|
+
if (obj1 === obj2) return true;
|
|
387
|
+
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return obj1 === obj2;
|
|
388
|
+
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2;
|
|
527
389
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (isDOMNode(value1) || isDOMNode(value2)) {
|
|
543
|
-
if (value1 !== value2)
|
|
544
|
-
return false;
|
|
545
|
-
} else if (isObjectLike(value1) && isObjectLike(value2)) {
|
|
546
|
-
if (value1 !== value2) {
|
|
547
|
-
stack.push([value1, value2]);
|
|
548
|
-
}
|
|
549
|
-
} else if (value1 !== value2) {
|
|
390
|
+
function checkContains(target, source) {
|
|
391
|
+
if (visited.has(source)) return true;
|
|
392
|
+
visited.add(source);
|
|
393
|
+
for (const key in source) {
|
|
394
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
395
|
+
if (ignoredKeys.includes(key)) continue;
|
|
396
|
+
if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
|
|
397
|
+
const sourceValue = source[key];
|
|
398
|
+
const targetValue = target[key];
|
|
399
|
+
if (isDOMNode(sourceValue) || isDOMNode(targetValue)) {
|
|
400
|
+
if (sourceValue !== targetValue) return false;
|
|
401
|
+
} else if (isObjectLike(sourceValue) && isObjectLike(targetValue)) {
|
|
402
|
+
if (!checkContains(targetValue, sourceValue)) return false;
|
|
403
|
+
} else if (sourceValue !== targetValue) {
|
|
550
404
|
return false;
|
|
551
405
|
}
|
|
552
406
|
}
|
|
407
|
+
return true;
|
|
553
408
|
}
|
|
554
|
-
return
|
|
409
|
+
return checkContains(obj1, obj2);
|
|
555
410
|
};
|
|
556
411
|
const removeFromObject = (obj, props) => {
|
|
557
|
-
if (props === void 0 || props === null)
|
|
558
|
-
return obj;
|
|
412
|
+
if (props === void 0 || props === null) return obj;
|
|
559
413
|
if (is(props)("string", "number")) {
|
|
560
414
|
delete obj[props];
|
|
561
415
|
} else if (isArray(props)) {
|
|
562
416
|
props.forEach((prop) => delete obj[prop]);
|
|
563
417
|
} else {
|
|
564
|
-
throw new Error(
|
|
418
|
+
throw new Error(
|
|
419
|
+
"Invalid input: props must be a string or an array of strings"
|
|
420
|
+
);
|
|
565
421
|
}
|
|
566
422
|
return obj;
|
|
567
423
|
};
|
|
@@ -653,7 +509,10 @@ const detectInfiniteLoop = (arr) => {
|
|
|
653
509
|
}
|
|
654
510
|
if (repeatCount >= maxRepeats * 2) {
|
|
655
511
|
if (ENV === "test" || ENV === "development") {
|
|
656
|
-
console.warn(
|
|
512
|
+
console.warn(
|
|
513
|
+
"Warning: Potential infinite loop detected due to repeated sequence:",
|
|
514
|
+
pattern
|
|
515
|
+
);
|
|
657
516
|
}
|
|
658
517
|
return true;
|
|
659
518
|
}
|
|
@@ -691,18 +550,12 @@ export {
|
|
|
691
550
|
deepClone,
|
|
692
551
|
deepContains,
|
|
693
552
|
deepDestringify,
|
|
694
|
-
deepDiff,
|
|
695
553
|
deepMerge,
|
|
696
554
|
deepStringify,
|
|
697
|
-
deepStringifyWithMaxDepth,
|
|
698
|
-
detachFunctionsFromObject,
|
|
699
555
|
detectInfiniteLoop,
|
|
700
|
-
diff,
|
|
701
|
-
diffArrays,
|
|
702
|
-
diffObjects,
|
|
703
556
|
excludeKeysFromObject,
|
|
704
557
|
exec,
|
|
705
|
-
|
|
558
|
+
execPromise,
|
|
706
559
|
getInObjectByPath,
|
|
707
560
|
hasFunction,
|
|
708
561
|
hasOwnProperty,
|
|
@@ -713,8 +566,6 @@ export {
|
|
|
713
566
|
makeObjectWithoutPrototype,
|
|
714
567
|
map,
|
|
715
568
|
merge,
|
|
716
|
-
mergeArrayExclude,
|
|
717
|
-
mergeIfExisted,
|
|
718
569
|
objectToString,
|
|
719
570
|
overwrite,
|
|
720
571
|
overwriteDeep,
|