0.0.4 • Published 3 years ago

typescript-validation v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

typescript-validation

A simple typescript library to validate strings

Installing

Using npm

npm install typescript-validation

Using yarn

yarn add typescript-validation

Usage

Importing package

import validation from "typescript-validation";

Validating

validation.validate("example@exmail.com", {
  isEmail: {
    need: true,
    message: "Invalid e-mail",
  },
});

Checking if the validations were successfull

Get error functions:

getErrors() - Get all errors (Return String[])

getLastError() - Get last error (Return String)

if (validation.success()) {
  // Success methods here
} else {
  // Unsuccess methods here
  console.log(validation.getLastError());
}

Full code example

import validation from "typescript-validation";

validation.validate("example@exmail.com", {
  isEmail: {
    need: true,
    message: "Invalid e-mail",
  },
});

if (validation.success()) {
  // Success methods here
} else {
  // Unsuccess methods here
  console.log(validation.getLastError());
}

Validations

need (Boolean): The final expected value (Default value: false)

message (String): Message if the result is not as expected

isAlpha: { need: false, message: "These are not alphabetic characters"}
isEmail: { need: false, message: "This is not an e-mail"}
isEmpty: { need: true, message: "This is empty"}
isNumeric: { need: false, message: "These are not numeric characters"}

min (Number): Minimum characters value

max (Number): Maximum characters value

isLength: { need: true, min: 5, max: 10, message: "This must be between 5 and 10 characters"}
0.0.1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.4

3 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago