|
1 | | -export type ParseOptions = { |
| 1 | +type Parse = typeof parse |
| 2 | + |
| 3 | +declare namespace parse { |
| 4 | + export type ParseOptions = { |
| 5 | + /** |
| 6 | + * What to do when a `__proto__` key is found. |
| 7 | + * - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value. |
| 8 | + * - `'remove'` - deletes any `__proto__` keys from the result object. |
| 9 | + * - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly). |
| 10 | + */ |
| 11 | + protoAction?: 'error' | 'remove' | 'ignore'; |
| 12 | + /** |
| 13 | + * What to do when a `constructor` key is found. |
| 14 | + * - `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value. |
| 15 | + * - `'remove'` - deletes any `constructor` keys from the result object. |
| 16 | + * - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly). |
| 17 | + */ |
| 18 | + constructorAction?: 'error' | 'remove' | 'ignore'; |
| 19 | + } |
| 20 | + |
| 21 | + export type ScanOptions = ParseOptions |
| 22 | + |
| 23 | + export type Reviver = (this: any, key: string, value: any) => any |
| 24 | + |
| 25 | + /** |
| 26 | + * Parses a given JSON-formatted text into an object. |
| 27 | + * |
| 28 | + * @param text The JSON text string. |
| 29 | + * @param reviver The `JSON.parse()` optional `reviver` argument. |
| 30 | + * @param options Optional configuration object. |
| 31 | + * @returns The parsed object. |
| 32 | + */ |
| 33 | + export const parse: Parse |
| 34 | + |
2 | 35 | /** |
3 | | - * What to do when a `__proto__` key is found. |
4 | | - * - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value. |
5 | | - * - `'remove'` - deletes any `__proto__` keys from the result object. |
6 | | - * - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly). |
7 | | - */ |
8 | | - protoAction?: 'error' | 'remove' | 'ignore'; |
| 36 | + * Parses a given JSON-formatted text into an object. |
| 37 | + * |
| 38 | + * @param text The JSON text string. |
| 39 | + * @param reviver The `JSON.parse()` optional `reviver` argument. |
| 40 | + * @returns The parsed object, or `null` if there was an error or if the JSON contained possibly insecure properties. |
| 41 | + */ |
| 42 | + export function safeParse(text: string | Buffer, reviver?: Reviver | null): any |
| 43 | + |
9 | 44 | /** |
10 | | - * What to do when a `constructor` key is found. |
11 | | - * - `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value. |
12 | | - * - `'remove'` - deletes any `constructor` keys from the result object. |
13 | | - * - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly). |
| 45 | + * Scans a given object for prototype properties. |
| 46 | + * |
| 47 | + * @param obj The object being scanned. |
| 48 | + * @param options Optional configuration object. |
| 49 | + * @returns The object, or `null` if onError is set to `nullify` |
14 | 50 | */ |
15 | | - constructorAction?: 'error' | 'remove' | 'ignore'; |
| 51 | + export function scan(obj: { [key: string | number]: any }, options?: ParseOptions): any |
| 52 | + |
| 53 | + export { parse as default} |
16 | 54 | } |
17 | 55 |
|
18 | | -export type ScanOptions = ParseOptions |
19 | | - |
20 | | -type Reviver = (this: any, key: string, value: any) => any |
21 | | - |
22 | | -/** |
23 | | - * Parses a given JSON-formatted text into an object. |
24 | | - * |
25 | | - * @param text The JSON text string. |
26 | | - * @param reviver The `JSON.parse()` optional `reviver` argument. |
27 | | - * @param options Optional configuration object. |
28 | | - * @returns The parsed object. |
29 | | - */ |
30 | | -export function parse(text: string | Buffer, reviver?: Reviver | null, options?: ParseOptions): any |
31 | | - |
32 | | -/** |
33 | | - * Parses a given JSON-formatted text into an object. |
34 | | - * |
35 | | - * @param text The JSON text string. |
36 | | - * @param reviver The `JSON.parse()` optional `reviver` argument. |
37 | | - * @returns The parsed object, or `null` if there was an error or if the JSON contained possibly insecure properties. |
38 | | - */ |
39 | | -export function safeParse(text: string | Buffer, reviver?: Reviver | null): any |
40 | | - |
41 | | -/** |
42 | | - * Scans a given object for prototype properties. |
43 | | - * |
44 | | - * @param obj The object being scanned. |
45 | | - * @param options Optional configuration object. |
46 | | - * @returns The object, or `null` if onError is set to `nullify` |
47 | | - */ |
48 | | -export function scan(obj: {[key: string | number]: any }, options?: ParseOptions): any |
| 56 | +declare function parse(text: string | Buffer, reviver?: parse.Reviver | null, options?: parse.ParseOptions): any |
| 57 | +export = parse |
0 commit comments