44[ ![ codecov] ( https://codecov.io/gh/typestack/class-transformer/branch/develop/graph/badge.svg )] ( https://codecov.io/gh/typestack/class-transformer )
55[ ![ npm version] ( https://badge.fury.io/js/class-transformer.svg )] ( https://badge.fury.io/js/class-transformer )
66
7- Its ES6 and Typescript era. Nowadays you are working with classes and constructor objects more then ever.
7+ Its ES6 and Typescript era. Nowadays you are working with classes and constructor objects more than ever.
88Class-transformer allows you to transform plain object to some instance of class and versa.
99Also it allows to serialize / deserialize object based on criteria.
1010This tool is super useful on both frontend and backend.
@@ -131,17 +131,17 @@ So what to do? How to make a `users` array of instances of `User` objects instea
131131Solution is to create new instances of User object and manually copy all properties to new objects.
132132But things may go wrong very fast once you have a more complex object hierarchy.
133133
134- Alternatives? Yes, you can use class-transformer. Purpose of this library is to help you to map you plain javascript
134+ Alternatives? Yes, you can use class-transformer. Purpose of this library is to help you to map your plain javascript
135135objects to the instances of classes you have.
136136
137137This library also great for models exposed in your APIs,
138138because it provides a great tooling to control what your models are exposing in your API.
139- Here is example how it will look like:
139+ Here is an example how it will look like:
140140
141141``` typescript
142142fetch (' users.json' ).then ((users : Object []) => {
143143 const realUsers = plainToClass (User , users );
144- // now each user in realUsers is instance of User class
144+ // now each user in realUsers is an instance of User class
145145});
146146```
147147
@@ -226,7 +226,7 @@ let users = plainToClass(User, userJson); // to convert user plain object a sing
226226
227227### plainToClassFromExist[ ⬆] ( #table-of-contents )
228228
229- This method transforms a plain object into a instance using a already filled Object which is a instance from the target class.
229+ This method transforms a plain object into an instance using an already filled Object which is an instance of the target class.
230230
231231``` typescript
232232const defaultUser = new User ();
@@ -246,19 +246,19 @@ let photo = classToPlain(photo);
246246
247247### classToClass[ ⬆] ( #table-of-contents )
248248
249- This method transforms your class object into new instance of the class object.
250- This maybe treated as deep clone of your objects.
249+ This method transforms your class object into a new instance of the class object.
250+ This may be treated as deep clone of your objects.
251251
252252``` typescript
253253import { classToClass } from ' class-transformer' ;
254254let photo = classToClass (photo );
255255```
256256
257- You can also use a ` ignoreDecorators ` option in transformation options to ignore all decorators you classes is using.
257+ You can also use an ` ignoreDecorators ` option in transformation options to ignore all decorators you classes is using.
258258
259259### serialize[ ⬆] ( #table-of-contents )
260260
261- You can serialize your model right to the json using ` serialize ` method:
261+ You can serialize your model right to json using ` serialize ` method:
262262
263263``` typescript
264264import { serialize } from ' class-transformer' ;
@@ -269,14 +269,14 @@ let photo = serialize(photo);
269269
270270### deserialize and deserializeArray[ ⬆] ( #table-of-contents )
271271
272- You can deserialize your model to from a json using ` deserialize ` method:
272+ You can deserialize your model from json using the ` deserialize ` method:
273273
274274``` typescript
275275import { deserialize } from ' class-transformer' ;
276276let photo = deserialize (Photo , photo );
277277```
278278
279- To make deserialization to work with arrays use ` deserializeArray ` method:
279+ To make deserialization work with arrays, use the ` deserializeArray ` method:
280280
281281``` typescript
282282import { deserializeArray } from ' class-transformer' ;
@@ -342,7 +342,7 @@ console.log(plainToClass(User, fromPlainUser, { excludeExtraneousValues: true })
342342## Working with nested objects[ ⬆] ( #table-of-contents )
343343
344344When you are trying to transform objects that have nested objects,
345- its required to known what type of object you are trying to transform.
345+ it's required to known what type of object you are trying to transform.
346346Since Typescript does not have good reflection abilities yet,
347347we should implicitly specify what type of object each property contain.
348348This is done using ` @Type ` decorator.
@@ -374,8 +374,8 @@ let album = plainToClass(Album, albumJson);
374374### Providing more than one type option[ ⬆] ( #table-of-contents )
375375
376376In case the nested object can be of different types, you can provide an additional options object,
377- that specifies a discriminator. The discriminator option must define a ` property ` that holds the sub
378- type name for the object and the possible ` subTypes ` , the nested object can converted to. A sub type
377+ that specifies a discriminator. The discriminator option must define a ` property ` that holds the subtype
378+ name for the object and the possible ` subTypes ` that the nested object can converted to. A sub type
379379has a ` value ` , that holds the constructor of the Type and the ` name ` , that can match with the ` property `
380380of the discriminator.
381381
@@ -444,7 +444,7 @@ in the options to keep the discriminator property also inside your resulting cla
444444
445445## Exposing getters and method return values[ ⬆] ( #table-of-contents )
446446
447- You can expose what your getter or method return by setting a ` @Expose() ` decorator to those getters or methods:
447+ You can expose what your getter or method return by setting an ` @Expose() ` decorator to those getters or methods:
448448
449449``` typescript
450450import { Expose } from ' class-transformer' ;
@@ -469,8 +469,8 @@ export class User {
469469
470470## Exposing properties with different names[ ⬆] ( #table-of-contents )
471471
472- If you want to expose some of properties with a different name,
473- you can do it by specifying a ` name ` option to ` @Expose ` decorator:
472+ If you want to expose some of the properties with a different name,
473+ you can do that by specifying a ` name ` option to ` @Expose ` decorator:
474474
475475``` typescript
476476import { Expose } from ' class-transformer' ;
@@ -511,7 +511,7 @@ export class User {
511511}
512512```
513513
514- Now when you transform a User, ` password ` property will be skipped and not be included in the transformed result.
514+ Now when you transform a User, the ` password ` property will be skipped and not be included in the transformed result.
515515
516516## Skipping depend of operation[ ⬆] ( #table-of-contents )
517517
@@ -530,7 +530,7 @@ export class User {
530530}
531531```
532532
533- Now ` password ` property will be excluded only during ` classToPlain ` operation. Oppositely , use ` toClassOnly ` option.
533+ Now ` password ` property will be excluded only during ` classToPlain ` operation. Vice versa , use the ` toClassOnly ` option.
534534
535535## Skipping all properties of the class[ ⬆] ( #table-of-contents )
536536
@@ -760,7 +760,7 @@ export class Photo {
760760 id: number ;
761761
762762 @Type (() => Date )
763- @Transform (value => moment (value ), { toClassOnly: true })
763+ @Transform (({ value }) => moment (value ), { toClassOnly: true })
764764 date: Moment ;
765765}
766766```
@@ -773,15 +773,17 @@ it will convert a date value in your photo object to moment date.
773773
774774The ` @Transform ` decorator is given more arguments to let you configure how you want the transformation to be done.
775775
776- ```
777- @Transform((value, obj, type) => value)
776+ ``` ts
777+ @Transform (({ value , key , obj , type } ) => value )
778778```
779779
780- | Argument | Description |
781- | -------- | --------------------------------------------- |
782- | ` value ` | The property value before the transformation. |
783- | ` obj ` | The transformation source object. |
784- | ` type ` | The transformation type. |
780+ | Argument | Description |
781+ | --------- | ------------------------------------------------------- |
782+ | ` value ` | The property value before the transformation. |
783+ | ` key ` | The name of the transformed property. |
784+ | ` obj ` | The transformation source object. |
785+ | ` type ` | The transformation type. |
786+ | ` options ` | The options object passed to the transformation method. |
785787
786788## Other decorators[ ⬆] ( #table-of-contents )
787789
0 commit comments