1.0.9 • Published 5 years ago

valid_me_js v1.0.9

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

validMejs

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

Build Status Maintainability Test Coverage

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 NgBanks project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago