1.0.3 • Published 6 years ago

small-validate v1.0.3

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
6 years ago

small-validate

A library object validators.

Installation and Usage

Install the library with command npm i small-validate or npm install small-validate

var { Validate } = require('small-validate');

let dataValidate = {
    userName: 'toanthien',
    passWord: '',
}

let option = {
    required: [
        { name: "userName", msg: "[name] is required", alias: "user name" },
        { name: "passWord", msg: "you must be input [name] to verify", alias: "pass word" }
    ],
    isEmpty: [
        {name: "passWord", msg: "[name] can't empty", alias: "pass word"},
        {name: "phone", msg: "[name] can't empty", alias: "phone number"}
    ],
    isNumber: [
        {name: "userName", msg: "[name] must a Number", alias: "us"},
    ]
}

console.log(Validate(dataValidate, option))

  /* return
     {
        msg: [ 'you must be input pass word to verify',
                'pass word can\'t empty',
                'us must a Number' ],
        isValid: false
    }
   */

Attribute

AttributeDescription
namerequire object key need to check.
msgoption message return when not valid, message default is used if not exists.
aliasoption Alias name is replaced in param name, if not attribute name is used.

Operators

ValidatorDescription
requiredcheck if a string is undefined.
isEmailcheck if the string is an email.
isEmptycheck if the string has a length of zero
isNumbercheck if the string is contain number only.
1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago