Validate functions, constructor and properties with validatorJS and Typescript decorators.
To install run one of this instructions:
npm install validatorjs-decorator
yarn add validatorjs-decorator
import { prop } from 'validatorjs-decorator';
class Example {
@prop('email|required', { required: 'You forgot to give a :attribute' })
public readonly email: string;
public readonly password: string;
constructor(
email: string,
password: string,
) {
this.email = email;
this.password = password;
}
}
import { validateClass, arg } from 'validatorjs-decorator';
@validateClass({ required: 'You forgot to give a :attribute' })
class Example {
public readonly email: string;
public readonly password: string;
constructor(
@arg('email', 'email|required') email: string,
@arg('password', 'string|required') password: string,
) {
this.email = email;
this.password = password;
}
}
import { validate, arg } from 'validatorjs-decorator';
class Example {
@validate({ required: 'You forgot to give a :attribute' })
login(
@arg('email', 'email|required') email: string,
@arg('password', 'string|required') password: string,
): string {
return `the values (${email}, ${password}) are good`;
}
}
Created by Albert Tjornehoj
E-Mail: me@albertcito.com
Website: albertcito.com