Stringify at perfect performance. +1200%
Benchmark it yourself: https://jsperf.com/likejson
Node.js:
npm i like-json
Browser:
<script src="https://unpkg.com/like-json/index.min.js"></script>
like.json(obj: Object|Array|Any, options: Object): Function
like.stringify(obj: Object|Array|Any, uniqueId: Number, options: Object): String
const like = require('like-json');
let stringify = like.json({ msg: '' });
let string1 = JSON.stringify({ msg: 'account created' });
let string2 = stringify({ msg: 'account created' });
console.log(string1 === string2); // true
const like = require('like-json');
let string1 = JSON.stringify({ msg: 'account created' });
let string2 = like.stringify({ msg: 'account created' }, 1);
console.log(string1 === string2); // true
There is no processing, so same than a simple concatenation:
console.log(stringify.toString());
// ->
function anonymous (o) {
return '{"msg":"' + o.msg + '"}';
}
Because that there is a conflict with double quotes:
{ msg: 'account "user" created' } // object
{"msg":"account \"user\" created"} // JSON.stringify
{"msg":"account "user" created"} // like.stringify
You can use single quotes, in that way avoid escape which reduces performance.
If really want to use double quotes then can use options:
let options = { encode: true };
let string1 = JSON.stringify({ msg: 'account "user" created' });
let string2 = like.stringify({ msg: 'account "user" created' }, 2, options);
console.log(string1 === string2); // true
npm test
Inside of stringify.test.js can see more info.
Code released under the MIT License.