Skip to content

Commit f6413c9

Browse files
refactor: format code with prettier (#379)
1 parent a797726 commit f6413c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6204
-6057
lines changed

CHANGELOG.md

+31-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Changelog and release notes
22

3-
43
### 0.2.3 [BREAKING CHANGE]
54

65
#### Changed
@@ -24,97 +23,97 @@ This version has introduced a breaking-change when this library is used with cla
2423
2524
#### Added
2625

27-
- add option to strip unkown properties via using the `excludeExtraneousValues` option
26+
- add option to strip unkown properties via using the `excludeExtraneousValues` option
2827

2928
### 0.2.0 [BREAKING CHANGE]
3029

3130
#### Added
3231

33-
- add documentation for using `Set`s and `Map`s
34-
- add opotion to pass a discriminator function to convert values into different types based on custom conditions
35-
- added support for polymorphism based on a named type property
32+
- add documentation for using `Set`s and `Map`s
33+
- add opotion to pass a discriminator function to convert values into different types based on custom conditions
34+
- added support for polymorphism based on a named type property
3635

3736
#### Fixed
3837

39-
- fix bug when transforming `null` values as primitives
38+
- fix bug when transforming `null` values as primitives
4039

4140
### 0.1.10
4241

4342
#### Fixed
4443

45-
- improve MetadataStorage perf by changing from Arrays to ES6 Maps by @sheiidan
46-
- fixed getAncestor issue with unknown nested properties by @247GradLabs
44+
- improve MetadataStorage perf by changing from Arrays to ES6 Maps by @sheiidan
45+
- fixed getAncestor issue with unknown nested properties by @247GradLabs
4746

4847
### 0.1.9
4948

5049
#### Fixed
5150

52-
- objects with `null` prototype are converted properly now
53-
- objects with unknown non primitive properties are converted properly now
54-
- corrected a typo in the README.md
55-
- fixed the deserialize example in the README.md
51+
- objects with `null` prototype are converted properly now
52+
- objects with unknown non primitive properties are converted properly now
53+
- corrected a typo in the README.md
54+
- fixed the deserialize example in the README.md
5655

5756
### 0.1.4
5857

5958
#### Added
6059

61-
- added `TransformClassToPlain` and `TransformClassToClass` decorators
60+
- added `TransformClassToPlain` and `TransformClassToClass` decorators
6261

6362
### 0.1.0
6463

6564
#### Added
6665

67-
- renamed library from `constructor-utils` to `class-transformer`
68-
- completely renamed most of names
69-
- renamed all main methods: `plainToConstructor` now is `plainToClass` and `constructorToPlain` is `classToPlain`, etc.
70-
- `plainToConstructorArray` method removed - now `plainToClass` handles it
71-
- `@Skip()` decorator renamed to `@Exclude()`
72-
- added `@Expose` decorator
73-
- added lot of new options: groups, versioning, custom names, etc.
74-
- methods and getters that should be exposed must be decorated with `@Expose` decorator
75-
- added `excludedPrefix` to class transform options that allows exclude properties that start with one of the given prefix
66+
- renamed library from `constructor-utils` to `class-transformer`
67+
- completely renamed most of names
68+
- renamed all main methods: `plainToConstructor` now is `plainToClass` and `constructorToPlain` is `classToPlain`, etc.
69+
- `plainToConstructorArray` method removed - now `plainToClass` handles it
70+
- `@Skip()` decorator renamed to `@Exclude()`
71+
- added `@Expose` decorator
72+
- added lot of new options: groups, versioning, custom names, etc.
73+
- methods and getters that should be exposed must be decorated with `@Expose` decorator
74+
- added `excludedPrefix` to class transform options that allows exclude properties that start with one of the given prefix
7675

7776
### 0.0.22
7877

7978
#### Fixed
8079

81-
- fixed array with primitive types being converted
80+
- fixed array with primitive types being converted
8281

8382
### 0.0.18-0.0.21
8483

8584
#### Fixed
8685

87-
- fixed bugs when getters are not converted with es6 target
86+
- fixed bugs when getters are not converted with es6 target
8887

8988
### 0.0.17
9089

9190
#### Fixed
9291

93-
- fixed issue #4
94-
- added type guessing during transformation from constructor to plain object
95-
- added sample with generics
92+
- fixed issue #4
93+
- added type guessing during transformation from constructor to plain object
94+
- added sample with generics
9695

9796
### 0.0.16
9897

9998
#### Changed
10099

101-
- renamed `constructor-utils/constructor-utils` to `constructor-utils` package namespace
100+
- renamed `constructor-utils/constructor-utils` to `constructor-utils` package namespace
102101

103102
### 0.0.15
104103

105104
#### Removed
106105

107-
- removed code mappings from package
106+
- removed code mappings from package
108107

109108
### 0.0.14
110109

111110
#### Removed
112111

113-
- removed `import "reflect-metadata"` from source code. Now reflect metadata should be included like any other shims.
112+
- removed `import "reflect-metadata"` from source code. Now reflect metadata should be included like any other shims.
114113

115114
### 0.0.13
116115

117116
#### Changed
118117

119-
- Library has changed its name from `serializer.ts` to `constructor-utils`.
120-
- Added `constructor-utils` namespace.
118+
- Library has changed its name from `serializer.ts` to `constructor-utils`.
119+
- Added `constructor-utils` namespace.

sample/sample1-simple-usage/Album.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import {Type, Exclude} from "../../src/decorators";
2-
import {Photo} from "./Photo";
1+
import { Type, Exclude } from '../../src/decorators';
2+
import { Photo } from './Photo';
33

44
export class Album {
5+
id: string;
56

6-
id: string;
7+
@Exclude()
8+
name: string;
79

8-
@Exclude()
9-
name: string;
10-
11-
@Type(() => Photo)
12-
photos: Photo[];
13-
14-
}
10+
@Type(() => Photo)
11+
photos: Photo[];
12+
}

