class-transformer
Advanced tools
Comparing version 0.1.0-beta.1 to 0.1.0-beta.2
@@ -5,2 +5,3 @@ import { ClassType } from "./ClassTransformer"; | ||
export { ClassTransformer } from "./ClassTransformer"; | ||
export { ClassTransformOptions } from "./ClassTransformOptions"; | ||
export * from "./decorators"; | ||
@@ -7,0 +8,0 @@ /** |
{ | ||
"name": "class-transformer", | ||
"version": "0.1.0-beta.1", | ||
"description": "Transforms or serializes / deserializes objects from one shape into another based on class decorators", | ||
"version": "0.1.0-beta.2", | ||
"description": "Proper decorator-based transformation / serialization / deserialization of plain javascript objects to class constructors", | ||
"license": "MIT", | ||
@@ -51,3 +51,7 @@ "readmeFilename": "README.md", | ||
"typings": "^1.3.2" | ||
}, | ||
"scripts": { | ||
"postinstall": "typings install", | ||
"test": "gulp tests" | ||
} | ||
} |
@@ -13,2 +13,3 @@ # class-transformer | ||
Also it allows to serialize / deserialize object based on criteria. | ||
This tool is useful on both frontend and backend. | ||
@@ -252,2 +253,55 @@ ## Installation | ||
### Exposing getters and method return values | ||
You can expose what you getter or method return by setting a `@Expose()` decorator to those getters or methods: | ||
```javascript | ||
import {Expose} from "class-transformer"; | ||
export class User { | ||
id: number; | ||
firstName: string; | ||
lastName: string; | ||
password: string; | ||
@Expose() | ||
get name() { | ||
return this.firstName + " " + this.lastName; | ||
} | ||
@Expose() | ||
getFullName() { | ||
return this.firstName + " " + this.lastName; | ||
} | ||
} | ||
``` | ||
### Exposing properties with different names | ||
If you want to expose some of properties with different names, | ||
you can do it by specifying a `name` option to `@Expose` decorator: | ||
```javascript | ||
import {Expose} from "class-transformer"; | ||
export class User { | ||
@Expose("uid") | ||
id: number; | ||
firstName: string; | ||
lastName: string; | ||
@Expose("secretKey") | ||
password: string; | ||
@Expose("fullName") | ||
getFullName() { | ||
return this.firstName + " " + this.lastName; | ||
} | ||
} | ||
``` | ||
### Skipping specific properties | ||
@@ -254,0 +308,0 @@ |
@@ -88,3 +88,3 @@ "use strict"; | ||
if (this.transformationType === "plainToClass" && !type && subValue instanceof Object && !(subValue instanceof Date)) | ||
throw new Error("Cannot determine type for " + targetType.name + "." + propertyName + ", did you forgot to specify a @Type?"); | ||
throw new Error("Cannot determine type for " + targetType.name + "." + propertyName + ", did you forget to specify a @Type?"); | ||
// if newValue is a source object that has method that match newKeyName then skip it | ||
@@ -91,0 +91,0 @@ var hasDescriptor = false; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103346
747
551
1