class-transformer-validator
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -57,3 +57,2 @@ "use strict"; | ||
} | ||
exports.transformAndValidateSync = transformAndValidateSync; | ||
//# sourceMappingURL=index.js.map | ||
exports.transformAndValidateSync = transformAndValidateSync; |
{ | ||
"name": "class-transformer-validator", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "A simple wrapper around class-transformer and class-validator which provides nice and programmer-friendly API.", | ||
@@ -45,11 +45,11 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.2", | ||
"@types/chai": "^4.1.4", | ||
"@types/chai-as-promised": "7.1.0", | ||
"@types/mocha": "^2.2.48", | ||
"@types/mocha": "^5.2.5", | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"class-transformer": "^0.1.9", | ||
"class-validator": "^0.8.1", | ||
"mocha": "^3.5.3", | ||
"tslint": "^5.9.1", | ||
"class-validator": "^0.9.1", | ||
"mocha": "^5.2.0", | ||
"tslint": "^5.11.0", | ||
"typescript": "~2.3.4" | ||
@@ -59,3 +59,3 @@ }, | ||
"class-transformer": "^0.1.9", | ||
"class-validator": "^0.8.1" | ||
"class-validator": "^0.9.1" | ||
}, | ||
@@ -62,0 +62,0 @@ "main": "index.js", |
@@ -31,3 +31,3 @@ # class-transformer-validator | ||
```js | ||
```ts | ||
import { IsEmail } from 'class-validator'; | ||
@@ -62,3 +62,3 @@ import { transformAndValidate } from "class-transformer-validator"; | ||
You can also transform and validate plain JS object (e.g. from express req.body). Using ES7 async/await syntax: | ||
```js | ||
```ts | ||
async (req, res) => { | ||
@@ -76,3 +76,3 @@ try { | ||
And since release `0.3.0` you can also pass array of objects - all of them will be validated using given class validation constraints: | ||
```js | ||
```ts | ||
async (req, res) => { | ||
@@ -94,11 +94,11 @@ try { | ||
There is available the `transformAndValidate` function with three overloads: | ||
```js | ||
```ts | ||
function transformAndValidate<T extends object>(classType: ClassType<T>, jsonString: string, options?: TransformValidationOptions): Promise<T|T[]>; | ||
``` | ||
```js | ||
```ts | ||
function transformAndValidate<T extends object>(classType: ClassType<T>, object: object, options?: TransformValidationOptions): Promise<T>; | ||
``` | ||
```js | ||
```ts | ||
function transformAndValidate<T extends object>(classType: ClassType<T>, array: object[], options?: TransformValidationOptions): Promise<T[]>; | ||
@@ -108,3 +108,3 @@ ``` | ||
Be aware that if you validate json string, the return type is a `Promise` of `T` or `T[]` so you need to assert the returned type if you know the shape of json: | ||
```js | ||
```ts | ||
const users = await transformAndValidate(User, JSON.stringify([{ email: "test@test.test" }])) as User[]; | ||
@@ -121,3 +121,3 @@ ``` | ||
- `classType` - an class symbol, a constructor function which can be called with `new` | ||
```js | ||
```ts | ||
type ClassType<T> = { | ||
@@ -134,3 +134,3 @@ new (...args: any[]): T; | ||
- `options` - optional options object, it has two optional properties | ||
```js | ||
```ts | ||
interface TransformValidationOptions { | ||
@@ -149,2 +149,5 @@ validator?: ValidatorOptions; | ||
**0.6.0** | ||
* updated `class-validator` dependency to version `^0.9.1` | ||
**0.5.0** | ||
@@ -151,0 +154,0 @@ * remove deprecated `TransformValdiationOptions` interface (typo) |
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
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
16823
175
125