forked from fastify/secure-json-parse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
60 lines (55 loc) · 2.31 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
export type ParseOptions = {
/**
* What to do when a `__proto__` key is found.
* - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
* - `'remove'` - deletes any `__proto__` keys from the result object.
* - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
*/
protoAction?: 'error' | 'remove' | 'ignore',
/**
* What to do when a `constructor` key is found.
* - `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value.
* - `'remove'` - deletes any `constructor` keys from the result object.
* - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
*/
constructorAction?: 'error' | 'remove' | 'ignore',
}
export type ScanOptions = {
/**
* What to do when a `__proto__` key is found.
* - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
* - `'remove'` - deletes any `__proto__` keys from the input `obj`.
*/
protoAction?: 'error' | 'remove',
/**
* What to do when a `constructor` key is found.
* - `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value.
* - `'remove'` - deletes any `constructor` keys from the input `obj`.
*/
constructorAction?: 'error' | 'remove',
}
type Reviver = (this: any, key: string, value: any) => any
/**
* Parses a given JSON-formatted text into an object.
*
* @param text The JSON text string.
* @param reviver The `JSON.parse()` optional `reviver` argument.
* @param options Optional configuration object.
* @returns The parsed object.
*/
export function parse(text: string | Buffer, reviver?: Reviver | null, options?: ParseOptions): any
/**
* Parses a given JSON-formatted text into an object.
*
* @param text The JSON text string.
* @param reviver The `JSON.parse()` optional `reviver` argument.
* @returns The parsed object, or `null` if there was an error or if the JSON contained possibly insecure properties.
*/
export function safeParse(text: string | Buffer, reviver?: Reviver | null): any
/**
* Scans a given object for prototype properties.
*
* @param obj The object being scanned.
* @param options Optional configuration object.
*/
export function scan(obj: any, options?: ScanOptions): void