A tiny argument assertion library

Usage no npm install needed!

<script type="module">
  import argAssert from '';


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.


npm install --save-dev arg-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.


 * 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.


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