Skip to content

Commit 0f5febb

Browse files
authored
nodenext compatibility (#87)
1 parent fcb126e commit 0f5febb

File tree

2 files changed

+57
-48
lines changed

2 files changed

+57
-48
lines changed

index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function safeParse (text, reviver) {
105105
}
106106
}
107107

108-
module.exports = {
109-
parse,
110-
scan: filter,
111-
safeParse
112-
}
108+
module.exports = parse
109+
module.exports.default = parse
110+
module.exports.parse = parse
111+
module.exports.safeParse = safeParse
112+
module.exports.scan = filter

types/index.d.ts

+52-43
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,57 @@
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+
235
/**
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+
944
/**
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`
1450
*/
15-
constructorAction?: 'error' | 'remove' | 'ignore';
51+
export function scan(obj: { [key: string | number]: any }, options?: ParseOptions): any
52+
53+
export { parse as default}
1654
}
1755

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

Comments
 (0)