This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

typescript-validation

0.0.4 • Public • Published

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

/typescript-validation/

    Package Sidebar

    Install

    npm i typescript-validation

    Weekly Downloads

    1

    Version

    0.0.4

    License

    MIT

    Unpacked Size

    4.24 kB

    Total Files

    8

    Last publish

    Collaborators

    • biewdev