Skip to content

Commit d6e10ff

Browse files
committed
README, bench, example.
1 parent 39f6de9 commit d6e10ff

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

README.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
11
# fast-json-stringify
2-
go away
2+
3+
__fast-json-stringify__ is x5 faster than `JSON.stringify()`.
4+
5+
Benchmarks:
6+
7+
```
8+
JSON.stringify x 1,681,132 ops/sec ±0.59% (88 runs sampled)
9+
fast-json-stringify x 5,117,658 ops/sec ±1.44% (87 runs sampled)
10+
```
11+
12+
## Example
13+
14+
```js
15+
const fastJson = require('fast-json-stringify')
16+
const stringify = fastJson({
17+
title: 'Example Schema',
18+
type: 'object',
19+
properties: {
20+
firstName: {
21+
type: 'string'
22+
},
23+
lastName: {
24+
type: 'string'
25+
},
26+
age: {
27+
description: 'Age in years',
28+
type: 'integer'
29+
}
30+
}
31+
})
32+
33+
console.log(stringify({
34+
firstName: 'Matteo',
35+
lastName: 'Collina',
36+
age: 32
37+
}))
38+
```
39+
40+
## API
41+
42+
### fastJsonStringify(schema)
43+
44+
Build a `stringify()` function based on
45+
[jsonschema](http://json-schema.org/).
46+
47+
Supported types:
48+
49+
* `integer'
50+
* `number'
51+
* `array'
52+
* `object'
53+
* `null'
54+
55+
## License
56+
57+
MIT

bench.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const benchmark = require('benchmark')
4+
const safeStringify = require('fast-safe-stringify')
45
const suite = new benchmark.Suite()
56

67
const schema = {
@@ -18,8 +19,7 @@ const schema = {
1819
'type': 'integer',
1920
'minimum': 0
2021
}
21-
},
22-
'required': ['firstName', 'lastName']
22+
}
2323
}
2424

2525
const obj = {
@@ -38,6 +38,10 @@ suite.add('fast-json-stringify', function () {
3838
stringify(obj)
3939
})
4040

41+
suite.add('fast-safe-stringify', function () {
42+
safeStringify(obj)
43+
})
44+
4145
suite.on('complete', print)
4246

4347
suite.run()

example.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict'
2+
3+
const fastJson = require('.')
4+
const stringify = fastJson({
5+
title: 'Example Schema',
6+
type: 'object',
7+
properties: {
8+
firstName: {
9+
type: 'string'
10+
},
11+
lastName: {
12+
type: 'string'
13+
},
14+
age: {
15+
description: 'Age in years',
16+
type: 'integer'
17+
}
18+
}
19+
})
20+
21+
console.log(stringify({
22+
firstName: 'Matteo',
23+
lastName: 'Collina',
24+
age: 32
25+
}))

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"homepage": "https://github.com/mcollina/fast-json-stringify#readme",
2626
"devDependencies": {
2727
"benchmark": "^2.1.1",
28+
"fast-safe-stringify": "^1.0.9",
2829
"is-my-json-valid": "^2.13.1",
2930
"pre-commit": "^1.1.3",
3031
"standard": "^7.1.2",

0 commit comments

Comments
 (0)