UNPKG

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