Skip to content

Commit 6001fae

Browse files
author
Umed Khudoiberdiev
committed
updated readme
1 parent 6292d72 commit 6001fae

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Now you can use `users[0].getName()` and `users[0].isAdult()` methods.
175175
}
176176
```
177177

178-
### Methods
178+
## Methods
179179

180180
#### plainToClass
181181

@@ -235,7 +235,7 @@ import {deserializeArray} from "class-transformer";
235235
let photos = deserializeArray(photos);
236236
```
237237

238-
### Working with nested objects
238+
## Working with nested objects
239239

240240
When you are trying to transform objects that have nested objects,
241241
its required to known what type of object you are trying to transform.
@@ -268,7 +268,7 @@ let album = plainToClass(Album, albumJson);
268268
// now album is Album object with Photo objects inside
269269
```
270270

271-
### Exposing getters and method return values
271+
## Exposing getters and method return values
272272

273273
You can expose what your getter or method return by setting a `@Expose()` decorator to those getters or methods:
274274

@@ -294,7 +294,7 @@ export class User {
294294
}
295295
```
296296

297-
### Exposing properties with different names
297+
## Exposing properties with different names
298298

299299
If you want to expose some of properties with a different name,
300300
you can do it by specifying a `name` option to `@Expose` decorator:
@@ -321,7 +321,7 @@ export class User {
321321
}
322322
```
323323

324-
### Skipping specific properties
324+
## Skipping specific properties
325325

326326
Sometimes you want to skip some properties during transformation.
327327
This can be done using `@Exclude` decorator:
@@ -342,7 +342,7 @@ export class User {
342342

343343
Now when you transform a User, `password` property will be skipped and not be included in the transformed result.
344344

345-
### Skipping depend of operation
345+
## Skipping depend of operation
346346

347347
You can control on what operation you will exclude a property. Use `toClassOnly` or `toPlainOnly` options:
348348

@@ -362,7 +362,7 @@ export class User {
362362

363363
Now `password` property will be excluded only during `classToPlain` operation. Oppositely, use `toClassOnly` option.
364364

365-
### Skipping all properties of the class
365+
## Skipping all properties of the class
366366

367367
You can skip all properties of the class, and expose only those are needed explicitly:
368368

@@ -392,7 +392,7 @@ let photo = classToPlain(photo, { strategy: "excludeAll" });
392392

393393
In this case you don't need to `@Exclude()` a whole class.
394394

395-
### Skipping private properties, or some prefixed properties
395+
## Skipping private properties, or some prefixed properties
396396

397397
If you name your private properties with a prefix, lets say with `_`,
398398
then you can exclude such properties from transformation too:
@@ -438,7 +438,7 @@ const plainUser = classToPlain(user, { excludePrefixes: ["_"] });
438438
// { id: 1, name: "Johny Cage" }
439439
```
440440

441-
### Using groups to control excluded properties
441+
## Using groups to control excluded properties
442442

443443
You can use groups to control what data will be exposed and what will not be:
444444

@@ -466,7 +466,7 @@ let user1 = classToPlain(user, { groups: ["user"] }); // will contain id, name,
466466
let user2 = classToPlain(user, { groups: ["admin"] }); // will contain id, name and email
467467
```
468468

469-
### Using versioning to control exposed and excluded properties
469+
## Using versioning to control exposed and excluded properties
470470

471471
If you are building an API that has different versions, class-transformer has extremely useful tools for that.
472472
You can control which properties of your model should be exposed or excluded in what version. Example:
@@ -498,7 +498,7 @@ let user4 = classToPlain(user, { version: 2 }); // will contain id and name
498498
let user5 = classToPlain(user, { version: 2.1 }); // will contain id, name nad password
499499
```
500500

501-
### Сonverting date strings into Date objects
501+
## Сonverting date strings into Date objects
502502

503503
Sometimes you have a Date in your plain javascript object received in a string format.
504504
And you want to create a real javascript Date object from it.
@@ -525,7 +525,7 @@ Note, that dates will be converted to strings when you'll try to convert class o
525525
Same technique can be used with `Number`, `String`, `Boolean`
526526
primitive types when you want to convert your values into these types.
527527

528-
### Working with arrays
528+
## Working with arrays
529529

530530
When you are using arrays you must provide a type of the object that array contains.
531531
This type, you specify in a `@Type()` decorator:
@@ -566,7 +566,7 @@ export class Photo {
566566

567567
Library will handle proper transformation automatically.
568568

569-
### Additional data transformation
569+
## Additional data transformation
570570

571571
You can perform additional data transformation using `@Transform` decorator.
572572
For example, you want to make your `Date` object to be a `moment` object when you are
@@ -590,14 +590,14 @@ Now when you call `plainToClass` and send a plain representation of the Photo ob
590590
it will convert a date value in your photo object to moment date.
591591
`@Transform` decorator also supports groups and versioning.
592592

593-
### Working with generics
593+
## Working with generics
594594

595595
Generics are not supported because TypeScript does not have good reflection abilities yet.
596596
Once TypeScript team provide us better runtime type reelection tools, generics will be implemented.
597597
There are some tweaks however you can use, that maybe can solve your problem.
598598
[Checkout this example.](https://github.com/pleerock/class-transformer/tree/master/sample/sample4-generics)
599599

600-
### How does it handle circular references?
600+
## How does it handle circular references?
601601

602602
Circular references are ignored.
603603
For example, if you are transforming class `User` that contains property `photos` with type of `Photo`,

0 commit comments

Comments
 (0)