UNPKG

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