@robertoachar/whoops

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i @robertoachar/whoops

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

8.31 kB

Total Files

12

Last publish

Collaborators

  • robertoachar