@@ -11,24 +11,22 @@ The fastest JSON stringifier
1111 - [ How it works] ( #how-it-works )
1212 - [ Caveats] ( #caveats )
1313 - [ Benchmarks] ( #benchmarks )
14- - [ Running the benchmarks] ( #running-the-benchmarks )
14+ - [ Running the benchmarks] ( #running-the-benchmarks )
1515 - [ Test machine] ( #test-machine )
1616 - [ Some numbers] ( #some-numbers )
1717 - [ Usage] ( #usage )
18- - [ Supported types] ( #supported-types )
18+ - [ Supported types] ( #supported-types )
1919 - [ Defining a schema] ( #defining-a-schema )
2020 - [ Defining schema with simple array] ( #defining-schema-with-simple-array )
2121 - [ Defining schema with complex array] ( #defining-schema-with-complex-array )
2222 - [ Defining schema with nested objects] ( #defining-schema-with-nested-objects )
2323 - [ Serializers] ( #serializers )
2424 - [ API] ( #api )
25- - [ sjs] ( #sjs-1 )
26- - [ attr] ( #attr )
27- - [ escape] ( #escape )
25+ - [ sjs] ( #sjs-1 )
26+ - [ attr] ( #attr )
27+ - [ escape] ( #escape )
2828 - [ License] ( #license )
2929
30-
31-
3230## TL;DR
3331
3432` SJS ` shows a significant increase in performance over both native ` JSON.stringify ` and ` fast-json-stringify ` .
@@ -43,11 +41,13 @@ Checkout [benchmarks](benchmark.md).
4341` SJS ` is fully compatible with both Node.js and the browser 🎉🎉
4442
4543Node:
44+
4645``` bash
4746npm install slow-json-stringify
4847```
4948
5049On the browser:
50+
5151``` html
5252<script src =" https://unpkg.com/slow-json-stringify/dist/sjs.umd.js" ></script >
5353```
@@ -59,11 +59,13 @@ The traditional approach consists in serializing every property taken singularly
5959` SJS ` uses a different approach to serialization.
6060
6161** Preparation:**
62+
6263- A schema is provided
6364- The schema is stringified
6465- A templated string is built with the provided schema.
6566
6667** Serialization:**
68+
6769- Object values are inserted in the already built template.
6870
6971It is faster simply because it performs a lot less work.
@@ -80,10 +82,11 @@ Moreover, `SJS` makes possible the serialization of types that are not natively
8082However, ` SJS ` provides a little utility for your escaping needs.
8183` escape ` uses a default regex if no additional regex is provided.
8284
83- ** default regex string:**
85+ ** default regex string:**
86+
8487``` javascript
8588/ \n | \r | \t | \" | \\ / gm
86- ```
89+ ```
8790
8891You can use ` escape ` like the following:
8992
@@ -111,10 +114,11 @@ Lies, damned lies.. and benchmarks.
111114Remember to test if ` SJS ` could be a real improvement for your use case.
112115Because there are times when the performance advantages with the added drawbacks could not be worth it.
113116
114- #### Running the benchmarks
117+ ### Running the benchmarks
115118
116119Every benchmark is replicable on your own machine.
117120To run your tests:
121+
118122- Clone this repo.
119123- Install dependencies.
120124- ` cd benchmark ` .
@@ -124,6 +128,7 @@ To run your tests:
124128#### Test machine
125129
126130The benchmarks were performed on a Dell Xps 15 9550.
131+
127132- ** cpu:** intel i7 6700HQ
128133- ** ram:** 16gb
129134- ** os:** Ubuntu 18.04
@@ -134,7 +139,7 @@ Checkout benchmarks [here](benchmark.md)
134139
135140## Usage
136141
137- #### Supported types
142+ ### Supported types
138143
139144The schema creation happens thanks to the ` attr ` helper exported from the main bundle.
140145
@@ -147,6 +152,7 @@ attr(type, serializer?)
147152```
148153
149154The ` attr ` helper natively supports the following types:
155+
150156- ` string `
151157- ` number `
152158- ` boolean `
@@ -274,7 +280,7 @@ stringify({
274280
275281## Serializers
276282
277- The ` attr ` helper accepts a serializer function. The serializer function gets invoked with the real value that should be stringified.
283+ The ` attr ` helper accepts a serializer function. The serializer function gets invoked with the real value that should be stringified.
278284
279285``` bash
280286serializer(rawValue)
@@ -338,18 +344,21 @@ const stringify = sjs({
338344
339345## API
340346
341- #### sjs
347+ ### sjs
348+
342349| param | type | required | default | spec |
343350| --------| ---------| ------------------------------------| -----------| -----------------------------------------------------|
344351| schema | object | yes | undefined | Schema that defines the stringification behavior. |
345352
346- #### attr
353+ ### attr
354+
347355| param | type | required | default | spec |
348356| ------------| ----------| ------------------------------------| -----------| --------------------------------------------------------|
349357| type | string | yes | undefined | Type of the property. |
350358| serializer | function | no | identity | Function used for serializing / validating properties. |
351359
352- #### escape
360+ ### escape
361+
353362| param | type | required | default | spec |
354363| -------| --------------------| ------------------------------------| ---------------------------| -----------------------------------------------------|
355364| regex | Regular Expression | no | default regex | regex used to escape text |
0 commit comments