提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
3.0 KiB

  1. import { Class, JSONValue, SuperJSONResult, SuperJSONValue } from './types.cjs';
  2. import { ClassRegistry, RegisterOptions } from './class-registry.cjs';
  3. import { Registry } from './registry.cjs';
  4. import { CustomTransfomer, CustomTransformerRegistry } from './custom-transformer-registry.cjs';
  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 | undefined;
  34. } | undefined) => T;
  35. static stringify: (object: SuperJSONValue) => string;
  36. static parse: <T = unknown>(string: string) => T;
  37. static registerClass: (v: Class, options?: string | RegisterOptions | undefined) => void;
  38. static registerSymbol: (v: Symbol, identifier?: string | undefined) => 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 | undefined;
  46. } | undefined) => 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?: string | RegisterOptions | undefined) => 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 | undefined) => void;
  52. export declare const allowErrorProps: (...props: string[]) => void;