@domql/utils 2.3.81 → 2.3.83
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/dist/cjs/object.js +27 -0
- package/object.js +29 -1
- package/package.json +2 -2
package/dist/cjs/object.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(object_exports, {
|
|
|
24
24
|
deepDestringify: () => deepDestringify,
|
|
25
25
|
deepMerge: () => deepMerge,
|
|
26
26
|
deepStringify: () => deepStringify,
|
|
27
|
+
detachFunctionsFromObject: () => detachFunctionsFromObject,
|
|
27
28
|
diff: () => diff,
|
|
28
29
|
exec: () => exec,
|
|
29
30
|
flattenRecursive: () => flattenRecursive,
|
|
@@ -159,6 +160,32 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
159
160
|
}
|
|
160
161
|
return stringified;
|
|
161
162
|
};
|
|
163
|
+
const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
164
|
+
for (const prop in obj) {
|
|
165
|
+
const objProp = obj[prop];
|
|
166
|
+
if ((0, import_types.isFunction)(objProp))
|
|
167
|
+
continue;
|
|
168
|
+
else if ((0, import_types.isObject)(objProp)) {
|
|
169
|
+
detached[prop] = {};
|
|
170
|
+
deepStringify(objProp, detached[prop]);
|
|
171
|
+
} else if ((0, import_types.isArray)(objProp)) {
|
|
172
|
+
detached[prop] = [];
|
|
173
|
+
objProp.forEach((v, i) => {
|
|
174
|
+
if ((0, import_types.isFunction)(v))
|
|
175
|
+
return;
|
|
176
|
+
if ((0, import_types.isObject)(v)) {
|
|
177
|
+
detached[prop][i] = {};
|
|
178
|
+
detachFunctionsFromObject(v, detached[prop][i]);
|
|
179
|
+
} else {
|
|
180
|
+
detached[prop][i] = v;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
detached[prop] = objProp;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return detached;
|
|
188
|
+
};
|
|
162
189
|
const deepDestringify = (obj, stringified = {}) => {
|
|
163
190
|
for (const prop in obj) {
|
|
164
191
|
const objProp = obj[prop];
|
package/object.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { window } from '@domql/globals'
|
|
4
|
-
import { isFunction, isObjectLike, isObject, isArray, isString
|
|
4
|
+
import { isFunction, isObjectLike, isObject, isArray, isString } from './types.js'
|
|
5
5
|
|
|
6
6
|
export const exec = (param, element, state, context) => {
|
|
7
7
|
if (isFunction(param)) {
|
|
@@ -138,6 +138,34 @@ export const deepStringify = (obj, stringified = {}) => {
|
|
|
138
138
|
return stringified
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Stringify object
|
|
143
|
+
*/
|
|
144
|
+
export const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
145
|
+
for (const prop in obj) {
|
|
146
|
+
const objProp = obj[prop]
|
|
147
|
+
if (isFunction(objProp)) continue
|
|
148
|
+
else if (isObject(objProp)) {
|
|
149
|
+
detached[prop] = {}
|
|
150
|
+
deepStringify(objProp, detached[prop])
|
|
151
|
+
} else if (isArray(objProp)) {
|
|
152
|
+
detached[prop] = []
|
|
153
|
+
objProp.forEach((v, i) => {
|
|
154
|
+
if (isFunction(v)) return
|
|
155
|
+
if (isObject(v)) {
|
|
156
|
+
detached[prop][i] = {}
|
|
157
|
+
detachFunctionsFromObject(v, detached[prop][i])
|
|
158
|
+
} else {
|
|
159
|
+
detached[prop][i] = v
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
} else {
|
|
163
|
+
detached[prop] = objProp
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return detached
|
|
167
|
+
}
|
|
168
|
+
|
|
141
169
|
/**
|
|
142
170
|
* Detringify object
|
|
143
171
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.83",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@domql/globals": "latest",
|
|
23
23
|
"@domql/tags": "latest"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "82d0f23182e270fbcaf995f59346c0eded5976c3"
|
|
26
26
|
}
|