@domql/utils 2.3.21 → 2.3.23

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.
Files changed (2) hide show
  1. package/object.js +35 -2
  2. package/package.json +2 -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)
@@ -64,7 +64,7 @@ export const deepClone = (obj) => {
64
64
  objProp = mergeArray(objProp)
65
65
  }
66
66
  if (isArray(objProp)) {
67
- o[prop] = objProp.map(deepClone)
67
+ o[prop] = objProp.map(v => isObject(v) ? deepClone(v) : v)
68
68
  } else if (isObject(objProp)) {
69
69
  o[prop] = deepClone(objProp)
70
70
  } else o[prop] = objProp
@@ -72,6 +72,39 @@ export const deepClone = (obj) => {
72
72
  return o
73
73
  }
74
74
 
75
+ /**
76
+ * Stringify object
77
+ */
78
+ export const deepStringify = (obj, stringified = {}) => {
79
+ console.log(obj)
80
+ for (const prop in obj) {
81
+ const objProp = obj[prop]
82
+ if (isFunction(objProp)) {
83
+ stringified[prop] = objProp.toString()
84
+ } else stringified[prop] = objProp
85
+ if (isObject(objProp)) deepStringify(stringified[prop], stringified[prop])
86
+ }
87
+ return stringified
88
+ }
89
+
90
+ /**
91
+ * Detringify object
92
+ */
93
+ export const deepDestringify = (obj, stringified = {}) => {
94
+ for (const prop in obj) {
95
+ const objProp = obj[prop]
96
+ if (isString(objProp)) {
97
+ if (objProp.slice(0, 1) === '(') {
98
+ try {
99
+ stringified[prop] = eval(objProp) // eslint-disable-line
100
+ } catch (e) { if (e) stringified[prop] = objProp }
101
+ }
102
+ } else stringified[prop] = objProp
103
+ if (isObject(objProp)) deepDestringify(stringified[prop], stringified[prop])
104
+ }
105
+ return stringified
106
+ }
107
+
75
108
  /**
76
109
  * Overwrites object properties with another
77
110
  */
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.3.21",
3
+ "version": "2.3.23",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
7
  "@domql/globals": "latest",
8
8
  "@domql/tags": "latest"
9
9
  },
10
- "gitHead": "591bd439470038afee450aa314c56a257107b1a0"
10
+ "gitHead": "3757666fe613ef00cbdf7d020da4b27c8bf3fb54"
11
11
  }