1.0.84 • Published 12 months ago
@webage/validation v1.0.84
validation
Transform and validation class properties
Install
npm install @webage/validation
pnpm add @webage/validation
Examples
import { PropertyValidation } from '@webage/validation';
import { plainToInstance } from 'class-transformer';
import { validateSync } from 'class-validator';
export class Example {
@PropertyValidation({ type: 'string', transform: true, minLength: 3 })
name: string;
@PropertyValidation({ type: 'date', transform: true, daysOfWeek: [0] })
startDate: Date;
@PropertyValidation({ type: 'boolean', transform: true })
isActive: Date;
@PropertyValidation({ type: 'number', transform: true, minimum: 0 })
price: string;
@PropertyValidation({ type: 'number', transform: true, moreThan: 'price' })
cost: string;
@PropertyValidation({ type: 'object', transform: true, target: () => Example })
object: Example;
}
const instance = plainToInstance(Example, {});
const errors = validateSync(instance);