0.1.0 • Published 4 years ago

validatorjs-decorators v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

ValidatorJS + Decorator + TypeScript

Build Status

Validate functions, constructor and properties with validatorJS and Typescript decorators.

Install

To install run one of this instructions:

  • npm install validatorjs-decorators
  • yarn add validatorjs-decorators

Validate properties

import { prop } from 'validatorjs-decorators';

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;
  }
}

Validate Constructor

import { validateClass, arg } from 'validatorjs-decorators';

@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;
  }
}

Validate function

import { validate, arg } from 'validatorjs-decorators';

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`;
  }
}

Credits

Created by Albert Tjornehoj
E-Mail: me@albertcito.com
Website: albertcito.com

0.1.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago