1.0.84 • Published 12 months ago

@webage/validation v1.0.84

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

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);
1.0.84

12 months ago

1.0.83

12 months ago

1.0.81

12 months ago

1.0.8

12 months ago

1.0.71

12 months ago

1.0.7

12 months ago

1.0.62

12 months ago

1.0.61

12 months ago

1.0.1

12 months ago

1.0.0

1 year ago