1.0.32 • Published 4 years ago

like-json v1.0.32

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

like-json

Stringify at perfect performance. +1200%

npm.io npm.io tested with jest npm.io

npm.io Benchmark it yourself: https://jsperf.com/likejson

Install

Node.js:

npm i like-json

Browser:

<script src="https://unpkg.com/like-json/index.min.js"></script>

Features

Methods

like.json(obj: Object|Array|Any, options: Object): Function
like.stringify(obj: Object|Array|Any, uniqueId: Number, options: Object): String

Examples

json

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

stringify

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

How it works?

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

Tests

npm test

Inside of stringify.test.js can see more info.

License

Code released under the MIT License.

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago