Skip to content

A tool like JSON.stringify and JSON.parse but can convert the type Function and RegExp in the js object.

Notifications You must be signed in to change notification settings

bonjs/stringify-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stringify-parse Build Status

A tool like JSON.stringify and JSON.parse but could convert the type Function and RegExp in the js object.

Install

npm install stringify-parse

eg.

let o = {
  name: 'stringify-parse',
  method: function() {
    console.log('this is a function');
  },
  reg: /\w+/
}

Now, I want to convert the object into string, if we use JSON.stringify, it will lost the property method and reg

{"name":"demo","reg":{}}

This is not what we want. Now we can use the tool stringify-parse

const stringifyParse = require('stringify-parse');
console.log(stringifyParse(o));

output:

{"name":"demo","method":function() {
    console.log('this is a function');
  },"reg":/\w+/

Then we can use the method stringifyParse.parse to convert the json string into object.

let str = `{"name":"demo","method":function() {
    console.log('this is a function');
  },"reg":/\w+/
 `;
console.log(stringifyParse.parse(str));

And you can use the window variable stringifyParse or jsfull like this:

<script src="stringify-parse.js"></script>

<script>
  let str = `{"name":"demo","method":function() {
    console.log('this is a function');
  },"reg":/\w+/
 `;
console.log(stringifyParse.parse(str));
console.log(jsfull.parse(str));
</script>

About

A tool like JSON.stringify and JSON.parse but can convert the type Function and RegExp in the js object.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published