1.0.84 • Published 2 years ago

@webage/validation v1.0.84

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years 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

2 years ago

1.0.83

2 years ago

1.0.81

2 years ago

1.0.8

2 years ago

1.0.71

2 years ago

1.0.7

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago