picoassert v1.4.3
picoassert
Perhaps the smallest Javascript assertion module
picoassert is a 113-byte Javascript assertion module based on
nanoassert.
Usage
var assert = require("picoassert")
assert.eq(a, b, `${a} == ${b}`); // Asserts `a` and `b` are equal.
assert.neq(a, b, `${a} != ${b}`); // Asserts `a` and `b` are not equal.
assert.is(a, `(!!${a}) === true`); // Asserts `a` is truthy.Why
The nanoassert repository README describes the author's complaint about the
excessive size of the assert module,
the standard assertion library. However, even the nanoassert library was
unnecessarily large, which led to the creation of picoassert.
This library is also an open golf challenge. Please feel free to submit pull requests if you're able to shorten the code!
Install
npm install picoassertContent Delivery Network (CDN)
The picoassert library can be imported via unpkg as shown below:
<script type="application/javascript">var module={};</script>
<script src="https://unpkg.com/picoassert/index.js"></script>
<script type="application/javascript">
var assert = module.exports;
// Library is imported as `assert`!
</script>Be aware that picoassert is a CommonJS module and therefore uses
module.exports; before importing the script, you will need to define module
or use a CommonJS-compatible module loader.
License
Please see the LICENSE file for license information.