index.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. interface Reviver {
  2. (this: any, key: string, value: any): any;
  3. }
  4. interface ParseOptions {
  5. /**
  6. * - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
  7. * - `'remove'` - deletes any `__proto__` keys from the result object.
  8. * - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
  9. */
  10. protoAction?: 'error' | 'remove' | 'ignore';
  11. }
  12. /**
  13. * Parses a given JSON-formatted text into an object.
  14. * @param text the JSON text string.
  15. */
  16. export function parse(text: string): any;
  17. /**
  18. * Parses a given JSON-formatted text into an object.
  19. * @param text the JSON text string.
  20. * @param reviver the `JSON.parse()` optional `reviver` argument.
  21. */
  22. export function parse(text: string, reviver: Reviver): any;
  23. /**
  24. * Parses a given JSON-formatted text into an object.
  25. * @param text the JSON text string.
  26. * @param options optional configuration object.
  27. */
  28. export function parse(text: string, options: ParseOptions): any;
  29. /**
  30. * Parses a given JSON-formatted text into an object.
  31. * @param text the JSON text string.
  32. * @param reviver the `JSON.parse()` optional `reviver` argument.
  33. * @param options optional configuration object.
  34. */
  35. export function parse(text: string, reviver: Reviver, options: ParseOptions): any;
  36. interface ScanOptions {
  37. /**
  38. * - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
  39. * - `'remove'` - deletes any `__proto__` keys from the input `obj`.
  40. */
  41. protoAction?: 'error' | 'remove';
  42. }
  43. /**
  44. * Scans a given object for prototype properties.
  45. * @param obj the object being scanned.
  46. * @param options optional configuration object.
  47. */
  48. export function scan(obj: any, options?: ScanOptions): void;
  49. /**
  50. * Parses a given JSON-formatted text into an object or `null` if an error is found.
  51. * @param text the JSON text string.
  52. * @param reviver the `JSON.parse()` optional `reviver` argument.
  53. */
  54. export function safeParse(text: string, reviver?: Reviver) : any | null;