stringify-parse
stringify-parse
A tool like JSON.stringify and JSON.parse but could convert the type Function and RegExp in the js object.
Install
1 | npm install stringify-parse |
eg.
1 | let o = { |
Now, I want to convert the object into string, if we use JSON.stringify, it will lost the property method and reg
1 | {"name":"demo","reg":{}} |
This is not what we want. Now we can use the tool stringify-parse
1 | const stringifyParse = require('stringify-parse'); |
output:
1 | {"name":"demo","method":function() { |
Then we can use the method stringifyParse.parse to convert the json string into object.
1 | let str = `{"name":"demo","method":function() { |