index.d.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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): T;
  18. stringify(object: SuperJSONValue): string;
  19. parse<T = unknown>(string: string): T;
  20. readonly classRegistry: ClassRegistry;
  21. registerClass(v: Class, options?: RegisterOptions | string): void;
  22. readonly symbolRegistry: Registry<Symbol>;
  23. registerSymbol(v: Symbol, identifier?: string): void;
  24. readonly customTransformerRegistry: CustomTransformerRegistry;
  25. registerCustom<I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, 'name'>, name: string): void;
  26. readonly allowedErrorProps: string[];
  27. allowErrorProps(...props: string[]): void;
  28. private static defaultInstance;
  29. static serialize: (object: SuperJSONValue) => SuperJSONResult;
  30. static deserialize: <T = unknown>(payload: SuperJSONResult) => T;
  31. static stringify: (object: SuperJSONValue) => string;
  32. static parse: <T = unknown>(string: string) => T;
  33. static registerClass: (v: Class, options?: string | RegisterOptions | undefined) => void;
  34. static registerSymbol: (v: Symbol, identifier?: string | undefined) => void;
  35. static registerCustom: <I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, "name">, name: string) => void;
  36. static allowErrorProps: (...props: string[]) => void;
  37. }
  38. export { SuperJSON, SuperJSONResult };
  39. export declare const serialize: (object: SuperJSONValue) => SuperJSONResult;
  40. export declare const deserialize: <T = unknown>(payload: SuperJSONResult) => T;
  41. export declare const stringify: (object: SuperJSONValue) => string;
  42. export declare const parse: <T = unknown>(string: string) => T;
  43. export declare const registerClass: (v: Class, options?: string | RegisterOptions | undefined) => void;
  44. export declare const registerCustom: <I, O extends JSONValue>(transformer: Omit<CustomTransfomer<I, O>, "name">, name: string) => void;
  45. export declare const registerSymbol: (v: Symbol, identifier?: string | undefined) => void;
  46. export declare const allowErrorProps: (...props: string[]) => void;