Skip to content

Commit 2f6565a

Browse files
authored
docs: add links to top with jump2header (#411)
1 parent 11c4cc9 commit 2f6565a

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

README.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This tool is super useful on both frontend and backend.
1212
Example how to use with angular 2 in [plunker](http://plnkr.co/edit/Mja1ZYAjVySWASMHVB9R).
1313
Source code is available [here](https://github.com/pleerock/class-transformer-demo).
1414

15+
## Table of contents
16+
1517
- [What is class-transformer](#what-is-class-transformer)
1618
- [Installation](#installation)
1719
- [Node.js](#nodejs)
@@ -47,7 +49,7 @@ Source code is available [here](https://github.com/pleerock/class-transformer-de
4749
- [Samples](#samples)
4850
- [Release notes](#release-notes)
4951

50-
## What is class-transformer
52+
## What is class-transformer[](#table-of-contents)
5153

5254
In JavaScript there are two types of objects:
5355

@@ -145,9 +147,9 @@ fetch('users.json').then((users: Object[]) => {
145147

146148
Now you can use `users[0].getName()` and `users[0].isAdult()` methods.
147149

148-
## Installation
150+
## Installation[](#table-of-contents)
149151

150-
### Node.js
152+
### Node.js[](#table-of-contents)
151153

152154
1. Install module:
153155

@@ -173,7 +175,7 @@ Now you can use `users[0].getName()` and `users[0].isAdult()` methods.
173175
import 'es6-shim';
174176
```
175177

176-
### Browser
178+
### Browser[](#table-of-contents)
177179

178180
1. Install module:
179181

@@ -210,9 +212,9 @@ Now you can use `users[0].getName()` and `users[0].isAdult()` methods.
210212
}
211213
```
212214

213-
## Methods
215+
## Methods[](#table-of-contents)
214216

215-
### plainToClass
217+
### plainToClass[](#table-of-contents)
216218

217219
This method transforms a plain javascript object to instance of specific class.
218220

@@ -222,7 +224,7 @@ import { plainToClass } from 'class-transformer';
222224
let users = plainToClass(User, userJson); // to convert user plain object a single user. also supports arrays
223225
```
224226

225-
### plainToClassFromExist
227+
### plainToClassFromExist[](#table-of-contents)
226228

227229
This method transforms a plain object into a instance using a already filled Object which is a instance from the target class.
228230

@@ -233,7 +235,7 @@ defaultUser.role = 'user';
233235
let mixedUser = plainToClassFromExist(defaultUser, user); // mixed user should have the value role = user when no value is set otherwise.
234236
```
235237

236-
### classToPlain
238+
### classToPlain[](#table-of-contents)
237239

238240
This method transforms your class object back to plain javascript object, that can be `JSON.stringify` later.
239241

@@ -242,7 +244,7 @@ import { classToPlain } from 'class-transformer';
242244
let photo = classToPlain(photo);
243245
```
244246

245-
### classToClass
247+
### classToClass[](#table-of-contents)
246248

247249
This method transforms your class object into new instance of the class object.
248250
This maybe treated as deep clone of your objects.
@@ -254,7 +256,7 @@ let photo = classToClass(photo);
254256

255257
You can also use a `ignoreDecorators` option in transformation options to ignore all decorators you classes is using.
256258

257-
### serialize
259+
### serialize[](#table-of-contents)
258260

259261
You can serialize your model right to the json using `serialize` method:
260262

@@ -265,7 +267,7 @@ let photo = serialize(photo);
265267

266268
`serialize` works with both arrays and non-arrays.
267269

268-
### deserialize and deserializeArray
270+
### deserialize and deserializeArray[](#table-of-contents)
269271

270272
You can deserialize your model to from a json using `deserialize` method:
271273

@@ -281,7 +283,7 @@ import { deserializeArray } from 'class-transformer';
281283
let photos = deserializeArray(Photo, photos);
282284
```
283285

284-
## Enforcing type-safe instance
286+
## Enforcing type-safe instance[](#table-of-contents)
285287

286288
The default behaviour of the `plainToClass` method is to set _all_ properties from the plain object,
287289
even those which are not specified in the class.
@@ -337,7 +339,7 @@ console.log(plainToClass(User, fromPlainUser, { excludeExtraneousValues: true })
337339
// }
338340
```
339341

340-
## Working with nested objects
342+
## Working with nested objects[](#table-of-contents)
341343

342344
When you are trying to transform objects that have nested objects,
343345
its required to known what type of object you are trying to transform.
@@ -369,7 +371,7 @@ let album = plainToClass(Album, albumJson);
369371
// now album is Album object with Photo objects inside
370372
```
371373

372-
### Providing more than one type option
374+
### Providing more than one type option[](#table-of-contents)
373375

374376
In case the nested object can be of different types, you can provide an additional options object,
375377
that specifies a discriminator. The discriminator option must define a `property` that holds the sub
@@ -440,7 +442,7 @@ let album = plainToClass(Album, albumJson);
440442
Hint: The same applies for arrays with different sub types. Moreover you can specify `keepDiscriminatorProperty: true`
441443
in the options to keep the discriminator property also inside your resulting class.
442444

443-
## Exposing getters and method return values
445+
## Exposing getters and method return values[](#table-of-contents)
444446

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

@@ -465,7 +467,7 @@ export class User {
465467
}
466468
```
467469

468-
## Exposing properties with different names
470+
## Exposing properties with different names[](#table-of-contents)
469471

470472
If you want to expose some of properties with a different name,
471473
you can do it by specifying a `name` option to `@Expose` decorator:
@@ -491,7 +493,7 @@ export class User {
491493
}
492494
```
493495

494-
## Skipping specific properties
496+
## Skipping specific properties[](#table-of-contents)
495497

496498
Sometimes you want to skip some properties during transformation.
497499
This can be done using `@Exclude` decorator:
@@ -511,7 +513,7 @@ export class User {
511513

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

514-
## Skipping depend of operation
516+
## Skipping depend of operation[](#table-of-contents)
515517

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

@@ -530,7 +532,7 @@ export class User {
530532

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

533-
## Skipping all properties of the class
535+
## Skipping all properties of the class[](#table-of-contents)
534536

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

@@ -559,7 +561,7 @@ let photo = classToPlain(photo, { strategy: 'excludeAll' });
559561

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

562-
## Skipping private properties, or some prefixed properties
564+
## Skipping private properties, or some prefixed properties[](#table-of-contents)
563565

564566
If you name your private properties with a prefix, lets say with `_`,
565567
then you can exclude such properties from transformation too:
@@ -603,7 +605,7 @@ const plainUser = classToPlain(user, { excludePrefixes: ['_'] });
603605
// { id: 1, name: "Johny Cage" }
604606
```
605607

606-
## Using groups to control excluded properties
608+
## Using groups to control excluded properties[](#table-of-contents)
607609

608610
You can use groups to control what data will be exposed and what will not be:
609611

@@ -626,7 +628,7 @@ let user1 = classToPlain(user, { groups: ['user'] }); // will contain id, name,
626628
let user2 = classToPlain(user, { groups: ['admin'] }); // will contain id, name and email
627629
```
628630

629-
## Using versioning to control exposed and excluded properties
631+
## Using versioning to control exposed and excluded properties[](#table-of-contents)
630632

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

656-
## Сonverting date strings into Date objects
658+
## Сonverting date strings into Date objects[](#table-of-contents)
657659

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

682-
## Working with arrays
684+
## Working with arrays[](#table-of-contents)
683685

684686
When you are using arrays you must provide a type of the object that array contains.
685687
This type, you specify in a `@Type()` decorator:
@@ -741,9 +743,9 @@ export class Player {
741743
}
742744
```
743745

744-
## Additional data transformation
746+
## Additional data transformation[](#table-of-contents)
745747

746-
### Basic usage
748+
### Basic usage[](#table-of-contents)
747749

748750
You can perform additional data transformation using `@Transform` decorator.
749751
For example, you want to make your `Date` object to be a `moment` object when you are
@@ -767,7 +769,7 @@ Now when you call `plainToClass` and send a plain representation of the Photo ob
767769
it will convert a date value in your photo object to moment date.
768770
`@Transform` decorator also supports groups and versioning.
769771

770-
### Advanced usage
772+
### Advanced usage[](#table-of-contents)
771773

772774
The `@Transform` decorator is given more arguments to let you configure how you want the transformation to be done.
773775

@@ -781,7 +783,7 @@ The `@Transform` decorator is given more arguments to let you configure how you
781783
| `obj` | The transformation source object. |
782784
| `type` | The transformation type. |
783785

784-
## Other decorators
786+
## Other decorators[](#table-of-contents)
785787

786788
| Signature | Example | Description |
787789
| ------------------------ | ---------------------------------------------------- | ------------------------------------------------------------------------------------- |
@@ -830,14 +832,14 @@ const user = controller.getUser();
830832
the `user` variable will contain only firstName,lastName, email properties becuase they are
831833
the exposed variables. email property is also exposed becuase we metioned the group "user.email".
832834

833-
## Working with generics
835+
## Working with generics[](#table-of-contents)
834836

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

840-
## Implicit type conversion
842+
## Implicit type conversion[](#table-of-contents)
841843

842844
> **NOTE** If you use class-validator together with class-transformer you propably DON'T want to enable this function.
843845
@@ -860,14 +862,14 @@ const result2 = plainToClass(MyPayload, { prop: 1234 }, { enableImplicitConversi
860862
*/
861863
```
862864

863-
## How does it handle circular references?
865+
## How does it handle circular references?[](#table-of-contents)
864866

865867
Circular references are ignored.
866868
For example, if you are transforming class `User` that contains property `photos` with type of `Photo`,
867869
and `Photo` contains link `user` to its parent `User`, then `user` will be ignored during transformation.
868870
Circular references are not ignored only during `classToClass` operation.
869871

870-
## Example with Angular2
872+
## Example with Angular2[](#table-of-contents)
871873

872874
Lets say you want to download users and want them automatically to be mapped to the instances of `User` class.
873875

@@ -889,11 +891,11 @@ You can also inject a class `ClassTransformer` as a service in `providers`, and
889891
Example how to use with angular 2 in [plunker](http://plnkr.co/edit/Mja1ZYAjVySWASMHVB9R).
890892
Source code is [here](https://github.com/pleerock/class-transformer-demo).
891893

892-
## Samples
894+
## Samples[](#table-of-contents)
893895

894896
Take a look on samples in [./sample](https://github.com/pleerock/class-transformer/tree/master/sample) for more examples of
895897
usages.
896898

897-
## Release notes
899+
## Release notes[](#table-of-contents)
898900

899901
See information about breaking changes and release notes [here](https://github.com/typestack/class-transformer/blob/master/CHANGELOG.md).

0 commit comments

Comments
 (0)