@@ -216,7 +216,7 @@ Now you can use `users[0].getName()` and `users[0].isAdult()` methods.
216
216
This method transforms a plain javascript object to instance of specific class.
217
217
218
218
``` typescript
219
- import { plainToClass } from ' class-transformer' ;
219
+ import { plainToClass } from ' @nestjs/ class-transformer' ;
220
220
221
221
let users = plainToClass (User , userJson ); // to convert user plain object a single user. also supports arrays
222
222
```
@@ -237,7 +237,7 @@ let mixedUser = plainToClassFromExist(defaultUser, user); // mixed user should h
237
237
This method transforms your class object back to plain javascript object, that can be ` JSON.stringify ` later.
238
238
239
239
``` typescript
240
- import { classToPlain } from ' class-transformer' ;
240
+ import { classToPlain } from ' @nestjs/ class-transformer' ;
241
241
let photo = classToPlain (photo );
242
242
```
243
243
@@ -247,7 +247,7 @@ This method transforms your class object into a new instance of the class object
247
247
This may be treated as deep clone of your objects.
248
248
249
249
``` typescript
250
- import { classToClass } from ' class-transformer' ;
250
+ import { classToClass } from ' @nestjs/ class-transformer' ;
251
251
let photo = classToClass (photo );
252
252
```
253
253
@@ -258,7 +258,7 @@ You can also use an `ignoreDecorators` option in transformation options to ignor
258
258
You can serialize your model right to json using ` serialize ` method:
259
259
260
260
``` typescript
261
- import { serialize } from ' class-transformer' ;
261
+ import { serialize } from ' @nestjs/ class-transformer' ;
262
262
let photo = serialize (photo );
263
263
```
264
264
@@ -269,14 +269,14 @@ let photo = serialize(photo);
269
269
You can deserialize your model from json using the ` deserialize ` method:
270
270
271
271
``` typescript
272
- import { deserialize } from ' class-transformer' ;
272
+ import { deserialize } from ' @nestjs/ class-transformer' ;
273
273
let photo = deserialize (Photo , photo );
274
274
```
275
275
276
276
To make deserialization work with arrays, use the ` deserializeArray ` method:
277
277
278
278
``` typescript
279
- import { deserializeArray } from ' class-transformer' ;
279
+ import { deserializeArray } from ' @nestjs/ class-transformer' ;
280
280
let photos = deserializeArray (Photo , photos );
281
281
```
282
282
@@ -286,7 +286,7 @@ The default behaviour of the `plainToClass` method is to set _all_ properties fr
286
286
even those which are not specified in the class.
287
287
288
288
``` typescript
289
- import { plainToClass } from ' class-transformer' ;
289
+ import { plainToClass } from ' @nestjs/ class-transformer' ;
290
290
291
291
class User {
292
292
id: number ;
@@ -313,7 +313,7 @@ If this behaviour does not suit your needs, you can use the `excludeExtraneousVa
313
313
in the ` plainToClass ` method while _ exposing all your class properties_ as a requirement.
314
314
315
315
``` typescript
316
- import { Expose , plainToClass } from ' class-transformer' ;
316
+ import { Expose , plainToClass } from ' @nestjs/ class-transformer' ;
317
317
318
318
class User {
319
319
@Expose () id: number ;
@@ -350,7 +350,7 @@ Lets say we have an album with photos.
350
350
And we are trying to convert album plain object to class object:
351
351
352
352
``` typescript
353
- import { Type , plainToClass } from ' class-transformer' ;
353
+ import { Type , plainToClass } from ' @nestjs/ class-transformer' ;
354
354
355
355
export class Album {
356
356
id: number ;
@@ -398,7 +398,7 @@ the additional property `__type`. This property is removed during transformation
398
398
```
399
399
400
400
``` typescript
401
- import { Type , plainToClass } from ' class-transformer' ;
401
+ import { Type , plainToClass } from ' @nestjs/ class-transformer' ;
402
402
403
403
export abstract class Photo {
404
404
id: number ;
@@ -446,7 +446,7 @@ in the options to keep the discriminator property also inside your resulting cla
446
446
You can expose what your getter or method return by setting an ` @Expose() ` decorator to those getters or methods:
447
447
448
448
``` typescript
449
- import { Expose } from ' class-transformer' ;
449
+ import { Expose } from ' @nestjs/ class-transformer' ;
450
450
451
451
export class User {
452
452
id: number ;
@@ -472,7 +472,7 @@ If you want to expose some of the properties with a different name,
472
472
you can do that by specifying a ` name ` option to ` @Expose ` decorator:
473
473
474
474
``` typescript
475
- import { Expose } from ' class-transformer' ;
475
+ import { Expose } from ' @nestjs/ class-transformer' ;
476
476
477
477
export class User {
478
478
@Expose ({ name: ' uid' })
@@ -498,7 +498,7 @@ Sometimes you want to skip some properties during transformation.
498
498
This can be done using ` @Exclude ` decorator:
499
499
500
500
``` typescript
501
- import { Exclude } from ' class-transformer' ;
501
+ import { Exclude } from ' @nestjs/ class-transformer' ;
502
502
503
503
export class User {
504
504
id: number ;
@@ -517,7 +517,7 @@ Now when you transform a User, the `password` property will be skipped and not b
517
517
You can control on what operation you will exclude a property. Use ` toClassOnly ` or ` toPlainOnly ` options:
518
518
519
519
``` typescript
520
- import { Exclude } from ' class-transformer' ;
520
+ import { Exclude } from ' @nestjs/ class-transformer' ;
521
521
522
522
export class User {
523
523
id: number ;
@@ -536,7 +536,7 @@ Now `password` property will be excluded only during `classToPlain` operation. V
536
536
You can skip all properties of the class, and expose only those are needed explicitly:
537
537
538
538
``` typescript
539
- import { Exclude , Expose } from ' class-transformer' ;
539
+ import { Exclude , Expose } from ' @nestjs/ class-transformer' ;
540
540
541
541
@Exclude ()
542
542
export class User {
@@ -554,7 +554,7 @@ Now `id` and `email` will be exposed, and password will be excluded during trans
554
554
Alternatively, you can set exclusion strategy during transformation:
555
555
556
556
``` typescript
557
- import { classToPlain } from ' class-transformer' ;
557
+ import { classToPlain } from ' @nestjs/ class-transformer' ;
558
558
let photo = classToPlain (photo , { strategy: ' excludeAll' });
559
559
```
560
560
@@ -566,7 +566,7 @@ If you name your private properties with a prefix, lets say with `_`,
566
566
then you can exclude such properties from transformation too:
567
567
568
568
``` typescript
569
- import { classToPlain } from ' class-transformer' ;
569
+ import { classToPlain } from ' @nestjs/ class-transformer' ;
570
570
let photo = classToPlain (photo , { excludePrefixes: [' _' ] });
571
571
```
572
572
@@ -575,7 +575,7 @@ You can pass any number of prefixes and all properties that begin with these pre
575
575
For example:
576
576
577
577
``` typescript
578
- import { Expose , classToPlain } from ' class-transformer' ;
578
+ import { Expose , classToPlain } from ' @nestjs/ class-transformer' ;
579
579
580
580
export class User {
581
581
id: number ;
@@ -609,7 +609,7 @@ const plainUser = classToPlain(user, { excludePrefixes: ['_'] });
609
609
You can use groups to control what data will be exposed and what will not be:
610
610
611
611
``` typescript
612
- import { Exclude , Expose , classToPlain } from ' class-transformer' ;
612
+ import { Exclude , Expose , classToPlain } from ' @nestjs/ class-transformer' ;
613
613
614
614
export class User {
615
615
id: number ;
@@ -633,7 +633,7 @@ If you are building an API that has different versions, class-transformer has ex
633
633
You can control which properties of your model should be exposed or excluded in what version. Example:
634
634
635
635
``` typescript
636
- import { Exclude , Expose , classToPlain } from ' class-transformer' ;
636
+ import { Exclude , Expose , classToPlain } from ' @nestjs/ class-transformer' ;
637
637
638
638
export class User {
639
639
id: number ;
@@ -661,7 +661,7 @@ And you want to create a real javascript Date object from it.
661
661
You can do it simply by passing a Date object to the ` @Type ` decorator:
662
662
663
663
``` typescript
664
- import { Type } from ' class-transformer' ;
664
+ import { Type } from ' @nestjs/ class-transformer' ;
665
665
666
666
export class User {
667
667
id: number ;
@@ -686,7 +686,7 @@ When you are using arrays you must provide a type of the object that array conta
686
686
This type, you specify in a ` @Type() ` decorator:
687
687
688
688
``` typescript
689
- import { Type } from ' class-transformer' ;
689
+ import { Type } from ' @nestjs/ class-transformer' ;
690
690
691
691
export class Photo {
692
692
id: number ;
@@ -701,7 +701,7 @@ export class Photo {
701
701
You can also use custom array types:
702
702
703
703
``` typescript
704
- import { Type } from ' class-transformer' ;
704
+ import { Type } from ' @nestjs/ class-transformer' ;
705
705
706
706
export class AlbumCollection extends Array <Album > {
707
707
// custom array functions ...
@@ -751,7 +751,7 @@ For example, you want to make your `Date` object to be a `moment` object when yo
751
751
transforming object from plain to class:
752
752
753
753
``` typescript
754
- import { Transform } from ' class-transformer' ;
754
+ import { Transform } from ' @nestjs/ class-transformer' ;
755
755
import * as moment from ' moment' ;
756
756
import { Moment } from ' moment' ;
757
757
@@ -883,7 +883,7 @@ Circular references are not ignored only during `classToClass` operation.
883
883
Lets say you want to download users and want them automatically to be mapped to the instances of ` User ` class.
884
884
885
885
``` typescript
886
- import { plainToClass } from ' class-transformer' ;
886
+ import { plainToClass } from ' @nestjs/ class-transformer' ;
887
887
888
888
this .http
889
889
.get (' users.json' )
0 commit comments