Skip to content

your middleware validating assistant. just super easy and flexible...

License

Notifications You must be signed in to change notification settings

jojitoon/validMejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

validMejs

Build Status Maintainability Test Coverage

Node.js middleware validating assistant. Just super easy and flexible...

Installation

$ npm install valid_me_js

Also make sure that you have Node.js 6 or newer in order to use it.

How to use

import { middleware } from 'valid_me_js';

const signUpValidator = (req, res, next) => {
  const valid = middleware(req, res, next);
  valid
    .hasElement('email', 'Your Email')
    .hasElement('username', 'My Username')
    .hasElement('password', 'My password')
    .isEmail()
    .isLength('username', 3)
    .hasSpaces('username')
    .hasSpaces('password')
    .isLength('password', 8)
    .check();
};

const signInValidator = (req, res, next) => {
  const valid = middleware(req, res, next);
  valid
    .hasElement('email')
    .hasElement('password')
    .isEmail()
    .check();
};


export { signUpValidator, signInValidator };

then you can use it in the express router like this

import express from 'express';
import user from '../controllers/users';
import { signUpValidator, signInValidator } from '../middlewares/validator';

const { signup, login } = user;

const router = express.Router();

router.post('/', signInValidator, login);
router.post('/new', signUpValidator, signup);

export default router;

and get errors as

{
  "errors": [
      "tex is required",
      "myDate is an invalid date. Must not be later than today",
      "not making sense abi !!!",
      "length is bad",
      "no upper",
      "no number",
      "no special"
    ],
    "message": "Invalid Parameters"
}

Changelog

Check the GitHub Releases page.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jojiAndela/validmejs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

MIT License

Code of Conduct

Everyone interacting in the validmejs project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

your middleware validating assistant. just super easy and flexible...

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published