Skip to content
An express middleware validator.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.npmrc
.prettierrc
.travis.yml
CHANGELOG.md
LICENSE
README.md
appveyor.yml
circle.yml
package.json

README.md

whoops

Generated by OSS Project Generator.

Travis Status AppVeyor Status CircleCI Status Coveralls Status NPM Version License

An express middleware validator.

This validator provides the following features:

  • checkArray(value, [message]): check if value is an array
  • checkArrayEmpty(value, [message]): check if value is an array and not empty
  • checkBoolean(value, [message]): check if value is a boolean
  • checkNumber(value, [message]): check if value is a number
  • checkNumberEmpty(value, [message]): check if value is a number and not zero or negative
  • checkObjectId(value, [message]): check if value is an ObjectId (mongoose)
  • checkString(value, [message]): check if value is a string
  • checkStringEmpty(value, [message]): check if value is a string and not empty

Installation

  • Install package
$ npm install --save @robertoachar/whoops

Usage

  • Import whoops
const express = require('express');
const whoops = require('@robertoachar/whoops');
  • Initialize whoops
const app = express();
app.use(whoops());
  • Use whoops
app.post('/', (req, res) => {
  req.whoops.checkStringEmpty(req.body.name, 'Enter a name');

  res.json({ name: req.body.name });
});
  • Error Handling
app.use((err, req, res, next) => {
  if (err && err.name === 'WhoopsError') {
    return res.status(400).json({ message: err.message }); // Enter a name
  }

  next(err);
});

Development

  • Cloning the repo
$ git clone https://github.com/robertoachar/whoops.git
  • Installing dependencies
$ npm install
  • Running scripts
Action Usage
Linting code npm run lint
Running unit tests npm run jest
Running code coverage npm run coverage
Running lint + tests npm test
Sending coverage results to Coveralls.io npm run coveralls

Author

Roberto Achar

License

MIT

You can’t perform that action at this time.