You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,28 @@ The above will produce the following string, HTML-escaped output which is safe t
66
66
'{"haxorXSS":"\\u003C\\u002Fscript\\u003E"}'
67
67
```
68
68
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
+
69
91
## License
70
92
71
93
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.
0 commit comments