|
| 1 | +declare namespace serializeJavascript { |
| 2 | + interface SerializeJSOptions { |
| 3 | + /** |
| 4 | + * This option is the same as the space argument that can be passed to JSON.stringify. |
| 5 | + * It can be used to add whitespace and indentation to the serialized output to make it more readable. |
| 6 | + */ |
| 7 | + space?: string | number | undefined; |
| 8 | + /** |
| 9 | + * This option is a signal to serialize() that the object being serialized does not contain any function or regexps values. |
| 10 | + * This enables a hot-path that allows serialization to be over 3x faster. |
| 11 | + * If you're serializing a lot of data, and know its pure JSON, then you can enable this option for a speed-up. |
| 12 | + */ |
| 13 | + isJSON?: boolean | undefined; |
| 14 | + /** |
| 15 | + * This option is to signal serialize() that we want to do a straight conversion, without the XSS protection. |
| 16 | + * This options needs to be explicitly set to true. HTML characters and JavaScript line terminators will not be escaped. |
| 17 | + * You will have to roll your own. |
| 18 | + */ |
| 19 | + unsafe?: true | undefined; |
| 20 | + /** |
| 21 | + * This option is to signal serialize() that we do not want serialize JavaScript function. |
| 22 | + * Just treat function like JSON.stringify do, but other features will work as expected. |
| 23 | + */ |
| 24 | + ignoreFunction?: boolean | undefined; |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Serialize JavaScript to a superset of JSON that includes regular expressions and functions. |
| 30 | + * @param input data to serialize |
| 31 | + * @param options optional object |
| 32 | + * @returns serialized data |
| 33 | + */ |
| 34 | +declare function serializeJavascript( |
| 35 | + input: any, |
| 36 | + options?: serializeJavascript.SerializeJSOptions | number | string |
| 37 | +): string; |
| 38 | + |
| 39 | +export = serializeJavascript; |
0 commit comments