Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsys/invar
:nut_and_bolt: Expressive runtime invariants for JavaScript
https://github.com/dsys/invar
Last synced: about 1 month ago
JSON representation
:nut_and_bolt: Expressive runtime invariants for JavaScript
- Host: GitHub
- URL: https://github.com/dsys/invar
- Owner: dsys
- License: bsd-3-clause
- Created: 2016-03-03T23:24:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-11T03:57:38.000Z (over 8 years ago)
- Last Synced: 2024-08-09T17:54:48.652Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 8
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The reign of poor error messages is over!
Expressive runtime invariants for JavaScript.## Installation
$ npm install invar --save
## Usage
```javascript
import invar from 'invar'
```---
### `invar(message)`
Check for truthiness.
#### Example
```javascript
invar(2 + 2 === 5, "I'm sorry Dave, I'm afraid I can't do that.")
```
#### ThrowsInvariant Violation: I'm sorry Dave, I'm afraid I can't do that.
---
### `invar.equal(actual, expected, message)`
Check for shallow equality.
#### Example
```javascript
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
```javascript
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
```javascript
function myFunction (mandatoryArg = invar.req('mandatoryArg')) {}
myFunction()
```#### Throws
Invariant Violation: Required argument 'mandatoryArg' not provided.
---
### `invar.fail(message)`
Always fail.
#### Example
```javascript
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](https://github.com/feross/standard), [Babel](https://babeljs.io/) for ES6+ support, and [Jest](http://facebook.github.io/jest/) for testing.
$ git clone [email protected]:pavlovml/invar.git
$ make testTo run the tests on file changes:
$ env WATCH=true make test
## License
[BSD 3-Clause](https://github.com/pavlovml/invar/blob/master/LICENSE)