JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q38807F
  • License MIT

Tiny Javascript assertion library

Package Exports

  • picoassert

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (picoassert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

picoassert

npm npm Github file size GitHub

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 picoassert

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