Skip to content

Commit 0e11a85

Browse files
authored
Merge branch 'develop' into feat/transform-plain-to-class
2 parents c5a8207 + 6f2b341 commit 0e11a85

18 files changed

+6480
-168
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
language: node_js
22
node_js:
33
- stable
4+
- 8
45
- 6
5-
- 5
6-
- 4
7-
- 0.12
8-
- 0.11
96

107
after_success:
11-
- bash <(curl -s https://codecov.io/bash)
8+
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Changelog and release notes
2+
3+
### 0.1.10
4+
5+
#### Fixed
6+
7+
- improve MetadataStorage perf by changing from Arrays to ES6 Maps by @sheiidan
8+
- fixed getAncestor issue with unknown nested properties by @247GradLabs
9+
10+
### 0.1.9
11+
12+
#### Fixed
13+
14+
- objects with `null` prototype are converted properly now
15+
- objects with unknown non primitive properties are converted properly now
16+
- corrected a typo in the README.md
17+
- fixed the deserialize example in the README.md
18+
19+
### 0.1.4
20+
21+
#### Added
22+
23+
- added `TransformClassToPlain` and `TransformClassToClass` decorators
24+
25+
### 0.1.0
26+
27+
#### Added
28+
29+
- renamed library from `constructor-utils` to `class-transformer`
30+
- completely renamed most of names
31+
- renamed all main methods: `plainToConstructor` now is `plainToClass` and `constructorToPlain` is `classToPlain`, etc.
32+
- `plainToConstructorArray` method removed - now `plainToClass` handles it
33+
- `@Skip()` decorator renamed to `@Exclude()`
34+
- added `@Expose` decorator
35+
- added lot of new options: groups, versioning, custom names, etc.
36+
- methods and getters that should be exposed must be decorated with `@Expose` decorator
37+
- added `excludedPrefix` to class transform options that allows exclude properties that start with one of the given prefix
38+
39+
### 0.0.22
40+
41+
#### Fixed
42+
43+
- fixed array with primitive types being converted
44+
45+
### 0.0.18-0.0.21
46+
47+
#### Fixed
48+
49+
- fixed bugs when getters are not converted with es6 target
50+
51+
### 0.0.17
52+
53+
#### Fixed
54+
55+
- fixed issue #4
56+
- added type guessing during transformation from constructor to plain object
57+
- added sample with generics
58+
59+
### 0.0.16
60+
61+
#### Changed
62+
63+
- renamed `constructor-utils/constructor-utils` to `constructor-utils` package namespace
64+
65+
### 0.0.15
66+
67+
#### Removed
68+
69+
- removed code mappings from package
70+
71+
### 0.0.14
72+
73+
#### Removed
74+
75+
- removed `import "reflect-metadata"` from source code. Now reflect metadata should be included like any other shims.
76+
77+
### 0.0.13
78+
79+
#### Changed
80+
81+
- Library has changed its name from `serializer.ts` to `constructor-utils`.
82+
- Added `constructor-utils` namespace.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2015-2016 Umed Khudoiberdiev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# class-transformer
22

3-
[![Build Status](https://travis-ci.org/pleerock/class-transformer.svg?branch=master)](https://travis-ci.org/pleerock/class-transformer)
4-
[![codecov](https://codecov.io/gh/pleerock/class-transformer/branch/master/graph/badge.svg)](https://codecov.io/gh/pleerock/class-transformer)
3+
[![Build Status](https://travis-ci.org/typestack/class-transformer.svg?branch=master)](https://travis-ci.org/typestack/class-transformer)
4+
[![codecov](https://codecov.io/gh/typestack/class-transformer/branch/master/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)
6-
[![Dependency Status](https://david-dm.org/pleerock/class-transformer.svg)](https://david-dm.org/pleerock/class-transformer)
7-
[![devDependency Status](https://david-dm.org/pleerock/class-transformer/dev-status.svg)](https://david-dm.org/pleerock/class-transformer#info=devDependencies)
8-
[![Join the chat at https://gitter.im/pleerock/class-transformer](https://badges.gitter.im/pleerock/class-transformer.svg)](https://gitter.im/pleerock/class-transformer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6+
[![Dependency Status](https://david-dm.org/typestack/class-transformer.svg)](https://david-dm.org/typestack/class-transformer)
7+
[![Join the chat at https://gitter.im/typestack/class-transformer](https://badges.gitter.im/typestack/class-transformer.svg)](https://gitter.im/typestack/class-transformer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
98

109
Its ES6 and Typescript era. Nowadays you are working with classes and constructor objects more then ever.
1110
Class-transformer allows you to transform plain object to some instance of class and versa.
@@ -225,14 +224,14 @@ You can deserialize your model to from a json using `deserialize` method:
225224

226225
```typescript
227226
import {deserialize} from "class-transformer";
228-
let photo = deserialize(photo);
227+
let photo = deserialize(Photo, photo);
229228
```
230229

231230
To make deserialization to work with arrays use `deserializeArray` method:
232231

233232
```typescript
234233
import {deserializeArray} from "class-transformer";
235-
let photos = deserializeArray(photos);
234+
let photos = deserializeArray(Photo, photos);
236235
```
237236

238237
## Working with nested objects
@@ -566,8 +565,33 @@ export class Photo {
566565

567566
Library will handle proper transformation automatically.
568567

568+
ES6 collections `Set` and `Map` also require the `@Type` decorator:
569+
570+
```typescript
571+
export class Skill {
572+
name: string;
573+
}
574+
575+
export class Weapon {
576+
name: string;
577+
range: number;
578+
}
579+
580+
export class Player {
581+
name: string;
582+
583+
@Type(() => Skill)
584+
skills: Set<Skill>;
585+
586+
@Type(() => Weapon)
587+
weapons: Map<string, Weapon>;
588+
}
589+
```
590+
569591
## Additional data transformation
570592

593+
### Basic usage
594+
571595
You can perform additional data transformation using `@Transform` decorator.
572596
For example, you want to make your `Date` object to be a `moment` object when you are
573597
transforming object from plain to class:
@@ -591,6 +615,20 @@ Now when you call `plainToClass` and send a plain representation of the Photo ob
591615
it will convert a date value in your photo object to moment date.
592616
`@Transform` decorator also supports groups and versioning.
593617

618+
### Advanced usage
619+
620+
The `@Transform` decorator is given more arguments to let you configure how you want the transformation to be done.
621+
622+
```
623+
@Transform((value, obj, type) => value)
624+
```
625+
626+
| Argument | Description
627+
|--------------------|---------------------------------------------------------------------------------|
628+
| `value` | The property value before the transformation.
629+
| `obj` | The transformation source object.
630+
| `type` | The transformation type.
631+
594632
## Other decorators
595633
| Signature | Example | Description
596634
|--------------------|------------------------------------------|---------------------------------------------|
@@ -644,7 +682,7 @@ the exposed variables. email property is also exposed becuase we metioned the gr
644682
## Working with generics
645683

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

@@ -667,7 +705,7 @@ this.http
667705
.map(res => res.json())
668706
.map(res => plainToClass(User, res as Object[]))
669707
.subscribe(users => {
670-
// now "users" is type of User[] and each user have getName() and isAdult() methods available
708+
// now "users" is type of User[] and each user has getName() and isAdult() methods available
671709
console.log(users);
672710
});
673711
```

doc/release-notes.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)