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