Skip to content

Commit e7015c3

Browse files
committed
Add docs on options to README
1 parent f2a5cf9 commit e7015c3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ The above will produce the following string, HTML-escaped output which is safe t
6666
'{"haxorXSS":"\\u003C\\u002Fscript\\u003E"}'
6767
```
6868

69+
### Options
70+
71+
The `serialize()` function accepts `options` as its second argument. There are two options, both default to being `undefined`:
72+
73+
#### `options.space`
74+
75+
This option is the same as the `space` argument that can be passed to [`JSON.stringify`][JSON.stringify]. It can be used to add whitespace and indentation to the serialized output to make it more readable.
76+
77+
```js
78+
serialize(obj, {space: 2});
79+
```
80+
81+
#### `options.isJSON`
82+
83+
This option is a signal to `serialize()` that the object being serialized does not contain any function or regexps values. This enables a hot-path that allows serialization to be over 3x faster. If you're serializing a lot of data, and know its pure JSON, then you can enable this option for a speed-up.
84+
85+
**Note:** That when using this option, the output will still be escaped to protect against XSS.
86+
87+
```js
88+
serialize(obj, {isJSON: true});
89+
```
90+
6991
## License
7092

7193
This software is free to use under the Yahoo! Inc. BSD license.
@@ -79,4 +101,5 @@ See the [LICENSE file][LICENSE] for license text and copyright information.
79101
[travis]: https://travis-ci.org/yahoo/serialize-javascript
80102
[travis-badge]: https://img.shields.io/travis/yahoo/serialize-javascript.svg?style=flat-square
81103
[express-state]: https://github.com/yahoo/express-state
104+
[JSON.stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
82105
[LICENSE]: https://github.com/yahoo/serialize-javascript/blob/master/LICENSE

0 commit comments

Comments
 (0)