@domql/utils 3.1.2 → 3.2.7
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 +11 -5
- package/cache.js +3 -0
- package/component.js +3 -4
- package/dist/cjs/array.js +11 -5
- package/dist/cjs/component.js +4 -6
- package/dist/cjs/element.js +6 -6
- package/dist/cjs/env.js +1 -1
- package/dist/cjs/events.js +3 -3
- package/dist/cjs/extends.js +44 -28
- package/dist/cjs/function.js +3 -3
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/key.js +2 -2
- package/dist/cjs/keys.js +29 -15
- package/dist/cjs/methods.js +88 -33
- package/dist/cjs/object.js +154 -141
- package/dist/cjs/props.js +43 -34
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +12 -11
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +71 -16
- package/dist/cjs/triggerEvent.js +90 -0
- package/dist/cjs/types.js +4 -12
- package/dist/esm/array.js +11 -5
- package/dist/esm/component.js +4 -6
- package/dist/esm/element.js +9 -27
- package/dist/esm/env.js +1 -1
- package/dist/esm/events.js +3 -3
- package/dist/esm/extends.js +48 -50
- package/dist/esm/function.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/key.js +2 -2
- package/dist/esm/keys.js +29 -15
- package/dist/esm/methods.js +86 -31
- package/dist/esm/object.js +158 -165
- package/dist/esm/props.js +43 -50
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +21 -38
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +71 -16
- package/dist/esm/triggerEvent.js +70 -0
- package/dist/esm/types.js +4 -12
- package/dist/iife/index.js +2779 -0
- package/element.js +2 -2
- package/events.js +3 -3
- package/extends.js +28 -17
- package/function.js +10 -9
- package/index.js +1 -0
- package/keys.js +25 -15
- package/log.js +0 -1
- package/methods.js +99 -24
- package/object.js +155 -215
- package/package.json +34 -13
- package/props.js +44 -27
- package/state.js +12 -12
- package/string.js +20 -38
- package/tags.js +45 -16
- package/triggerEvent.js +76 -0
- package/types.js +8 -25
- package/dist/cjs/package.json +0 -4
package/dist/cjs/object.js
CHANGED
|
@@ -29,7 +29,6 @@ __export(object_exports, {
|
|
|
29
29
|
detectInfiniteLoop: () => detectInfiniteLoop,
|
|
30
30
|
excludeKeysFromObject: () => excludeKeysFromObject,
|
|
31
31
|
exec: () => exec,
|
|
32
|
-
execPromise: () => execPromise,
|
|
33
32
|
getInObjectByPath: () => getInObjectByPath,
|
|
34
33
|
hasFunction: () => hasFunction,
|
|
35
34
|
hasOwnProperty: () => hasOwnProperty,
|
|
@@ -56,26 +55,25 @@ var import_array = require("./array.js");
|
|
|
56
55
|
var import_string = require("./string.js");
|
|
57
56
|
var import_node = require("./node.js");
|
|
58
57
|
var import_keys = require("./keys.js");
|
|
59
|
-
const ENV =
|
|
58
|
+
const ENV = process.env.NODE_ENV;
|
|
59
|
+
const _startsWithDunder = (e) => e.charCodeAt(0) === 95 && e.charCodeAt(1) === 95;
|
|
60
60
|
const exec = (param, element, state, context) => {
|
|
61
61
|
if ((0, import_types.isFunction)(param)) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
element,
|
|
65
|
-
state || element.state,
|
|
66
|
-
context || element.context
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return param;
|
|
70
|
-
};
|
|
71
|
-
const execPromise = async (param, element, state, context) => {
|
|
72
|
-
if ((0, import_types.isFunction)(param)) {
|
|
73
|
-
return await param.call(
|
|
62
|
+
if (!element) return;
|
|
63
|
+
const result = param.call(
|
|
74
64
|
element,
|
|
75
65
|
element,
|
|
76
66
|
state || element.state,
|
|
77
67
|
context || element.context
|
|
78
68
|
);
|
|
69
|
+
if (result && typeof result.then === "function") {
|
|
70
|
+
let resolved;
|
|
71
|
+
result.then((value) => {
|
|
72
|
+
resolved = value;
|
|
73
|
+
});
|
|
74
|
+
return resolved;
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
79
77
|
}
|
|
80
78
|
return param;
|
|
81
79
|
};
|
|
@@ -85,25 +83,23 @@ const map = (obj, extention, element) => {
|
|
|
85
83
|
}
|
|
86
84
|
};
|
|
87
85
|
const merge = (element, obj, excludeFrom = []) => {
|
|
86
|
+
const useSet = excludeFrom instanceof Set;
|
|
88
87
|
for (const e in obj) {
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const objProp = obj[e];
|
|
95
|
-
if (elementProp === void 0) {
|
|
96
|
-
element[e] = objProp;
|
|
88
|
+
if (!Object.prototype.hasOwnProperty.call(obj, e)) continue;
|
|
89
|
+
if (_startsWithDunder(e)) continue;
|
|
90
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
91
|
+
if (element[e] === void 0) {
|
|
92
|
+
element[e] = obj[e];
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
return element;
|
|
100
96
|
};
|
|
101
97
|
const deepMerge = (element, extend, excludeFrom = import_keys.METHODS_EXL) => {
|
|
98
|
+
const useSet = excludeFrom instanceof Set;
|
|
102
99
|
for (const e in extend) {
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
}
|
|
100
|
+
if (!Object.prototype.hasOwnProperty.call(extend, e)) continue;
|
|
101
|
+
if (_startsWithDunder(e)) continue;
|
|
102
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
107
103
|
const elementProp = element[e];
|
|
108
104
|
const extendProp = extend[e];
|
|
109
105
|
if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
|
|
@@ -115,12 +111,12 @@ const deepMerge = (element, extend, excludeFrom = import_keys.METHODS_EXL) => {
|
|
|
115
111
|
return element;
|
|
116
112
|
};
|
|
117
113
|
const clone = (obj, excludeFrom = []) => {
|
|
114
|
+
const useSet = excludeFrom instanceof Set;
|
|
118
115
|
const o = {};
|
|
119
116
|
for (const prop in obj) {
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
}
|
|
117
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
|
|
118
|
+
if (_startsWithDunder(prop)) continue;
|
|
119
|
+
if (useSet ? excludeFrom.has(prop) : excludeFrom.includes(prop)) continue;
|
|
124
120
|
o[prop] = obj[prop];
|
|
125
121
|
}
|
|
126
122
|
return o;
|
|
@@ -134,23 +130,24 @@ const deepClone = (obj, options = {}) => {
|
|
|
134
130
|
visited = /* @__PURE__ */ new WeakMap(),
|
|
135
131
|
handleExtends = false
|
|
136
132
|
} = options;
|
|
133
|
+
const contentWindow = targetWindow || import_globals.window || globalThis;
|
|
137
134
|
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
|
|
138
135
|
return obj;
|
|
139
136
|
}
|
|
140
137
|
if (visited.has(obj)) {
|
|
141
138
|
return visited.get(obj);
|
|
142
139
|
}
|
|
143
|
-
const
|
|
140
|
+
const isArr = (0, import_types.isArray)(obj);
|
|
141
|
+
const clone2 = isArr ? [] : {};
|
|
144
142
|
visited.set(obj, clone2);
|
|
143
|
+
const excludeSet = exclude instanceof Set ? exclude : exclude.length > 3 ? new Set(exclude) : null;
|
|
145
144
|
for (const key in obj) {
|
|
146
145
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
}
|
|
146
|
+
if (_startsWithDunder(key) || key === "__proto__") continue;
|
|
147
|
+
if (excludeSet ? excludeSet.has(key) : exclude.includes(key)) continue;
|
|
150
148
|
const value = obj[key];
|
|
151
|
-
if (cleanUndefined &&
|
|
152
|
-
|
|
153
|
-
}
|
|
149
|
+
if (cleanUndefined && value === void 0) continue;
|
|
150
|
+
if (cleanNull && value === null) continue;
|
|
154
151
|
if ((0, import_node.isDOMNode)(value)) {
|
|
155
152
|
clone2[key] = value;
|
|
156
153
|
continue;
|
|
@@ -159,8 +156,8 @@ const deepClone = (obj, options = {}) => {
|
|
|
159
156
|
clone2[key] = (0, import_array.unstackArrayOfObjects)(value, exclude);
|
|
160
157
|
continue;
|
|
161
158
|
}
|
|
162
|
-
if ((0, import_types.isFunction)(value) &&
|
|
163
|
-
clone2[key] =
|
|
159
|
+
if ((0, import_types.isFunction)(value) && options.window) {
|
|
160
|
+
clone2[key] = contentWindow.eval("(" + value.toString() + ")");
|
|
164
161
|
continue;
|
|
165
162
|
}
|
|
166
163
|
if ((0, import_types.isObjectLike)(value)) {
|
|
@@ -175,14 +172,13 @@ const deepClone = (obj, options = {}) => {
|
|
|
175
172
|
return clone2;
|
|
176
173
|
};
|
|
177
174
|
const deepStringify = (obj, stringified = {}) => {
|
|
178
|
-
var _a, _b;
|
|
179
175
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
180
176
|
;
|
|
181
|
-
(obj.__element ||
|
|
177
|
+
(obj.__element || obj.parent?.__element).warn(
|
|
182
178
|
"Trying to clone element or state at",
|
|
183
179
|
obj
|
|
184
180
|
);
|
|
185
|
-
obj =
|
|
181
|
+
obj = obj.parse?.();
|
|
186
182
|
}
|
|
187
183
|
for (const prop in obj) {
|
|
188
184
|
const objProp = obj[prop];
|
|
@@ -192,50 +188,63 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
192
188
|
stringified[prop] = {};
|
|
193
189
|
deepStringify(objProp, stringified[prop]);
|
|
194
190
|
} else if ((0, import_types.isArray)(objProp)) {
|
|
195
|
-
stringified[prop] = [];
|
|
196
|
-
objProp.
|
|
191
|
+
const arr = stringified[prop] = [];
|
|
192
|
+
for (let i = 0; i < objProp.length; i++) {
|
|
193
|
+
const v = objProp[i];
|
|
197
194
|
if ((0, import_types.isObject)(v)) {
|
|
198
|
-
|
|
199
|
-
deepStringify(v,
|
|
195
|
+
arr[i] = {};
|
|
196
|
+
deepStringify(v, arr[i]);
|
|
200
197
|
} else if ((0, import_types.isFunction)(v)) {
|
|
201
|
-
|
|
198
|
+
arr[i] = v.toString();
|
|
202
199
|
} else {
|
|
203
|
-
|
|
200
|
+
arr[i] = v;
|
|
204
201
|
}
|
|
205
|
-
}
|
|
202
|
+
}
|
|
206
203
|
} else {
|
|
207
204
|
stringified[prop] = objProp;
|
|
208
205
|
}
|
|
209
206
|
}
|
|
210
207
|
return stringified;
|
|
211
208
|
};
|
|
209
|
+
const OBJ_TO_STR_SPECIAL_CHARS = /* @__PURE__ */ new Set([
|
|
210
|
+
"&",
|
|
211
|
+
"*",
|
|
212
|
+
"-",
|
|
213
|
+
":",
|
|
214
|
+
"%",
|
|
215
|
+
"{",
|
|
216
|
+
"}",
|
|
217
|
+
">",
|
|
218
|
+
"<",
|
|
219
|
+
"@",
|
|
220
|
+
".",
|
|
221
|
+
"/",
|
|
222
|
+
"!",
|
|
223
|
+
" "
|
|
224
|
+
]);
|
|
212
225
|
const objectToString = (obj = {}, indent = 0) => {
|
|
213
226
|
if (obj === null || typeof obj !== "object") {
|
|
214
227
|
return String(obj);
|
|
215
228
|
}
|
|
216
|
-
|
|
217
|
-
|
|
229
|
+
let hasKeys = false;
|
|
230
|
+
for (const _k in obj) {
|
|
231
|
+
hasKeys = true;
|
|
232
|
+
break;
|
|
218
233
|
}
|
|
234
|
+
if (!hasKeys) return "{}";
|
|
219
235
|
const spaces = " ".repeat(indent);
|
|
220
236
|
let str = "{\n";
|
|
221
|
-
for (const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
"@",
|
|
233
|
-
".",
|
|
234
|
-
"/",
|
|
235
|
-
"!",
|
|
236
|
-
" "
|
|
237
|
-
]);
|
|
238
|
-
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
237
|
+
for (const key in obj) {
|
|
238
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
239
|
+
const value = obj[key];
|
|
240
|
+
let keyNeedsQuotes = false;
|
|
241
|
+
for (let i = 0; i < key.length; i++) {
|
|
242
|
+
if (OBJ_TO_STR_SPECIAL_CHARS.has(key[i])) {
|
|
243
|
+
keyNeedsQuotes = true;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const stringedKey = keyNeedsQuotes ? `'${key}'` : key;
|
|
239
248
|
str += `${spaces} ${stringedKey}: `;
|
|
240
249
|
if ((0, import_types.isArray)(value)) {
|
|
241
250
|
str += "[\n";
|
|
@@ -264,36 +273,36 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
264
273
|
str += `${spaces}}`;
|
|
265
274
|
return str;
|
|
266
275
|
};
|
|
276
|
+
const FN_PATTERNS = [
|
|
277
|
+
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
278
|
+
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
279
|
+
/^function[\s(]/,
|
|
280
|
+
/^async\s+/,
|
|
281
|
+
/^\(\s*function/,
|
|
282
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
283
|
+
];
|
|
284
|
+
const RE_JSON_LIKE = /^["[{]/;
|
|
267
285
|
const hasFunction = (str) => {
|
|
268
286
|
if (!str) return false;
|
|
269
287
|
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
270
|
-
if (trimmed === "") return false;
|
|
271
|
-
|
|
272
|
-
if (
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
280
|
-
];
|
|
281
|
-
const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
|
|
282
|
-
const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
|
|
283
|
-
const isArrayLiteral = trimmed.startsWith("[");
|
|
284
|
-
const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
|
|
285
|
-
return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
|
|
288
|
+
if (trimmed === "" || trimmed === "{}" || trimmed === "[]") return false;
|
|
289
|
+
const isFn = FN_PATTERNS.some((pattern) => pattern.test(trimmed));
|
|
290
|
+
if (!isFn) return false;
|
|
291
|
+
const firstChar = trimmed.charCodeAt(0);
|
|
292
|
+
const hasArrow = trimmed.includes("=>");
|
|
293
|
+
if (firstChar === 123 && !hasArrow) return false;
|
|
294
|
+
if (firstChar === 91) return false;
|
|
295
|
+
if (RE_JSON_LIKE.test(trimmed) && !hasArrow) return false;
|
|
296
|
+
return true;
|
|
286
297
|
};
|
|
287
298
|
const deepDestringify = (obj, destringified = {}) => {
|
|
288
299
|
for (const prop in obj) {
|
|
289
|
-
|
|
290
|
-
if (!hasOwnProperty2) continue;
|
|
300
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
|
|
291
301
|
const objProp = obj[prop];
|
|
292
302
|
if ((0, import_types.isString)(objProp)) {
|
|
293
303
|
if (hasFunction(objProp)) {
|
|
294
304
|
try {
|
|
295
|
-
|
|
296
|
-
destringified[prop] = evalProp;
|
|
305
|
+
destringified[prop] = import_globals.window.eval(`(${objProp})`);
|
|
297
306
|
} catch (e) {
|
|
298
307
|
if (e) destringified[prop] = objProp;
|
|
299
308
|
}
|
|
@@ -301,25 +310,25 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
301
310
|
destringified[prop] = objProp;
|
|
302
311
|
}
|
|
303
312
|
} else if ((0, import_types.isArray)(objProp)) {
|
|
304
|
-
destringified[prop] = [];
|
|
305
|
-
objProp.
|
|
313
|
+
const arr = destringified[prop] = [];
|
|
314
|
+
for (let i = 0; i < objProp.length; i++) {
|
|
315
|
+
const arrProp = objProp[i];
|
|
306
316
|
if ((0, import_types.isString)(arrProp)) {
|
|
307
317
|
if (hasFunction(arrProp)) {
|
|
308
318
|
try {
|
|
309
|
-
|
|
310
|
-
destringified[prop].push(evalProp);
|
|
319
|
+
arr.push(import_globals.window.eval(`(${arrProp})`));
|
|
311
320
|
} catch (e) {
|
|
312
|
-
if (e)
|
|
321
|
+
if (e) arr.push(arrProp);
|
|
313
322
|
}
|
|
314
323
|
} else {
|
|
315
|
-
|
|
324
|
+
arr.push(arrProp);
|
|
316
325
|
}
|
|
317
326
|
} else if ((0, import_types.isObject)(arrProp)) {
|
|
318
|
-
|
|
327
|
+
arr.push(deepDestringify(arrProp));
|
|
319
328
|
} else {
|
|
320
|
-
|
|
329
|
+
arr.push(arrProp);
|
|
321
330
|
}
|
|
322
|
-
}
|
|
331
|
+
}
|
|
323
332
|
} else if ((0, import_types.isObject)(objProp)) {
|
|
324
333
|
destringified[prop] = deepDestringify(objProp, destringified[prop]);
|
|
325
334
|
} else {
|
|
@@ -336,39 +345,44 @@ const stringToObject = (str, opts = { verbose: true }) => {
|
|
|
336
345
|
}
|
|
337
346
|
};
|
|
338
347
|
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
339
|
-
const isEmpty = (o) =>
|
|
348
|
+
const isEmpty = (o) => {
|
|
349
|
+
for (const _ in o) return false;
|
|
350
|
+
return true;
|
|
351
|
+
};
|
|
340
352
|
const isEmptyObject = (o) => (0, import_types.isObject)(o) && isEmpty(o);
|
|
341
353
|
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
342
354
|
const overwrite = (element, params, opts = {}) => {
|
|
343
355
|
const excl = opts.exclude || [];
|
|
344
356
|
const allowUnderscore = opts.preventUnderscore;
|
|
345
357
|
for (const e in params) {
|
|
346
|
-
if (excl.includes(e) || !allowUnderscore && e
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
element[e] = paramsProp;
|
|
358
|
+
if (excl.includes(e) || !allowUnderscore && _startsWithDunder(e)) continue;
|
|
359
|
+
if (params[e] !== void 0) {
|
|
360
|
+
element[e] = params[e];
|
|
350
361
|
}
|
|
351
362
|
}
|
|
352
363
|
return element;
|
|
353
364
|
};
|
|
354
365
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
366
|
+
const useSet = excludeFrom instanceof Set;
|
|
355
367
|
for (const e in params) {
|
|
356
|
-
if (
|
|
368
|
+
if (_startsWithDunder(e)) continue;
|
|
369
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
357
370
|
obj[e] = params[e];
|
|
358
371
|
}
|
|
359
372
|
return obj;
|
|
360
373
|
};
|
|
361
374
|
const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
362
|
-
const excl = opts.exclude || [];
|
|
363
|
-
const forcedExclude = opts.preventForce ? [] : ["node", "window"];
|
|
364
375
|
if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
|
|
365
376
|
return params;
|
|
366
377
|
}
|
|
367
378
|
if (visited.has(obj)) return visited.get(obj);
|
|
368
379
|
visited.set(obj, obj);
|
|
380
|
+
const excl = opts.exclude;
|
|
381
|
+
const exclSet = excl ? excl instanceof Set ? excl : new Set(excl) : null;
|
|
382
|
+
const forcedExclude = !opts.preventForce;
|
|
369
383
|
for (const e in params) {
|
|
370
|
-
if (!Object.hasOwnProperty.call(params, e)) continue;
|
|
371
|
-
if (
|
|
384
|
+
if (!Object.prototype.hasOwnProperty.call(params, e)) continue;
|
|
385
|
+
if (exclSet && exclSet.has(e) || forcedExclude && _startsWithDunder(e)) continue;
|
|
372
386
|
const objProp = obj[e];
|
|
373
387
|
const paramsProp = params[e];
|
|
374
388
|
if ((0, import_node.isDOMNode)(paramsProp)) {
|
|
@@ -395,29 +409,30 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
395
409
|
if (keysParam.length !== keysElement.length) {
|
|
396
410
|
return false;
|
|
397
411
|
}
|
|
398
|
-
for (
|
|
399
|
-
|
|
412
|
+
for (let i = 0; i < keysParam.length; i++) {
|
|
413
|
+
const key = keysParam[i];
|
|
414
|
+
if (!Object.prototype.hasOwnProperty.call(element, key)) {
|
|
400
415
|
return false;
|
|
401
416
|
}
|
|
402
|
-
|
|
403
|
-
const elementProp = element[key];
|
|
404
|
-
if (!isEqualDeep(paramProp, elementProp, visited)) {
|
|
417
|
+
if (!isEqualDeep(param[key], element[key], visited)) {
|
|
405
418
|
return false;
|
|
406
419
|
}
|
|
407
420
|
}
|
|
408
421
|
return true;
|
|
409
422
|
};
|
|
410
|
-
const
|
|
423
|
+
const DEEP_CONTAINS_IGNORED = /* @__PURE__ */ new Set(["node", "__ref"]);
|
|
424
|
+
const deepContains = (obj1, obj2, ignoredKeys = DEEP_CONTAINS_IGNORED) => {
|
|
411
425
|
if (obj1 === obj2) return true;
|
|
412
426
|
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return obj1 === obj2;
|
|
413
427
|
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) return obj1 === obj2;
|
|
428
|
+
const ignored = ignoredKeys instanceof Set ? ignoredKeys : new Set(ignoredKeys);
|
|
414
429
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
415
430
|
function checkContains(target, source) {
|
|
416
431
|
if (visited.has(source)) return true;
|
|
417
432
|
visited.add(source);
|
|
418
433
|
for (const key in source) {
|
|
419
434
|
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
420
|
-
if (
|
|
435
|
+
if (ignored.has(key)) continue;
|
|
421
436
|
if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
|
|
422
437
|
const sourceValue = source[key];
|
|
423
438
|
const targetValue = target[key];
|
|
@@ -438,7 +453,7 @@ const removeFromObject = (obj, props) => {
|
|
|
438
453
|
if ((0, import_types.is)(props)("string", "number")) {
|
|
439
454
|
delete obj[props];
|
|
440
455
|
} else if ((0, import_types.isArray)(props)) {
|
|
441
|
-
props.
|
|
456
|
+
for (let i = 0; i < props.length; i++) delete obj[props[i]];
|
|
442
457
|
} else {
|
|
443
458
|
throw new Error(
|
|
444
459
|
"Invalid input: props must be a string or an array of strings"
|
|
@@ -459,19 +474,17 @@ const createObjectWithoutPrototype = (obj) => {
|
|
|
459
474
|
return newObj;
|
|
460
475
|
};
|
|
461
476
|
const createNestedObject = (arr, lastValue) => {
|
|
477
|
+
if (arr.length === 0) return lastValue;
|
|
462
478
|
const nestedObject = {};
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
if (index === arr.length - 1 && lastValue) {
|
|
471
|
-
obj[value] = lastValue;
|
|
479
|
+
let current = nestedObject;
|
|
480
|
+
for (let i = 0; i < arr.length; i++) {
|
|
481
|
+
if (i === arr.length - 1 && lastValue) {
|
|
482
|
+
current[arr[i]] = lastValue;
|
|
483
|
+
} else {
|
|
484
|
+
current[arr[i]] = {};
|
|
485
|
+
current = current[arr[i]];
|
|
472
486
|
}
|
|
473
|
-
|
|
474
|
-
}, nestedObject);
|
|
487
|
+
}
|
|
475
488
|
return nestedObject;
|
|
476
489
|
};
|
|
477
490
|
const removeNestedKeyByPath = (obj, path) => {
|
|
@@ -480,13 +493,11 @@ const removeNestedKeyByPath = (obj, path) => {
|
|
|
480
493
|
}
|
|
481
494
|
let current = obj;
|
|
482
495
|
for (let i = 0; i < path.length - 1; i++) {
|
|
483
|
-
if (current[path[i]] === void 0)
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
496
|
+
if (current[path[i]] === void 0) return;
|
|
486
497
|
current = current[path[i]];
|
|
487
498
|
}
|
|
488
499
|
const lastKey = path[path.length - 1];
|
|
489
|
-
if (current && Object.hasOwnProperty.call(current, lastKey)) {
|
|
500
|
+
if (current && Object.prototype.hasOwnProperty.call(current, lastKey)) {
|
|
490
501
|
delete current[lastKey];
|
|
491
502
|
}
|
|
492
503
|
};
|
|
@@ -501,8 +512,7 @@ const setInObjectByPath = (obj, path, value) => {
|
|
|
501
512
|
}
|
|
502
513
|
current = current[path[i]];
|
|
503
514
|
}
|
|
504
|
-
|
|
505
|
-
current[lastKey] = value;
|
|
515
|
+
current[path[path.length - 1]] = value;
|
|
506
516
|
return obj;
|
|
507
517
|
};
|
|
508
518
|
const getInObjectByPath = (obj, path) => {
|
|
@@ -545,15 +555,13 @@ const detectInfiniteLoop = (arr) => {
|
|
|
545
555
|
}
|
|
546
556
|
};
|
|
547
557
|
const isCyclic = (obj) => {
|
|
548
|
-
const
|
|
558
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
549
559
|
function detect(obj2) {
|
|
550
560
|
if (obj2 && typeof obj2 === "object") {
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
seenObjects.push(obj2);
|
|
561
|
+
if (seen.has(obj2)) return true;
|
|
562
|
+
seen.add(obj2);
|
|
555
563
|
for (const key in obj2) {
|
|
556
|
-
if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
564
|
+
if (Object.prototype.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
557
565
|
console.log(obj2, "cycle at " + key);
|
|
558
566
|
return true;
|
|
559
567
|
}
|
|
@@ -564,7 +572,12 @@ const isCyclic = (obj) => {
|
|
|
564
572
|
return detect(obj);
|
|
565
573
|
};
|
|
566
574
|
const excludeKeysFromObject = (obj, excludedKeys) => {
|
|
567
|
-
const
|
|
568
|
-
|
|
575
|
+
const excluded = excludedKeys instanceof Set ? excludedKeys : new Set(excludedKeys);
|
|
576
|
+
const result = {};
|
|
577
|
+
for (const key in obj) {
|
|
578
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !excluded.has(key)) {
|
|
579
|
+
result[key] = obj[key];
|
|
580
|
+
}
|
|
581
|
+
}
|
|
569
582
|
return result;
|
|
570
583
|
};
|