Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fourlabsldn/fl-assert

A simple assertion library for throwing errors
https://github.com/fourlabsldn/fl-assert

Last synced: 5 days ago
JSON representation

A simple assertion library for throwing errors

Awesome Lists containing this project

README

        

# fl-assert

Simple assertion functions to throw errors in the code.

Read the [DOCS](http://fourlabsldn.github.io/fl-assert/index.html)

[Check out the repo](https://github.com/fourlabsldn/fl-assert/)
## Usage
Use it like this:
``` javascript
const myCollection = [1, 2];

assert(myCollection.length > 0, 'myCollection must have at least one element'); // Nothing happens
assert(myCollection.length > 5, 'myCollection must have at least one element'); // Throws the string passed as an error message

assert.warn(typeof myCollection[0] === 'number', 'First element of collection is not a number'); // Nothing happens
assert.warn(typeof myCollection[0] === 'string', 'First element of collection is not a string'); // Logs a warning with the string passed as the warning message
```

## ES6
The main file in the dist folder is an ES6 module, and [it is specified as such](https://github.com/rollup/rollup/wiki/jsnext:main), so you can just write
this line below start rocking.
``` javascript
import assert from 'fl-assert'
```

## Install
### Bower
```
npm install --save-dev fl-assert
```