@domql/utils 2.3.21 → 2.3.24
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/object.js +34 -4
- package/package.json +3 -2
package/object.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isFunction, isObjectLike, isObject, isArray } from './types'
|
|
3
|
+
import { isFunction, isObjectLike, isObject, isArray, isString } from './types'
|
|
4
4
|
|
|
5
5
|
export const exec = (param, element, state) => {
|
|
6
6
|
if (isFunction(param)) return param(element, state || element.state)
|
|
@@ -25,7 +25,6 @@ export const merge = (element, obj) => {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export const deepMerge = (element, extend) => {
|
|
28
|
-
// console.groupCollapsed('deepMerge:')
|
|
29
28
|
for (const e in extend) {
|
|
30
29
|
const elementProp = element[e]
|
|
31
30
|
const extendProp = extend[e]
|
|
@@ -37,7 +36,6 @@ export const deepMerge = (element, extend) => {
|
|
|
37
36
|
deepMerge(elementProp, extendProp)
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
// console.groupEnd('deepMerge:')
|
|
41
39
|
return element
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -64,7 +62,7 @@ export const deepClone = (obj) => {
|
|
|
64
62
|
objProp = mergeArray(objProp)
|
|
65
63
|
}
|
|
66
64
|
if (isArray(objProp)) {
|
|
67
|
-
o[prop] = objProp.map(deepClone)
|
|
65
|
+
o[prop] = objProp.map(v => isObject(v) ? deepClone(v) : v)
|
|
68
66
|
} else if (isObject(objProp)) {
|
|
69
67
|
o[prop] = deepClone(objProp)
|
|
70
68
|
} else o[prop] = objProp
|
|
@@ -72,6 +70,38 @@ export const deepClone = (obj) => {
|
|
|
72
70
|
return o
|
|
73
71
|
}
|
|
74
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Stringify object
|
|
75
|
+
*/
|
|
76
|
+
export const deepStringify = (obj, stringified = {}) => {
|
|
77
|
+
for (const prop in obj) {
|
|
78
|
+
const objProp = obj[prop]
|
|
79
|
+
if (isFunction(objProp)) {
|
|
80
|
+
stringified[prop] = objProp.toString()
|
|
81
|
+
} else stringified[prop] = objProp
|
|
82
|
+
if (isObject(objProp)) deepStringify(stringified[prop], stringified[prop])
|
|
83
|
+
}
|
|
84
|
+
return stringified
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Detringify object
|
|
89
|
+
*/
|
|
90
|
+
export const deepDestringify = (obj, stringified = {}) => {
|
|
91
|
+
for (const prop in obj) {
|
|
92
|
+
const objProp = obj[prop]
|
|
93
|
+
if (isString(objProp)) {
|
|
94
|
+
if (objProp.slice(0, 1) === '(') {
|
|
95
|
+
try {
|
|
96
|
+
stringified[prop] = eval(objProp) // eslint-disable-line
|
|
97
|
+
} catch (e) { if (e) stringified[prop] = objProp }
|
|
98
|
+
}
|
|
99
|
+
} else stringified[prop] = objProp
|
|
100
|
+
if (isObject(objProp)) deepDestringify(stringified[prop], stringified[prop])
|
|
101
|
+
}
|
|
102
|
+
return stringified
|
|
103
|
+
}
|
|
104
|
+
|
|
75
105
|
/**
|
|
76
106
|
* Overwrites object properties with another
|
|
77
107
|
*/
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.24",
|
|
4
4
|
"main": "index.js",
|
|
5
|
+
"module": "index.js",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"dependencies": {
|
|
7
8
|
"@domql/globals": "latest",
|
|
8
9
|
"@domql/tags": "latest"
|
|
9
10
|
},
|
|
10
|
-
"gitHead": "
|
|
11
|
+
"gitHead": "1b912f1758896a2721daf5fed681290833ee9a4d"
|
|
11
12
|
}
|