@invisible/assert

1.0.2 • Public • Published

@invisible/assert

CircleCI

Assertion library to allow one to throw custom errors.

@invisible/assert uses ES2015 Proxies to intercept calls to assert. All methods of assert are available, and it is compatible with both Node.js's standard assertion library and the one on npm.

Motivation

To allow assert to throw custom errors.

Example

assert encapsulates Custom Errors under an AssertionError, which sucks

const assert = require('assert')
assert(false, Error('yohoo')

{ AssertionError: Error: yohoo
    at Object.<anonymous> (/tmp/a/index.js:2:1)
  name: 'AssertionError',
  actual: false,
  expected: true,
  operator: '==',
  message: 
   Error: yohoo
       at Object.<anonymous> (/tmp/a/index.js:2:15)
  generatedMessage: false }

Stack-trace trimmed for readability.

@invisible/assert throws Custom Errors properly, which is nice

const assert = require('assert')
assert(false, Error('yohoo'))
Error: yohoo
    at Object.<anonymous> (/tmp/a/index.js:2:16)

Stack-trace trimmed for readability.

Installation

npm install @invisible/assert

NB: The npm library assert is not a dependency in package.json in order to allow one to use Node.js's standard assert library.

Readme

Keywords

Package Sidebar

Install

npm i @invisible/assert

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • brittonware
  • juliendemarque
  • chancellorrr
  • adamhaney-invisible
  • nadeeminv
  • gtaltemann
  • elseagle
  • invisible-bot
  • rodrigo4244
  • scottdownes
  • zacksingh
  • el5091