File tree 4 files changed +88
-3
lines changed
4 files changed +88
-3
lines changed Original file line number Diff line number Diff line change 1
1
# 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
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const benchmark = require ( 'benchmark' )
4
+ const safeStringify = require ( 'fast-safe-stringify' )
4
5
const suite = new benchmark . Suite ( )
5
6
6
7
const schema = {
@@ -18,8 +19,7 @@ const schema = {
18
19
'type' : 'integer' ,
19
20
'minimum' : 0
20
21
}
21
- } ,
22
- 'required' : [ 'firstName' , 'lastName' ]
22
+ }
23
23
}
24
24
25
25
const obj = {
@@ -38,6 +38,10 @@ suite.add('fast-json-stringify', function () {
38
38
stringify ( obj )
39
39
} )
40
40
41
+ suite . add ( 'fast-safe-stringify' , function ( ) {
42
+ safeStringify ( obj )
43
+ } )
44
+
41
45
suite . on ( 'complete' , print )
42
46
43
47
suite . run ( )
Original file line number Diff line number Diff line change
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
+ } ) )
Original file line number Diff line number Diff line change 25
25
"homepage" : " https://github.com/mcollina/fast-json-stringify#readme" ,
26
26
"devDependencies" : {
27
27
"benchmark" : " ^2.1.1" ,
28
+ "fast-safe-stringify" : " ^1.0.9" ,
28
29
"is-my-json-valid" : " ^2.13.1" ,
29
30
"pre-commit" : " ^1.1.3" ,
30
31
"standard" : " ^7.1.2" ,
You can’t perform that action at this time.
0 commit comments