New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@robertoachar/whoops

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@robertoachar/whoops

An express middleware validator.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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
ActionUsage
Linting codenpm run lint
Running unit testsnpm run jest
Running code coveragenpm run coverage
Running lint + testsnpm test
Sending coverage results to Coveralls.ionpm run coveralls

Author

Roberto Achar

License

MIT

Keywords

node

FAQs

Package last updated on 19 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts