Socket
Book a DemoInstallSign in
Socket

arg-assert

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arg-assert

A tiny argument assertion library

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

Arg Assert

Simple, tiny assertion library designed for making assertions about function arguments.

NOTE: when I use the term "truthy" in these docs, I do not use it in the sense usually understood in javascript. In these docs, "truthy" means not null, undefined, or false.

Installation

npm install --save-dev arg-assert

API

assert

/**
 * Assert a value is truthy.
 * @param thingToBeTruthy The assertion subject.
 * @param {string} [message] The error message to display if thingToBeTruthy is
 *   falsy.
 * @throws {Error} An error with message equal to the passed in message (if
 *   given) if thingToBeTruthy is falsy.
 */

assertAll

/**
 * Assert a collection of values are truthy.
 * @param {{Object.<string, *>}} thingsToBeTruthy An object whose keys are the
 *  names of the args that should be truthy.
 * @throws {Error} An error with message with the form '"[thingToBeTruthy]" must
 *   be truthy.
 */

Tip: This is especially nice when asserting a number of arguments are non-null, and if you are using es6, you can use deconstruction to keep your code compact.

Example:

function(a, b, c) {
  assertAll({a, b, c});
}

Keywords

assertion

FAQs

Package last updated on 27 Jan 2016

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