npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

detonate

v0.0.2

Published

Go boom! with a clean, compact syntax for your javascript type checking.

Downloads

4

Readme

detonate

Go boom! with a clean, compact syntax for your javascript type checking.

Build Status Coverage Status

: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 detonate

Usage

const boom = require('detonate');

boom.if('foo').not.typeof('function');
//=> TypeError: Expected a function

Why?

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