Skip to content

Commit

Permalink
fixed destringify
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoloza committed Feb 2, 2023
1 parent 1b912f1 commit 63fe4f7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/utils/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const deepStringify = (obj, stringified = {}) => {
if (isFunction(objProp)) {
stringified[prop] = objProp.toString()
} else stringified[prop] = objProp
// if (prop === 'src') {
// console.log(typeof stringified[prop])
// console.log(prop, stringified[prop])
// }
if (isObject(objProp)) deepStringify(stringified[prop], stringified[prop])
}
return stringified
Expand All @@ -91,10 +95,16 @@ export const deepDestringify = (obj, stringified = {}) => {
for (const prop in obj) {
const objProp = obj[prop]
if (isString(objProp)) {
if (objProp.slice(0, 1) === '(') {
if (objProp.includes('=>') || objProp.includes('function') || objProp[0] === '(') {
// console.groupCollapsed(prop)
// console.log(obj)
// console.log(objProp)
try {
stringified[prop] = eval(objProp) // eslint-disable-line
const evalProp = eval(objProp) // eslint-disable-line
// console.log(evalProp)
stringified[prop] = evalProp
} catch (e) { if (e) stringified[prop] = objProp }
// console.groupEnd(prop)
}
} else stringified[prop] = objProp
if (isObject(objProp)) deepDestringify(stringified[prop], stringified[prop])
Expand Down

0 comments on commit 63fe4f7

Please sign in to comment.