UNPKG

3.12 kBTypeScriptView Raw
1import { ClassTransformOptions } from './interfaces';
2import { ClassConstructor } from './interfaces';
3export declare class ClassTransformer {
4 /**
5 * Converts class (constructor) object to plain (literal) object. Also works with arrays.
6 */
7 instanceToPlain<T extends Record<string, any>>(object: T, options?: ClassTransformOptions): Record<string, any>;
8 instanceToPlain<T extends Record<string, any>>(object: T[], options?: ClassTransformOptions): Record<string, any>[];
9 /**
10 * Converts class (constructor) object to plain (literal) object.
11 * Uses given plain object as source object (it means fills given plain object with data from class object).
12 * Also works with arrays.
13 */
14 classToPlainFromExist<T extends Record<string, any>, P>(object: T, plainObject: P, options?: ClassTransformOptions): T;
15 classToPlainFromExist<T extends Record<string, any>, P>(object: T, plainObjects: P[], options?: ClassTransformOptions): T[];
16 /**
17 * Converts plain (literal) object to class (constructor) object. Also works with arrays.
18 */
19 plainToInstance<T extends Record<string, any>, V extends Array<any>>(cls: ClassConstructor<T>, plain: V, options?: ClassTransformOptions): T[];
20 plainToInstance<T extends Record<string, any>, V>(cls: ClassConstructor<T>, plain: V, options?: ClassTransformOptions): T;
21 /**
22 * Converts plain (literal) object to class (constructor) object.
23 * Uses given object as source object (it means fills given object with data from plain object).
24 * Also works with arrays.
25 */
26 plainToClassFromExist<T extends Record<string, any>, V extends Array<any>>(clsObject: T, plain: V, options?: ClassTransformOptions): T;
27 plainToClassFromExist<T extends Record<string, any>, V>(clsObject: T, plain: V, options?: ClassTransformOptions): T[];
28 /**
29 * Converts class (constructor) object to new class (constructor) object. Also works with arrays.
30 */
31 instanceToInstance<T>(object: T, options?: ClassTransformOptions): T;
32 instanceToInstance<T>(object: T[], options?: ClassTransformOptions): T[];
33 /**
34 * Converts class (constructor) object to plain (literal) object.
35 * Uses given plain object as source object (it means fills given plain object with data from class object).
36 * Also works with arrays.
37 */
38 classToClassFromExist<T>(object: T, fromObject: T, options?: ClassTransformOptions): T;
39 classToClassFromExist<T>(object: T, fromObjects: T[], options?: ClassTransformOptions): T[];
40 /**
41 * Serializes given object to a JSON string.
42 */
43 serialize<T>(object: T, options?: ClassTransformOptions): string;
44 serialize<T>(object: T[], options?: ClassTransformOptions): string;
45 /**
46 * Deserializes given JSON string to a object of the given class.
47 */
48 deserialize<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T;
49 /**
50 * Deserializes given JSON string to an array of objects of the given class.
51 */
52 deserializeArray<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T[];
53}