1.0.0 • Published 7 years ago

validationsjs v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

Simple validations library

usage

//if objToBeValidated contains invalid data then errors will be object with invalid fields and messages, otherwise it will be false boolean value

const errors = new require("validationsjs").Validator(objToBeValidated)
            .check("password").password()
            .check("email").email()
            .check("firstName").min(3)
            .check("lastName").min(3)
            .getErrors();

if ( errors ) {
    console.log("Object had invalid fields. Details: ", JSON.strinigy(errors))
}

returnes object might look like this

{
    "password":"invalidPassword",
    "lastName": "canNotBeShorterThan"
}

you can provide messages parameter, then error codes will be replaced with proper messages. If you need other language support just copy content of messages_en.js and provide other values.

const messages = require('validationsjs/messages_en');
new require("validationsjs", messages);

to run tests

npm install
./node_modules/mocha/bin/mocha

to run eslint

npm install
./node_modules/eslint/bin/eslint.js .

or

npm install
npm test