@rickyli79/rich-json
Version:
Serialize and Deserialize javascript objects
51 lines (50 loc) • 2.19 kB
TypeScript
import type { SetOptional } from 'type-fest';
export declare function simEval(code: string): any;
export declare const isNodeJs: boolean;
export declare const isBrowser: boolean;
export type ClassSpy<T extends object = object> = Function & {
prototype: T;
};
export type InstanceTypeSpy<TClass> = InstanceType<{
new (): never;
} & TClass>;
export declare function getMarkKey(num: number, sp: string): string;
export declare function getNativeKeys(sp: string, mark?: string): {
sp: string;
mark: string | undefined;
type: string;
content: string;
className: string;
required: string[];
required_length: number;
all: string[];
all_length: number;
};
export type NativeKeys = SetOptional<ReturnType<typeof getNativeKeys>, 'mark'>;
export declare function isNativeProperty(value: any, nativeKeys: NativeKeys): boolean;
export declare function calMarkId(value: Record<string, any>, nativeKeys: NativeKeys, usedMark: string[]): void;
export type CustomerSerializer<T extends ClassSpy, TContent = any> = {
className: string;
class: T;
toContent(value: InstanceTypeSpy<T>, isPlainContent: () => void): TContent;
fromContent(content: TContent): InstanceTypeSpy<T>;
isType(value: any): value is InstanceTypeSpy<T>;
/**
* when `TContent` is of `object` type, does it need to be serialized
* @default true
*/
serializContent?: boolean;
};
export type SerializeConfig = {
Date: boolean;
Function: boolean;
RegExp: boolean;
Set: boolean;
Map: boolean;
Buffer: boolean;
};
export declare function getBuildinSerializers(): CustomerSerializer<ClassSpy, any>[];
export declare const customerSerializers: CustomerSerializer<ClassSpy, any>[];
export declare function resetCustomerSerializers(): CustomerSerializer<ClassSpy<object>, any>[];
export declare function createCustomerSerializer<T extends ClassSpy, TContent = any>(pars: SetOptional<CustomerSerializer<T, TContent>, 'className' | 'isType'>): CustomerSerializer<T, TContent>;
export declare function addCustomerSerializer<T extends ClassSpy, TContent = any>(pars: SetOptional<CustomerSerializer<T, TContent>, 'className' | 'isType'>): void;