sample/sample1-simple-usage/Photo.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
import {Type} from "../../src/decorators";
2-
import {Album} from "./Album";
3-
import {User} from "./User";
1+
import { Type } from '../../src/decorators';
2+
import { Album } from './Album';
3+
import { User } from './User';
44

55
export class Photo {
6+
id: string;
67

7-
id: string;
8+
filename: string;
89

9-
filename: string;
10+
description: string;
1011

11-
description: string;
12+
tags: string[];
1213

13-
tags: string[];
14+
@Type(() => User)
15+
author: User;
1416

15-
@Type(() => User)
16-
author: User;
17+
@Type(() => Album)
18+
albums: Album[];
1719

18-
@Type(() => Album)
19-
albums: Album[];
20-
21-
get name() {
22-
return this.id + "_" + this.filename;
23-
}
20+
get name() {
21+
return this.id + '_' + this.filename;
22+
}
2423

25-
getAlbums() {
26-
console.log("this is not serialized/deserialized");
27-
return this.albums;
28-
}
29-
30-
}
24+
getAlbums() {
25+
console.log('this is not serialized/deserialized');
26+
return this.albums;
27+
}
28+
}

sample/sample1-simple-usage/User.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import {Type} from "../../src/decorators";
1+
import { Type } from '../../src/decorators';
22

33
export class User {
4+
@Type(() => Number)
5+
id: number;
46

5-
@Type(() => Number)
6-
id: number;
7-
8-
firstName: string;
9-
10-
lastName: string;
11-
12-
@Type(() => Date)
13-
registrationDate: Date;
14-
15-
}
7+
firstName: string;
8+
9+
lastName: string;
10+
11+
@Type(() => Date)
12+
registrationDate: Date;
13+
}

sample/sample1-simple-usage/app.ts

