npm

Need private packages and team management tools?Check out npm Orgs. »

express-param-validator

1.1.1 • Public • Published

Study purposes only.

EXPRESS PARAM VALIDATOR

TODO:

  • Doc existing code
  • Add validation options:
    • required
    • type
    • value
    • email
    • maximum length
    • minimum length
    • size
    • not allowed characters
  • Create user friendly method(s) to generate the validation object

Testing:

  yarn run test

Usage

  yarn add express-param-validator
  const { paramValidator } = require('express-param-validator')
 
  const REQUIRED_PARAMS = [
    {name: 'token', type: 'string'},
    {name: 'name', type: 'string'}
    {name: 'type', type: 'string'},
    {name: 'unit', type: 'number'},
    {name: 'price', type: 'number'},
    {name: 'expireDate', type: 'object'},
    {name: 'discount', type: 'string', optional: true},
    {name: 'email', type: 'email', blacklist: ['outlook']}
    {name: 'status', type: 'string', oneOf: ['active', 'inactive']}
  ]
  // just like router.post('/add', (req, res) => {})
  const post = function(req, res) {
    paramValidator(
        REQUIRED_PARAMS,
        req,
        res, 
        function (sendError, sendSuccess) {
          if(auth(req.body.token))
            return sendSuccess('successfull message')
          else
            return sendError(401)
        }
      )
  }

The idea is to improve my repository management in addition to maintaining and developing simple parameter validation

install

npm i express-param-validator

Downloadsweekly downloads

5

version

1.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability