Skip to content

Commit a5df6f1

Browse files
authored
Merge branch 'master' into master
2 parents 597a984 + c3d0030 commit a5df6f1

12 files changed

+211
-72
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: node_js
22
node_js:
33
- stable
4+
- 8
45
- 6
5-
- 5
6-
- 4
76

87
after_success:
98
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

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

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

225225
```typescript
226226
import {deserialize} from "class-transformer";
227-
let photo = deserialize(photo);
227+
let photo = deserialize(Photo, photo);
228228
```
229229

230230
To make deserialization to work with arrays use `deserializeArray` method:
231231

232232
```typescript
233233
import {deserializeArray} from "class-transformer";
234-
let photos = deserializeArray(photos);
234+
let photos = deserializeArray(Photo, photos);
235235
```
236236

237237
## Working with nested objects
@@ -658,7 +658,7 @@ the exposed variables. email property is also exposed becuase we metioned the gr
658658
## Working with generics
659659

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

doc/release-notes.md

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

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "class-transformer",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "Proper decorator-based transformation / serialization / deserialization of plain javascript objects to class constructors",
55
"license": "MIT",
66
"readmeFilename": "README.md",

src/TransformOperationExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class TransformOperationExecutor {
8080

8181
return new Date(value);
8282

83-
} else if (value instanceof Object) {
83+
} else if (typeof value === "object" && value !== null) {
8484

8585
// try to guess the type
8686
if (!targetType && value.constructor !== Object/* && TransformationType === TransformationType.CLASS_TO_PLAIN*/) targetType = value.constructor;

src/metadata/MetadataStorage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,19 @@ export class MetadataStorage {
146146

147147
private getMetadata<T extends { target: Function, propertyName: string }>(metadatas: T[], target: Function): T[] {
148148
const metadataFromTarget = metadatas.filter(meta => meta.target === target && meta.propertyName !== undefined);
149-
const metadataFromChildren = metadatas.filter(meta => target.prototype instanceof meta.target && meta.propertyName !== undefined);
149+
const metadataFromChildren = metadatas.filter(meta => target && target.prototype instanceof meta.target && meta.propertyName !== undefined);
150150
return metadataFromChildren.concat(metadataFromTarget);
151151
}
152152

153153
private findMetadata<T extends { target: Function, propertyName: string }>(metadatas: T[], target: Function, propertyName: string): T {
154154
const metadataFromTarget = metadatas.find(meta => meta.target === target && meta.propertyName === propertyName);
155-
const metadataFromChildren = metadatas.find(meta => target.prototype instanceof meta.target && meta.propertyName === propertyName);
155+
const metadataFromChildren = metadatas.find(meta => target && target.prototype instanceof meta.target && meta.propertyName === propertyName);
156156
return metadataFromTarget || metadataFromChildren;
157157
}
158158

159159
private findMetadatas<T extends { target: Function, propertyName: string }>(metadatas: T[], target: Function, propertyName: string): T[] {
160160
const metadataFromTarget = metadatas.filter(meta => meta.target === target && meta.propertyName === propertyName);
161-
const metadataFromChildren = metadatas.filter(meta => target.prototype instanceof meta.target && meta.propertyName === propertyName);
161+
const metadataFromChildren = metadatas.filter(meta => target && target.prototype instanceof meta.target && meta.propertyName === propertyName);
162162
return metadataFromChildren.reverse().concat(metadataFromTarget.reverse());
163163
}
164164

test/functional/basic-functionality.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ describe("basic functionality", () => {
15991599

16001600
});
16011601

1602-
it("should be able to transform array too", () => {
1602+
it("should transform array", () => {
16031603
defaultMetadataStorage.clear();
16041604

16051605

@@ -1725,4 +1725,17 @@ describe("basic functionality", () => {
17251725

17261726
});
17271727

1728+
it("should transform objects with null prototype", () => {
1729+
class TestClass {
1730+
prop: string;
1731+
}
1732+
1733+
const obj = Object.create(null);
1734+
obj.a = "JS FTW";
1735+
1736+
const transformedClass = plainToClass(TestClass, obj);
1737+
1738+
transformedClass.should.be.instanceOf(TestClass);
1739+
});
1740+
17281741
});

0 commit comments

Comments
 (0)