-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: format code with prettier (#379)
- Loading branch information
1 parent
a797726
commit f6413c9
Showing
42 changed files
with
6,204 additions
and
6,057 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import {Type, Exclude} from "../../src/decorators"; | ||
import {Photo} from "./Photo"; | ||
import { Type, Exclude } from '../../src/decorators'; | ||
import { Photo } from './Photo'; | ||
|
||
export class Album { | ||
id: string; | ||
|
||
id: string; | ||
@Exclude() | ||
name: string; | ||
|
||
@Exclude() | ||
name: string; | ||
|
||
@Type(() => Photo) | ||
photos: Photo[]; | ||
|
||
} | ||
@Type(() => Photo) | ||
photos: Photo[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import {Type} from "../../src/decorators"; | ||
import {Album} from "./Album"; | ||
import {User} from "./User"; | ||
import { Type } from '../../src/decorators'; | ||
import { Album } from './Album'; | ||
import { User } from './User'; | ||
|
||
export class Photo { | ||
id: string; | ||
|
||
id: string; | ||
filename: string; | ||
|
||
filename: string; | ||
description: string; | ||
|
||
description: string; | ||
tags: string[]; | ||
|
||
tags: string[]; | ||
@Type(() => User) | ||
author: User; | ||
|
||
@Type(() => User) | ||
author: User; | ||
@Type(() => Album) | ||
albums: Album[]; | ||
|
||
@Type(() => Album) | ||
albums: Album[]; | ||
|
||
get name() { | ||
return this.id + "_" + this.filename; | ||
} | ||
get name() { | ||
return this.id + '_' + this.filename; | ||
} | ||
|
||
getAlbums() { | ||
console.log("this is not serialized/deserialized"); | ||
return this.albums; | ||
} | ||
|
||
} | ||
getAlbums() { | ||
console.log('this is not serialized/deserialized'); | ||
return this.albums; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import {Type} from "../../src/decorators"; | ||
import { Type } from '../../src/decorators'; | ||
|
||
export class User { | ||
@Type(() => Number) | ||
id: number; | ||
|
||
@Type(() => Number) | ||
id: number; | ||
|
||
firstName: string; | ||
|
||
lastName: string; | ||
|
||
@Type(() => Date) | ||
registrationDate: Date; | ||
|
||
} | ||
firstName: string; | ||
|
||
lastName: string; | ||
|
||
@Type(() => Date) | ||
registrationDate: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,91 @@ | ||
import "es6-shim"; | ||
import "reflect-metadata"; | ||
import {plainToClass, classToPlain} from "../../src/index"; | ||
import {Photo} from "./Photo"; | ||
import 'es6-shim'; | ||
import 'reflect-metadata'; | ||
import { plainToClass, classToPlain } from '../../src/index'; | ||
import { Photo } from './Photo'; | ||
|
||
// check deserialization | ||
|
||
let photoJson = { | ||
id: "1", | ||
filename: "myphoto.jpg", | ||
description: "about my photo", | ||
tags: [ | ||
"me", | ||
"iam" | ||
], | ||
author: { | ||
id: "2", | ||
firstName: "Johny", | ||
lastName: "Cage" | ||
}, | ||
albums: [{ | ||
id: "1", | ||
name: "My life" | ||
id: '1', | ||
filename: 'myphoto.jpg', | ||
description: 'about my photo', | ||
tags: ['me', 'iam'], | ||
author: { | ||
id: '2', | ||
firstName: 'Johny', | ||
lastName: 'Cage', | ||
}, | ||
albums: [ | ||
{ | ||
id: '1', | ||
name: 'My life', | ||
}, | ||
{ | ||
id: "2", | ||
name: "My young years" | ||
}] | ||
id: '2', | ||
name: 'My young years', | ||
}, | ||
], | ||
}; | ||
|
||
let photo = plainToClass(Photo, photoJson); | ||
console.log("deserialized object: " , photo); | ||
console.log('deserialized object: ', photo); | ||
|
||
// now check serialization | ||
|
||
let newPhotoJson = classToPlain(photo); | ||
console.log("serialized object: " , newPhotoJson); | ||
console.log('serialized object: ', newPhotoJson); | ||
|
||
// try to deserialize an array | ||
console.log("-------------------------------"); | ||
console.log('-------------------------------'); | ||
|
||
let photosJson = [{ | ||
id: "1", | ||
filename: "myphoto.jpg", | ||
description: "about my photo", | ||
let photosJson = [ | ||
{ | ||
id: '1', | ||
filename: 'myphoto.jpg', | ||
description: 'about my photo', | ||
author: { | ||
id: "2", | ||
firstName: "Johny", | ||
lastName: "Cage", | ||
registrationDate: "1995-12-17T03:24:00" | ||
}, | ||
albums: [{ | ||
id: "1", | ||
name: "My life" | ||
id: '2', | ||
firstName: 'Johny', | ||
lastName: 'Cage', | ||
registrationDate: '1995-12-17T03:24:00', | ||
}, | ||
{ | ||
id: "2", | ||
name: "My young years" | ||
}] | ||
}, | ||
{ | ||
id: "2", | ||
filename: "hisphoto.jpg", | ||
description: "about his photo", | ||
albums: [ | ||
{ | ||
id: '1', | ||
name: 'My life', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'My young years', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: '2', | ||
filename: 'hisphoto.jpg', | ||
description: 'about his photo', | ||
author: { | ||
id: "2", | ||
firstName: "Johny", | ||
lastName: "Cage" | ||
}, | ||
albums: [{ | ||
id: "1", | ||
name: "My life" | ||
id: '2', | ||
firstName: 'Johny', | ||
lastName: 'Cage', | ||
}, | ||
{ | ||
id: "2", | ||
name: "My young years" | ||
}] | ||
}]; | ||
albums: [ | ||
{ | ||
id: '1', | ||
name: 'My life', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'My young years', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
let photos = plainToClass(Photo, photosJson); | ||
console.log("deserialized array: " , photos); | ||
console.log('deserialized array: ', photos); | ||
|
||
// now check array serialization | ||
|
||
let newPhotosJson = classToPlain(photos); | ||
console.log("serialized array: " , newPhotosJson); | ||
console.log('serialized array: ', newPhotosJson); |
Oops, something went wrong.