@domql/utils 3.2.3 → 3.2.10
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 +5 -5
- package/dist/cjs/extends.js +43 -27
- 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 +30 -16
- package/dist/cjs/methods.js +64 -28
- package/dist/cjs/object.js +141 -125
- package/dist/cjs/props.js +41 -32
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +9 -8
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +69 -4
- 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 +8 -26
- package/dist/esm/extends.js +47 -49
- 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 +30 -16
- package/dist/esm/methods.js +63 -42
- package/dist/esm/object.js +145 -149
- package/dist/esm/props.js +41 -48
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +17 -34
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +69 -4
- 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/extends.js +28 -17
- package/function.js +4 -6
- package/index.js +1 -0
- package/keys.js +26 -16
- package/methods.js +63 -18
- package/object.js +142 -200
- package/package.json +33 -12
- package/props.js +42 -25
- package/state.js +7 -7
- package/string.js +20 -38
- package/tags.js +43 -4
- package/triggerEvent.js +76 -0
- package/types.js +4 -23
- package/dist/cjs/package.json +0 -4
package/dist/esm/object.js
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
1
|
import { window } from "./globals.js";
|
|
21
2
|
import {
|
|
22
3
|
isFunction,
|
|
@@ -24,17 +5,17 @@ import {
|
|
|
24
5
|
isObject,
|
|
25
6
|
isArray,
|
|
26
7
|
isString,
|
|
27
|
-
is
|
|
28
|
-
isUndefined,
|
|
29
|
-
isNull
|
|
8
|
+
is
|
|
30
9
|
} from "./types.js";
|
|
31
10
|
import { unstackArrayOfObjects } from "./array.js";
|
|
32
11
|
import { stringIncludesAny } from "./string.js";
|
|
33
12
|
import { isDOMNode } from "./node.js";
|
|
34
13
|
import { METHODS_EXL } from "./keys.js";
|
|
35
14
|
const ENV = process.env.NODE_ENV;
|
|
15
|
+
const _startsWithDunder = (e) => e.charCodeAt(0) === 95 && e.charCodeAt(1) === 95;
|
|
36
16
|
const exec = (param, element, state, context) => {
|
|
37
17
|
if (isFunction(param)) {
|
|
18
|
+
if (!element) return;
|
|
38
19
|
const result = param.call(
|
|
39
20
|
element,
|
|
40
21
|
element,
|
|
@@ -58,25 +39,23 @@ const map = (obj, extention, element) => {
|
|
|
58
39
|
}
|
|
59
40
|
};
|
|
60
41
|
const merge = (element, obj, excludeFrom = []) => {
|
|
42
|
+
const useSet = excludeFrom instanceof Set;
|
|
61
43
|
for (const e in obj) {
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const objProp = obj[e];
|
|
68
|
-
if (elementProp === void 0) {
|
|
69
|
-
element[e] = objProp;
|
|
44
|
+
if (!Object.prototype.hasOwnProperty.call(obj, e)) continue;
|
|
45
|
+
if (_startsWithDunder(e)) continue;
|
|
46
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
47
|
+
if (element[e] === void 0) {
|
|
48
|
+
element[e] = obj[e];
|
|
70
49
|
}
|
|
71
50
|
}
|
|
72
51
|
return element;
|
|
73
52
|
};
|
|
74
53
|
const deepMerge = (element, extend, excludeFrom = METHODS_EXL) => {
|
|
54
|
+
const useSet = excludeFrom instanceof Set;
|
|
75
55
|
for (const e in extend) {
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
}
|
|
56
|
+
if (!Object.prototype.hasOwnProperty.call(extend, e)) continue;
|
|
57
|
+
if (_startsWithDunder(e)) continue;
|
|
58
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
80
59
|
const elementProp = element[e];
|
|
81
60
|
const extendProp = extend[e];
|
|
82
61
|
if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
|
|
@@ -88,12 +67,12 @@ const deepMerge = (element, extend, excludeFrom = METHODS_EXL) => {
|
|
|
88
67
|
return element;
|
|
89
68
|
};
|
|
90
69
|
const clone = (obj, excludeFrom = []) => {
|
|
70
|
+
const useSet = excludeFrom instanceof Set;
|
|
91
71
|
const o = {};
|
|
92
72
|
for (const prop in obj) {
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
}
|
|
73
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
|
|
74
|
+
if (_startsWithDunder(prop)) continue;
|
|
75
|
+
if (useSet ? excludeFrom.has(prop) : excludeFrom.includes(prop)) continue;
|
|
97
76
|
o[prop] = obj[prop];
|
|
98
77
|
}
|
|
99
78
|
return o;
|
|
@@ -114,17 +93,17 @@ const deepClone = (obj, options = {}) => {
|
|
|
114
93
|
if (visited.has(obj)) {
|
|
115
94
|
return visited.get(obj);
|
|
116
95
|
}
|
|
117
|
-
const
|
|
96
|
+
const isArr = isArray(obj);
|
|
97
|
+
const clone2 = isArr ? [] : {};
|
|
118
98
|
visited.set(obj, clone2);
|
|
99
|
+
const excludeSet = exclude instanceof Set ? exclude : exclude.length > 3 ? new Set(exclude) : null;
|
|
119
100
|
for (const key in obj) {
|
|
120
101
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
}
|
|
102
|
+
if (_startsWithDunder(key) || key === "__proto__") continue;
|
|
103
|
+
if (excludeSet ? excludeSet.has(key) : exclude.includes(key)) continue;
|
|
124
104
|
const value = obj[key];
|
|
125
|
-
if (cleanUndefined &&
|
|
126
|
-
|
|
127
|
-
}
|
|
105
|
+
if (cleanUndefined && value === void 0) continue;
|
|
106
|
+
if (cleanNull && value === null) continue;
|
|
128
107
|
if (isDOMNode(value)) {
|
|
129
108
|
clone2[key] = value;
|
|
130
109
|
continue;
|
|
@@ -138,9 +117,10 @@ const deepClone = (obj, options = {}) => {
|
|
|
138
117
|
continue;
|
|
139
118
|
}
|
|
140
119
|
if (isObjectLike(value)) {
|
|
141
|
-
clone2[key] = deepClone(value,
|
|
120
|
+
clone2[key] = deepClone(value, {
|
|
121
|
+
...options,
|
|
142
122
|
visited
|
|
143
|
-
})
|
|
123
|
+
});
|
|
144
124
|
} else {
|
|
145
125
|
clone2[key] = value;
|
|
146
126
|
}
|
|
@@ -148,14 +128,13 @@ const deepClone = (obj, options = {}) => {
|
|
|
148
128
|
return clone2;
|
|
149
129
|
};
|
|
150
130
|
const deepStringify = (obj, stringified = {}) => {
|
|
151
|
-
var _a, _b;
|
|
152
131
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
153
132
|
;
|
|
154
|
-
(obj.__element ||
|
|
133
|
+
(obj.__element || obj.parent?.__element).warn(
|
|
155
134
|
"Trying to clone element or state at",
|
|
156
135
|
obj
|
|
157
136
|
);
|
|
158
|
-
obj =
|
|
137
|
+
obj = obj.parse?.();
|
|
159
138
|
}
|
|
160
139
|
for (const prop in obj) {
|
|
161
140
|
const objProp = obj[prop];
|
|
@@ -165,50 +144,63 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
165
144
|
stringified[prop] = {};
|
|
166
145
|
deepStringify(objProp, stringified[prop]);
|
|
167
146
|
} else if (isArray(objProp)) {
|
|
168
|
-
stringified[prop] = [];
|
|
169
|
-
objProp.
|
|
147
|
+
const arr = stringified[prop] = [];
|
|
148
|
+
for (let i = 0; i < objProp.length; i++) {
|
|
149
|
+
const v = objProp[i];
|
|
170
150
|
if (isObject(v)) {
|
|
171
|
-
|
|
172
|
-
deepStringify(v,
|
|
151
|
+
arr[i] = {};
|
|
152
|
+
deepStringify(v, arr[i]);
|
|
173
153
|
} else if (isFunction(v)) {
|
|
174
|
-
|
|
154
|
+
arr[i] = v.toString();
|
|
175
155
|
} else {
|
|
176
|
-
|
|
156
|
+
arr[i] = v;
|
|
177
157
|
}
|
|
178
|
-
}
|
|
158
|
+
}
|
|
179
159
|
} else {
|
|
180
160
|
stringified[prop] = objProp;
|
|
181
161
|
}
|
|
182
162
|
}
|
|
183
163
|
return stringified;
|
|
184
164
|
};
|
|
165
|
+
const OBJ_TO_STR_SPECIAL_CHARS = /* @__PURE__ */ new Set([
|
|
166
|
+
"&",
|
|
167
|
+
"*",
|
|
168
|
+
"-",
|
|
169
|
+
":",
|
|
170
|
+
"%",
|
|
171
|
+
"{",
|
|
172
|
+
"}",
|
|
173
|
+
">",
|
|
174
|
+
"<",
|
|
175
|
+
"@",
|
|
176
|
+
".",
|
|
177
|
+
"/",
|
|
178
|
+
"!",
|
|
179
|
+
" "
|
|
180
|
+
]);
|
|
185
181
|
const objectToString = (obj = {}, indent = 0) => {
|
|
186
182
|
if (obj === null || typeof obj !== "object") {
|
|
187
183
|
return String(obj);
|
|
188
184
|
}
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
let hasKeys = false;
|
|
186
|
+
for (const _k in obj) {
|
|
187
|
+
hasKeys = true;
|
|
188
|
+
break;
|
|
191
189
|
}
|
|
190
|
+
if (!hasKeys) return "{}";
|
|
192
191
|
const spaces = " ".repeat(indent);
|
|
193
192
|
let str = "{\n";
|
|
194
|
-
for (const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"@",
|
|
206
|
-
".",
|
|
207
|
-
"/",
|
|
208
|
-
"!",
|
|
209
|
-
" "
|
|
210
|
-
]);
|
|
211
|
-
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
193
|
+
for (const key in obj) {
|
|
194
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
195
|
+
const value = obj[key];
|
|
196
|
+
let keyNeedsQuotes = false;
|
|
197
|
+
for (let i = 0; i < key.length; i++) {
|
|
198
|
+
if (OBJ_TO_STR_SPECIAL_CHARS.has(key[i])) {
|
|
199
|
+
keyNeedsQuotes = true;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const stringedKey = keyNeedsQuotes ? `'${key}'` : key;
|
|
212
204
|
str += `${spaces} ${stringedKey}: `;
|
|
213
205
|
if (isArray(value)) {
|
|
214
206
|
str += "[\n";
|
|
@@ -237,36 +229,36 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
237
229
|
str += `${spaces}}`;
|
|
238
230
|
return str;
|
|
239
231
|
};
|
|
232
|
+
const FN_PATTERNS = [
|
|
233
|
+
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
234
|
+
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
235
|
+
/^function[\s(]/,
|
|
236
|
+
/^async\s+/,
|
|
237
|
+
/^\(\s*function/,
|
|
238
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
239
|
+
];
|
|
240
|
+
const RE_JSON_LIKE = /^["[{]/;
|
|
240
241
|
const hasFunction = (str) => {
|
|
241
242
|
if (!str) return false;
|
|
242
243
|
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
243
|
-
if (trimmed === "") return false;
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
253
|
-
];
|
|
254
|
-
const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
|
|
255
|
-
const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
|
|
256
|
-
const isArrayLiteral = trimmed.startsWith("[");
|
|
257
|
-
const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
|
|
258
|
-
return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
|
|
244
|
+
if (trimmed === "" || trimmed === "{}" || trimmed === "[]") return false;
|
|
245
|
+
const isFn = FN_PATTERNS.some((pattern) => pattern.test(trimmed));
|
|
246
|
+
if (!isFn) return false;
|
|
247
|
+
const firstChar = trimmed.charCodeAt(0);
|
|
248
|
+
const hasArrow = trimmed.includes("=>");
|
|
249
|
+
if (firstChar === 123 && !hasArrow) return false;
|
|
250
|
+
if (firstChar === 91) return false;
|
|
251
|
+
if (RE_JSON_LIKE.test(trimmed) && !hasArrow) return false;
|
|
252
|
+
return true;
|
|
259
253
|
};
|
|
260
254
|
const deepDestringify = (obj, destringified = {}) => {
|
|
261
255
|
for (const prop in obj) {
|
|
262
|
-
|
|
263
|
-
if (!hasOwnProperty2) continue;
|
|
256
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
|
|
264
257
|
const objProp = obj[prop];
|
|
265
258
|
if (isString(objProp)) {
|
|
266
259
|
if (hasFunction(objProp)) {
|
|
267
260
|
try {
|
|
268
|
-
|
|
269
|
-
destringified[prop] = evalProp;
|
|
261
|
+
destringified[prop] = window.eval(`(${objProp})`);
|
|
270
262
|
} catch (e) {
|
|
271
263
|
if (e) destringified[prop] = objProp;
|
|
272
264
|
}
|
|
@@ -274,25 +266,25 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
274
266
|
destringified[prop] = objProp;
|
|
275
267
|
}
|
|
276
268
|
} else if (isArray(objProp)) {
|
|
277
|
-
destringified[prop] = [];
|
|
278
|
-
objProp.
|
|
269
|
+
const arr = destringified[prop] = [];
|
|
270
|
+
for (let i = 0; i < objProp.length; i++) {
|
|
271
|
+
const arrProp = objProp[i];
|
|
279
272
|
if (isString(arrProp)) {
|
|
280
273
|
if (hasFunction(arrProp)) {
|
|
281
274
|
try {
|
|
282
|
-
|
|
283
|
-
destringified[prop].push(evalProp);
|
|
275
|
+
arr.push(window.eval(`(${arrProp})`));
|
|
284
276
|
} catch (e) {
|
|
285
|
-
if (e)
|
|
277
|
+
if (e) arr.push(arrProp);
|
|
286
278
|
}
|
|
287
279
|
} else {
|
|
288
|
-
|
|
280
|
+
arr.push(arrProp);
|
|
289
281
|
}
|
|
290
282
|
} else if (isObject(arrProp)) {
|
|
291
|
-
|
|
283
|
+
arr.push(deepDestringify(arrProp));
|
|
292
284
|
} else {
|
|
293
|
-
|
|
285
|
+
arr.push(arrProp);
|
|
294
286
|
}
|
|
295
|
-
}
|
|
287
|
+
}
|
|
296
288
|
} else if (isObject(objProp)) {
|
|
297
289
|
destringified[prop] = deepDestringify(objProp, destringified[prop]);
|
|
298
290
|
} else {
|
|
@@ -309,39 +301,44 @@ const stringToObject = (str, opts = { verbose: true }) => {
|
|
|
309
301
|
}
|
|
310
302
|
};
|
|
311
303
|
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
312
|
-
const isEmpty = (o) =>
|
|
304
|
+
const isEmpty = (o) => {
|
|
305
|
+
for (const _ in o) return false;
|
|
306
|
+
return true;
|
|
307
|
+
};
|
|
313
308
|
const isEmptyObject = (o) => isObject(o) && isEmpty(o);
|
|
314
309
|
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
315
310
|
const overwrite = (element, params, opts = {}) => {
|
|
316
311
|
const excl = opts.exclude || [];
|
|
317
312
|
const allowUnderscore = opts.preventUnderscore;
|
|
318
313
|
for (const e in params) {
|
|
319
|
-
if (excl.includes(e) || !allowUnderscore && e
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
element[e] = paramsProp;
|
|
314
|
+
if (excl.includes(e) || !allowUnderscore && _startsWithDunder(e)) continue;
|
|
315
|
+
if (params[e] !== void 0) {
|
|
316
|
+
element[e] = params[e];
|
|
323
317
|
}
|
|
324
318
|
}
|
|
325
319
|
return element;
|
|
326
320
|
};
|
|
327
321
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
322
|
+
const useSet = excludeFrom instanceof Set;
|
|
328
323
|
for (const e in params) {
|
|
329
|
-
if (
|
|
324
|
+
if (_startsWithDunder(e)) continue;
|
|
325
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
330
326
|
obj[e] = params[e];
|
|
331
327
|
}
|
|
332
328
|
return obj;
|
|
333
329
|
};
|
|
334
330
|
const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
335
|
-
const excl = opts.exclude || [];
|
|
336
|
-
const forcedExclude = opts.preventForce ? [] : ["node", "window"];
|
|
337
331
|
if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
|
|
338
332
|
return params;
|
|
339
333
|
}
|
|
340
334
|
if (visited.has(obj)) return visited.get(obj);
|
|
341
335
|
visited.set(obj, obj);
|
|
336
|
+
const excl = opts.exclude;
|
|
337
|
+
const exclSet = excl ? excl instanceof Set ? excl : new Set(excl) : null;
|
|
338
|
+
const forcedExclude = !opts.preventForce;
|
|
342
339
|
for (const e in params) {
|
|
343
|
-
if (!Object.hasOwnProperty.call(params, e)) continue;
|
|
344
|
-
if (
|
|
340
|
+
if (!Object.prototype.hasOwnProperty.call(params, e)) continue;
|
|
341
|
+
if (exclSet && exclSet.has(e) || forcedExclude && _startsWithDunder(e)) continue;
|
|
345
342
|
const objProp = obj[e];
|
|
346
343
|
const paramsProp = params[e];
|
|
347
344
|
if (isDOMNode(paramsProp)) {
|
|
@@ -368,29 +365,30 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
368
365
|
if (keysParam.length !== keysElement.length) {
|
|
369
366
|
return false;
|
|
370
367
|
}
|
|
371
|
-
for (
|
|
372
|
-
|
|
368
|
+
for (let i = 0; i < keysParam.length; i++) {
|
|
369
|
+
const key = keysParam[i];
|
|
370
|
+
if (!Object.prototype.hasOwnProperty.call(element, key)) {
|
|
373
371
|
return false;
|
|
374
372
|
}
|
|
375
|
-
|
|
376
|
-
const elementProp = element[key];
|
|
377
|
-
if (!isEqualDeep(paramProp, elementProp, visited)) {
|
|
373
|
+
if (!isEqualDeep(param[key], element[key], visited)) {
|
|
378
374
|
return false;
|
|
379
375
|
}
|
|
380
376
|
}
|
|
381
377
|
return true;
|
|
382
378
|
};
|
|
383
|
-
const
|
|
379
|
+
const DEEP_CONTAINS_IGNORED = /* @__PURE__ */ new Set(["node", "__ref"]);
|
|
380
|
+
const deepContains = (obj1, obj2, ignoredKeys = DEEP_CONTAINS_IGNORED) => {
|
|
384
381
|
if (obj1 === obj2) return true;
|
|
385
382
|
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return obj1 === obj2;
|
|
386
383
|
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2;
|
|
384
|
+
const ignored = ignoredKeys instanceof Set ? ignoredKeys : new Set(ignoredKeys);
|
|
387
385
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
388
386
|
function checkContains(target, source) {
|
|
389
387
|
if (visited.has(source)) return true;
|
|
390
388
|
visited.add(source);
|
|
391
389
|
for (const key in source) {
|
|
392
390
|
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
393
|
-
if (
|
|
391
|
+
if (ignored.has(key)) continue;
|
|
394
392
|
if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
|
|
395
393
|
const sourceValue = source[key];
|
|
396
394
|
const targetValue = target[key];
|
|
@@ -411,7 +409,7 @@ const removeFromObject = (obj, props) => {
|
|
|
411
409
|
if (is(props)("string", "number")) {
|
|
412
410
|
delete obj[props];
|
|
413
411
|
} else if (isArray(props)) {
|
|
414
|
-
props.
|
|
412
|
+
for (let i = 0; i < props.length; i++) delete obj[props[i]];
|
|
415
413
|
} else {
|
|
416
414
|
throw new Error(
|
|
417
415
|
"Invalid input: props must be a string or an array of strings"
|
|
@@ -432,19 +430,17 @@ const createObjectWithoutPrototype = (obj) => {
|
|
|
432
430
|
return newObj;
|
|
433
431
|
};
|
|
434
432
|
const createNestedObject = (arr, lastValue) => {
|
|
433
|
+
if (arr.length === 0) return lastValue;
|
|
435
434
|
const nestedObject = {};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (index === arr.length - 1 && lastValue) {
|
|
444
|
-
obj[value] = lastValue;
|
|
435
|
+
let current = nestedObject;
|
|
436
|
+
for (let i = 0; i < arr.length; i++) {
|
|
437
|
+
if (i === arr.length - 1 && lastValue) {
|
|
438
|
+
current[arr[i]] = lastValue;
|
|
439
|
+
} else {
|
|
440
|
+
current[arr[i]] = {};
|
|
441
|
+
current = current[arr[i]];
|
|
445
442
|
}
|
|
446
|
-
|
|
447
|
-
}, nestedObject);
|
|
443
|
+
}
|
|
448
444
|
return nestedObject;
|
|
449
445
|
};
|
|
450
446
|
const removeNestedKeyByPath = (obj, path) => {
|
|
@@ -453,13 +449,11 @@ const removeNestedKeyByPath = (obj, path) => {
|
|
|
453
449
|
}
|
|
454
450
|
let current = obj;
|
|
455
451
|
for (let i = 0; i < path.length - 1; i++) {
|
|
456
|
-
if (current[path[i]] === void 0)
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
452
|
+
if (current[path[i]] === void 0) return;
|
|
459
453
|
current = current[path[i]];
|
|
460
454
|
}
|
|
461
455
|
const lastKey = path[path.length - 1];
|
|
462
|
-
if (current && Object.hasOwnProperty.call(current, lastKey)) {
|
|
456
|
+
if (current && Object.prototype.hasOwnProperty.call(current, lastKey)) {
|
|
463
457
|
delete current[lastKey];
|
|
464
458
|
}
|
|
465
459
|
};
|
|
@@ -474,8 +468,7 @@ const setInObjectByPath = (obj, path, value) => {
|
|
|
474
468
|
}
|
|
475
469
|
current = current[path[i]];
|
|
476
470
|
}
|
|
477
|
-
|
|
478
|
-
current[lastKey] = value;
|
|
471
|
+
current[path[path.length - 1]] = value;
|
|
479
472
|
return obj;
|
|
480
473
|
};
|
|
481
474
|
const getInObjectByPath = (obj, path) => {
|
|
@@ -518,15 +511,13 @@ const detectInfiniteLoop = (arr) => {
|
|
|
518
511
|
}
|
|
519
512
|
};
|
|
520
513
|
const isCyclic = (obj) => {
|
|
521
|
-
const
|
|
514
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
522
515
|
function detect(obj2) {
|
|
523
516
|
if (obj2 && typeof obj2 === "object") {
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
seenObjects.push(obj2);
|
|
517
|
+
if (seen.has(obj2)) return true;
|
|
518
|
+
seen.add(obj2);
|
|
528
519
|
for (const key in obj2) {
|
|
529
|
-
if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
520
|
+
if (Object.prototype.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
530
521
|
console.log(obj2, "cycle at " + key);
|
|
531
522
|
return true;
|
|
532
523
|
}
|
|
@@ -537,8 +528,13 @@ const isCyclic = (obj) => {
|
|
|
537
528
|
return detect(obj);
|
|
538
529
|
};
|
|
539
530
|
const excludeKeysFromObject = (obj, excludedKeys) => {
|
|
540
|
-
const
|
|
541
|
-
|
|
531
|
+
const excluded = excludedKeys instanceof Set ? excludedKeys : new Set(excludedKeys);
|
|
532
|
+
const result = {};
|
|
533
|
+
for (const key in obj) {
|
|
534
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !excluded.has(key)) {
|
|
535
|
+
result[key] = obj[key];
|
|
536
|
+
}
|
|
537
|
+
}
|
|
542
538
|
return result;
|
|
543
539
|
};
|
|
544
540
|
export {
|