+65-60
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,91 @@
1-
import "es6-shim";
2-
import "reflect-metadata";
3-
import {plainToClass, classToPlain} from "../../src/index";
4-
import {Photo} from "./Photo";
1+
import 'es6-shim';
2+
import 'reflect-metadata';
3+
import { plainToClass, classToPlain } from '../../src/index';
4+
import { Photo } from './Photo';
55

66
// check deserialization
77

88
let photoJson = {
9-
id: "1",
10-
filename: "myphoto.jpg",
11-
description: "about my photo",
12-
tags: [
13-
"me",
14-
"iam"
15-
],
16-
author: {
17-
id: "2",
18-
firstName: "Johny",
19-
lastName: "Cage"
20-
},
21-
albums: [{
22-
id: "1",
23-
name: "My life"
9+
id: '1',
10+
filename: 'myphoto.jpg',
11+
description: 'about my photo',
12+
tags: ['me', 'iam'],
13+
author: {
14+
id: '2',
15+
firstName: 'Johny',
16+
lastName: 'Cage',
17+
},
18+
albums: [
19+
{
20+
id: '1',
21+
name: 'My life',
2422
},
2523
{
26-
id: "2",
27-
name: "My young years"
28-
}]
24+
id: '2',
25+
name: 'My young years',
26+
},
27+
],
2928
};
3029

3130
let photo = plainToClass(Photo, photoJson);
32-
console.log("deserialized object: " , photo);
31+
console.log('deserialized object: ', photo);
3332

3433
// now check serialization
3534

3635
let newPhotoJson = classToPlain(photo);
37-
console.log("serialized object: " , newPhotoJson);
36+
console.log('serialized object: ', newPhotoJson);
3837

3938
// try to deserialize an array
40-
console.log("-------------------------------");
39+
console.log('-------------------------------');
4140

42-
let photosJson = [{
43-
id: "1",
44-
filename: "myphoto.jpg",
45-
description: "about my photo",
41+
let photosJson = [
42+
{
43+
id: '1',
44+
filename: 'myphoto.jpg',
45+
description: 'about my photo',
4646
author: {
47-
id: "2",
48-
firstName: "Johny",
49-
lastName: "Cage",
50-
registrationDate: "1995-12-17T03:24:00"
51-
},
52-
albums: [{
53-
id: "1",
54-
name: "My life"
47+
id: '2',
48+
firstName: 'Johny',
49+
lastName: 'Cage',
50+
registrationDate: '1995-12-17T03:24:00',
5551
},
56-
{
57-
id: "2",
58-
name: "My young years"
59-
}]
60-
},
61-
{
62-
id: "2",
63-
filename: "hisphoto.jpg",
64-
description: "about his photo",
52+
albums: [
53+
{
54+
id: '1',
55+
name: 'My life',
56+
},
57+
{
58+
id: '2',
59+
name: 'My young years',
60+
},
61+
],
62+
},
63+
{
64+
id: '2',
65+
filename: 'hisphoto.jpg',
66+
description: 'about his photo',
6567
author: {
66-
id: "2",
67-
firstName: "Johny",
68-
lastName: "Cage"
69-
},
70-
albums: [{
71-
id: "1",
72-
name: "My life"
68+
id: '2',
69+
firstName: 'Johny',
70+
lastName: 'Cage',
7371
},
74-
{
75-
id: "2",
76-
name: "My young years"
77-
}]
78-
}];
72+
albums: [
73+
{
74+
id: '1',
75+
name: 'My life',
76+
},
77+
{
78+
id: '2',
79+
name: 'My young years',
80+
},
81+
],
82+
},
83+
];
7984

8085
let photos = plainToClass(Photo, photosJson);
81-
console.log("deserialized array: " , photos);
86+
console.log('deserialized array: ', photos);
8287

8388
// now check array serialization
8489

8590
let newPhotosJson = classToPlain(photos);
86-
console.log("serialized array: " , newPhotosJson);
91+
console.log('serialized array: ', newPhotosJson);

0 commit comments

Comments
 (0)