Skip to content
/ invar Public

🔩 Expressive runtime invariants for JavaScript

License

Notifications You must be signed in to change notification settings

dsys/invar

Repository files navigation

logo

The reign of poor error messages is over!
Expressive runtime invariants for JavaScript.

TravisCI shield npm shield JavaScript Standard Style

Installation

$ npm install invar --save

Usage

import invar from 'invar'

invar(message)

Check for truthiness.

Example

invar(2 + 2 === 5, "I'm sorry Dave, I'm afraid I can't do that.")

Throws

Invariant Violation: I'm sorry Dave, I'm afraid I can't do that.

invar.equal(actual, expected, message)

Check for shallow equality.

Example

invar.equal(2 + 2, 5, "Daisy, Daisy, give me your answer do.")

Throws

Invariant Violation: Daisy, Daisy, give me your answer do.
    actual: 4
  expected: 5

invar.notEqual(actual, expected, message)

Check for shallow unequality.

Example

invar.notEqual(2 + 2, 4, "I've just picked up a fault in the AE35 unit.")

Throws

Invariant Violation: I've just picked up a fault in the AE35 unit.
    actual: 4
  expected: not 4

invar.req(arg)

Always fail. Used for mandatory function arguments.

Example

function myFunction (mandatoryArg = invar.req('mandatoryArg')) {}
myFunction()

Throws

Invariant Violation: Required argument 'mandatoryArg' not provided.

invar.fail(message)

Always fail.

Example

invar.fail("I'm afraid. I'm afraid, Dave. Dave, my mind is going.")

Throws

Invariant Violation: I'm afraid. I'm afraid, Dave. Dave, my mind is going.

Development

Invar uses JavaScript Standard Style, Babel for ES6+ support, and Jest for testing.

$ git clone git@github.com:pavlovml/invar.git
$ make test

To run the tests on file changes:

$ env WATCH=true make test

License

BSD 3-Clause

About

🔩 Expressive runtime invariants for JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published