index.d.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types.js';
  2. import { ClassRegistry, RegisterOptions } from './class-registry.js';
  3. import { Registry } from './registry.js';
  4. import { CustomTransfomer, CustomTransformerRegistry } from './custom-transformer-registry.js';
  5. export default class SuperJSON {
  6. /**
  7. * If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
  8. */
  9. private readonly dedupe;
  10. /**
  11. * @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
  12. */
  13. constructor({ dedupe, }?: {
  14. dedupe?: boolean;
  15. });
  16. serialize(object: SuperJSONValue): SuperJSONResult;
  17. deserialize<T = unknown>(payload: SuperJSONResult, options?: {
  18. inPlace?: boolean;
  19. }): T;
  20. stringify(object: SuperJSONValue): string;
  21. parse<T = unknown>(string: string): T;
  22. readonly classRegistry: ClassRegistry;
  23. registerClass(v: Class, options?: RegisterOptions | string): void;
  24. readonly symbolRegistry: Registry<Symbol>;
  25. registerSymbol(v: Symbol, identifier?: string): void;
  26. readonly customTransformerRegistry: CustomTransformerRegistry;
  27. registerCustom<I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, 'name'>, name: string): void;
  28. readonly allowedErrorProps: string[];
  29. allowErrorProps(...props: string[]): void;
  30. private static defaultInstance;
  31. static serialize: (object: SuperJSONValue) => SuperJSONResult;
  32. static deserialize: <T = unknown>(payload: SuperJSONResult, options?: {
  33. inPlace?: boolean;
  34. }) => T;
  35. static stringify: (object: SuperJSONValue) => string;
  36. static parse: <T = unknown>(string: string) => T;
  37. static registerClass: (v: Class, options?: RegisterOptions | string) => void;
  38. static registerSymbol: (v: Symbol, identifier?: string) => void;
  39. static registerCustom: <I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, "name">, name: string) => void;
  40. static allowErrorProps: (...props: string[]) => void;
  41. }
  42. export { SuperJSON, SuperJSONResult, SuperJSONValue };
  43. export declare const serialize: (object: SuperJSONValue) => SuperJSONResult;
  44. export declare const deserialize: <T = unknown>(payload: SuperJSONResult, options?: {
  45. inPlace?: boolean;
  46. }) => T;
  47. export declare const stringify: (object: SuperJSONValue) => string;
  48. export declare const parse: <T = unknown>(string: string) => T;
  49. export declare const registerClass: (v: Class, options?: RegisterOptions | string) => void;
  50. export declare const registerCustom: <I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, "name">, name: string) => void;
  51. export declare const registerSymbol: (v: Symbol, identifier?: string) => void;
  52. export declare const allowErrorProps: (...props: string[]) => void;