1.0.8-1 • Published 12 months ago

validator-experimental-decorators v1.0.8-1

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Quick start

To install this package in your project, run the following command in your terminal.

npm i validator-experimental-decorators

The package provides the following tools

-Length -validateNegativeNumber -validatePositiveNumber -isEmail -isValidPassword

@isEmail

class Person {
  @isEmail
  email(input: string) {
    return input;
  }
}

const person = new Person();

//If you do not provide a valid email address here, the validator library will throw an error.
person.email("example@gmail.com");

@isValidPassword

class Person {
  @isValidPassword
  public password(password: string): string {
    return password;
  }
}

const person = new Person();
person.password("iamvalidpassword1337");
class Person {
  @isValidPassword
  public password(password: string): string {
    return password;
  }
}

const person = new Person();
//If you do not provide a valid password here, the validator library will throw an error.
person.password("iamvalidpassword1337");

@Length

-For the "Length(min, max)" function, you need to specify the range by providing the minimum value first, followed by the maximum value.

class Person {
  @Length(0,10)
  public password(password: string): string {
    return password;
  }
}

const person = new Person();
//If you do not provide a valid password here, the validator library will throw an error.
person.password("iamvalidpassword1337");

@validateNegativeNumber

class Person {
  @validateNegativeNumber
  public number(number: string): number {
    return number;
  }
}

const person = new Person();
// If you enter a positive number, the validator will throw an error.
person.number(-1337)

@validatePositiveNumber

class Person {
  @validatePositiveNumber
  public number(number: string): number {
    return number;
  }
}

const person = new Person();
// If you enter a negative number, the validator will throw an error.
person.number(1337)

Example Usage

const {
  Length,
  isEmail,
  isValidPassword,
  validateNegativeNumber,
  validatePositiveNumber,
} = new Validator();

class Person {
  constructor(
    public name: string,
    public email: string,
    public password: string,
    public userAge: number
  ) {}

  @isEmail
  public changeEmail(newEmail: string): string {
    return (this.email = newEmail);
  }

  @Length(0, 10)
  public changeUsername(newUsername: string): string {
    return (this.name = newUsername);
  }

  @isValidPassword
  public changeUserPassword(newPassword: string): string {
    return (this.password = newPassword);
  }

  @validatePositiveNumber
  get age() {
    return this.userAge;
  }

  @validatePositiveNumber
  set _age(newAge: number) {
    this.userAge = newAge;
  }
}
1.0.8-1

12 months ago

1.0.8-0

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago