UNPKG

4.78 kBTypeScriptView Raw
1import { ClassTransformOptions } from './interfaces';
2import { ClassConstructor } from './interfaces';
3export { ClassTransformer } from './ClassTransformer';
4export * from './decorators';
5export * from './interfaces';
6export * from './enums';
7/**
8 * Converts class (constructor) object to plain (literal) object. Also works with arrays.
9 *
10 * @deprecated Function name changed, use the `instanceToPlain` method instead.
11 */
12export declare function classToPlain<T>(object: T, options?: ClassTransformOptions): Record<string, any>;
13export declare function classToPlain<T>(object: T[], options?: ClassTransformOptions): Record<string, any>[];
14/**
15 * Converts class (constructor) object to plain (literal) object. Also works with arrays.
16 */
17export declare function instanceToPlain<T>(object: T, options?: ClassTransformOptions): Record<string, any>;
18export declare function instanceToPlain<T>(object: T[], options?: ClassTransformOptions): Record<string, any>[];
19/**
20 * Converts class (constructor) object to plain (literal) object.
21 * Uses given plain object as source object (it means fills given plain object with data from class object).
22 * Also works with arrays.
23 *
24 * @deprecated This function is being removed.
25 */
26export declare function classToPlainFromExist<T>(object: T, plainObject: Record<string, any>, options?: ClassTransformOptions): Record<string, any>;
27export declare function classToPlainFromExist<T>(object: T, plainObjects: Record<string, any>[], options?: ClassTransformOptions): Record<string, any>[];
28/**
29 * Converts plain (literal) object to class (constructor) object. Also works with arrays.
30 *
31 * @deprecated Function name changed, use the `plainToInstance` method instead.
32 */
33export declare function plainToClass<T, V>(cls: ClassConstructor<T>, plain: V[], options?: ClassTransformOptions): T[];
34export declare function plainToClass<T, V>(cls: ClassConstructor<T>, plain: V, options?: ClassTransformOptions): T;
35/**
36 * Converts plain (literal) object to class (constructor) object. Also works with arrays.
37 */
38export declare function plainToInstance<T, V>(cls: ClassConstructor<T>, plain: V[], options?: ClassTransformOptions): T[];
39export declare function plainToInstance<T, V>(cls: ClassConstructor<T>, plain: V, options?: ClassTransformOptions): T;
40/**
41 * Converts plain (literal) object to class (constructor) object.
42 * Uses given object as source object (it means fills given object with data from plain object).
43 * Also works with arrays.
44 *
45 * @deprecated This function is being removed. The current implementation is incorrect as it modifies the source object.
46 */
47export declare function plainToClassFromExist<T, V>(clsObject: T[], plain: V[], options?: ClassTransformOptions): T[];
48export declare function plainToClassFromExist<T, V>(clsObject: T, plain: V, options?: ClassTransformOptions): T;
49/**
50 * Converts class (constructor) object to new class (constructor) object. Also works with arrays.
51 */
52export declare function instanceToInstance<T>(object: T, options?: ClassTransformOptions): T;
53export declare function instanceToInstance<T>(object: T[], options?: ClassTransformOptions): T[];
54/**
55 * Converts class (constructor) object to plain (literal) object.
56 * Uses given plain object as source object (it means fills given plain object with data from class object).
57 * Also works with arrays.
58 *
59 * @deprecated This function is being removed. The current implementation is incorrect as it modifies the source object.
60 */
61export declare function classToClassFromExist<T>(object: T, fromObject: T, options?: ClassTransformOptions): T;
62export declare function classToClassFromExist<T>(object: T, fromObjects: T[], options?: ClassTransformOptions): T[];
63/**
64 * Serializes given object to a JSON string.
65 *
66 * @deprecated This function is being removed. Please use
67 * ```
68 * JSON.stringify(instanceToPlain(object, options))
69 * ```
70 */
71export declare function serialize<T>(object: T, options?: ClassTransformOptions): string;
72export declare function serialize<T>(object: T[], options?: ClassTransformOptions): string;
73/**
74 * Deserializes given JSON string to a object of the given class.
75 *
76 * @deprecated This function is being removed. Please use the following instead:
77 * ```
78 * instanceToClass(cls, JSON.parse(json), options)
79 * ```
80 */
81export declare function deserialize<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T;
82/**
83 * Deserializes given JSON string to an array of objects of the given class.
84 *
85 * @deprecated This function is being removed. Please use the following instead:
86 * ```
87 * JSON.parse(json).map(value => instanceToClass(cls, value, options))
88 * ```
89 *
90 */
91export declare function deserializeArray<T>(cls: ClassConstructor<T>, json: string, options?: ClassTransformOptions): T[];