detonate v0.0.2
detonate
Go boom! with a clean, compact syntax for your javascript type checking.
:boom: Note: This is currently in the beginning/experimental phases. Currently there is only support for equality and type checking. Please report any issues and use with caution. Pull requests welcome.
Install
$ npm install --save detonateUsage
const boom = require('detonate');
boom.if('foo').not.typeof('function');
//=> TypeError: Expected a functionWhy?
detonate saves you time and makes your programs more compact by taking these common checks:
if (typeof str !== 'string') {
    throw new TypeError('Expected a string');
}and converting them to this:
boom.if(str).not.typeof('string');Both blocks of code do the exact same thing (they throw the exact same error, if applicable), but detonate does the same with less code, and better readability.
You can also do the same thing with detonate's readability enhancers and aliases. For example, all of these statements are equivalent; You can work with the style you like the best:
// is.not.a
boom.if(str).is.not.a('string');
boom.if(str).not.a('string');
// is.not.typeof
boom.if(str).is.not.typeof('string');
boom.if(str).not.typeof('string');API
detonate.if(target)
target
Type: string|number|object|function
This is the item you want to evaluate for type, equality, etc.
chaining
You can chain new items onto the if() function, such as:
.not
.not negates the current operation
These two statements are opposite:
boom.if('string').typeof('function');
boom.if('string').not.typeof('function');.typeof(type)
.typeof will check the value of typeof <type>
boom.if('string').is.not.typeof('function');.equal(value)
.equal will check the equality of <value>
boom.if('foo').is.equal('bar');.equals(value)
.equals in an alias of .equal()
.a(type)
.a() is an alias of .typeof()
These statements are equivalent:
boom.if('string').is.not.a('function');
boom.if('string').is.not.typeof('function');Readability Enhancers
The only purpose of .is and .does is to enhance the readability of your statements.
For example, these statements are equivalent:
boom.if('foo').does.not.equal('bar');
boom.if('foo').is.not.equal('bar');
boom.if('foo').not.equal('bar');License
MIT © Michael Wuergler