Skip to content

Commit

Permalink
refactor: format code with prettier (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoNameProvided authored Jul 29, 2020
1 parent a797726 commit f6413c9
Show file tree
Hide file tree
Showing 42 changed files with 6,204 additions and 6,057 deletions.
63 changes: 31 additions & 32 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Changelog and release notes


### 0.2.3 [BREAKING CHANGE]

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

- add option to strip unkown properties via using the `excludeExtraneousValues` option
- add option to strip unkown properties via using the `excludeExtraneousValues` option

### 0.2.0 [BREAKING CHANGE]

#### Added

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

#### Fixed

- fix bug when transforming `null` values as primitives
- fix bug when transforming `null` values as primitives

### 0.1.10

#### Fixed

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

### 0.1.9

#### Fixed

- objects with `null` prototype are converted properly now
- objects with unknown non primitive properties are converted properly now
- corrected a typo in the README.md
- fixed the deserialize example in the README.md
- objects with `null` prototype are converted properly now
- objects with unknown non primitive properties are converted properly now
- corrected a typo in the README.md
- fixed the deserialize example in the README.md

### 0.1.4

#### Added

- added `TransformClassToPlain` and `TransformClassToClass` decorators
- added `TransformClassToPlain` and `TransformClassToClass` decorators

### 0.1.0

#### Added

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

### 0.0.22

#### Fixed

- fixed array with primitive types being converted
- fixed array with primitive types being converted

### 0.0.18-0.0.21

#### Fixed

- fixed bugs when getters are not converted with es6 target
- fixed bugs when getters are not converted with es6 target

### 0.0.17

#### Fixed

- fixed issue #4
- added type guessing during transformation from constructor to plain object
- added sample with generics
- fixed issue #4
- added type guessing during transformation from constructor to plain object
- added sample with generics

### 0.0.16

#### Changed

- renamed `constructor-utils/constructor-utils` to `constructor-utils` package namespace
- renamed `constructor-utils/constructor-utils` to `constructor-utils` package namespace

### 0.0.15

#### Removed

- removed code mappings from package
- removed code mappings from package

### 0.0.14

#### Removed

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

### 0.0.13

#### Changed

- Library has changed its name from `serializer.ts` to `constructor-utils`.
- Added `constructor-utils` namespace.
- Library has changed its name from `serializer.ts` to `constructor-utils`.
- Added `constructor-utils` namespace.
18 changes: 8 additions & 10 deletions sample/sample1-simple-usage/Album.ts
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[];
}
40 changes: 19 additions & 21 deletions sample/sample1-simple-usage/Photo.ts
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;
}
}
22 changes: 10 additions & 12 deletions sample/sample1-simple-usage/User.ts
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;
}
125 changes: 65 additions & 60 deletions sample/sample1-simple-usage/app.ts
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);
Loading

0 comments on commit f6413c9

Please sign in to comment.