Closed drschwabe closed 1 year ago
me too,why author can't do it? i think it need a parse
way will be beautifull
We are silly, the string can be executed directly with eval
We are silly, the string can be executed directly with
eval
oh cool, thx that seems less hacky than my original tek - will try that !
Just wanted to A) see if there is an existing way to do this without being too hacky (see hacky solution below) and if not, B) suggest the feature or a supplementary module to do parsing of javascript-stringified output so that we can create an object from a string generated with javascript-stringify.
Regarding potential existing way, I tried this lib but does not seem to be able to parse an object output with javascript-stringify
https://github.com/greenpioneersolutions/auto-parse
(note for my test I wrote the javascript-stringify output to a file and then performed a
fs.readFile(objString, 'utf8')
on it and then attempted to read the resulting string with auto-parse)The way that I found which actually works is a bit hacky and requires Node:
you can write the javascript-stringify output to a string, append
module.exports=
, write to disk, and perform arequire
on the resulting file.related: https://github.com/blakeembrey/javascript-stringify/issues/32