Skip to content

nodenext compatibility #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function safeParse (text, reviver) {
}
}

module.exports = {
parse,
scan: filter,
safeParse
}
module.exports = parse
module.exports.default = parse
module.exports.parse = parse
module.exports.safeParse = safeParse
module.exports.scan = filter
95 changes: 52 additions & 43 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
export type ParseOptions = {
type Parse = typeof parse

declare namespace parse {
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 = ParseOptions

export 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 const parse: Parse

/**
* 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';
* 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

/**
* 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).
* Scans a given object for prototype properties.
*
* @param obj The object being scanned.
* @param options Optional configuration object.
* @returns The object, or `null` if onError is set to `nullify`
*/
constructorAction?: 'error' | 'remove' | 'ignore';
export function scan(obj: { [key: string | number]: any }, options?: ParseOptions): any

export { parse as default}
}

export type ScanOptions = ParseOptions

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.
* @returns The object, or `null` if onError is set to `nullify`
*/
export function scan(obj: {[key: string | number]: any }, options?: ParseOptions): any
declare function parse(text: string | Buffer, reviver?: parse.Reviver | null, options?: parse.ParseOptions): any
export = parse