JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 521878
  • Score
    100M100P100Q184056F
  • License ISC

Nanoscale assertion module

Package Exports

  • nanoassert
  • nanoassert/index.js

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 (nanoassert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nanoassert

NPM

Nanoscale assertion module

Usage

const assert = require('nanoassert')

assert(a !== b, `${a} !== ${b}`)

API

assert(predicate, [message])

Assert that predicate is truthy, otherwise throw AssertionError with optional message. In Javascript runtimes that support Error.captureStackTrace, you will get a nicer stack trace with this error. If you want friendlier messages you can use template strings to show the assertion made like in the example above.

Why

I like to write public facing code very defensively, but have reservations about the size incurred by the assert module. I only use the top-level assert method anyway.

nanoassert@^1.1.0

Docs for the previous version, which is used by many modules on npm, can be found here

nanoassert@^3.0.0

Modernise nanoassert some, and add the small type definition from DefinitelyTyped. Functionally there should be no changes for most users, but the name property of the AssertionError is no longer set on the prototype, and newer syntax is employed, which might break some downstream modules.

Thank you to the folks that created and maintained the original type definitions.

Install

npm install nanoassert

License

ISC