1.0.0 • Published 7 years ago
throw-if-true v1.0.0
throw-if-true
A tiny utility to throw error if given param is truthy.
Install
$ yarn add throw-if-true
Examples
const httpErrors = require('http-errors');
const throwIfTrue = require('throw-if-true');
const doc = functionThatReturnsFromDb();
// Throws Error with no message
throwIfTrue(!!doc);
// Throws Error with message 'Doc is not set'
throwIfTrue(!!doc, 'Doc is not set');
// Throws NotFoundError with message 'Doc not set'
throwIfTrue(!!doc, httpErrors.NotFound, 'Doc not set');
1.0.0
7 years ago