1.0.84 • Published 1 year ago

@webage/validation v1.0.84

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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

1 year ago

1.0.83

1 year ago

1.0.81

1 year ago

1.0.8

1 year ago

1.0.71

1 year ago

1.0.7

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago