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

allege

v2.0.1

Published

Make complex conditionals easier to read and write

Downloads

44

Readme

Allege

Make complex conditionals easier to read and write.

Build Status

Introduction

Sometimes, if statements can get very complex. For example:

if (foo.bar === 'value_a' || foo.bar === 'value_b' || foo.bar === 'value_c' || foo.bar === 'value_d' || foo.bar === 'value_e') {
    // do something
}

With Allege, you can simplify your if like so:

if (allege.that(foo.bar).isIn(
    'value_a', 
    'value_b', 
    'value_c', 
    'value_d',
    'value_e'
)) {
    // do something
}

API & Methods

Allege exposes different functions based on what you're trying to compare.

Single Input Commands

To use these methods, call allege.that() with just a single argument, like so: allege.that(foo). Then, these methods will be available:

isIn(possibility1, ..., possibilityN) -> boolean

Determines whether foo is referentially equal (===) to any of the possibility items.

allege.that(5).isIn(1, 2, 3, 4, 5, 6);
// --> true

allege.that('hi').isIn('hello', 'good morning', 'sup');
// --> false

isNotIn(possibility1, ..., possibilityN) -> boolean

Determines whether foo is referentially unequal (!==) to all of the possibility items.

allege.that(5).isNotIn(1, 2, 3, 4);
// --> true

allege.that(5).isNotIn(1, 2, 3, 4, 5);
// --> false

Multiple Input Commands

To use these methods, call allege.these() with more than one argument, like so: allege.these(foo, bar, baz, quux). Then, these methods will be available:

areAll(possibility) -> boolean

Determines whether all inputs are referentially equal (===) to the possibility item.

allege.these(5, 5, 5, 5).areAll(5);
// --> true

allege.these(5, 4, 5, 4).areAll(4);
// --> false

areAllNot(possibility) -> boolean

Determines whether all inputs are referentially unequal (!==) to the possibility item.

allege.these(5, 5, 5, 5).areAllNot(4);
// --> true

allege.these(5, 5, 5, 5).areAllNot(5);
// --> false

Installation

Grab this module from npm with the following command:

yarn add allege

Then you can use it in your project like so:

import allege from 'allege';
if (allege.that(5).isNotIn(1,2,3)) {
    // do something
}

// or:
import { that, these } from 'allege';
if (that(5).isNotIn(1,2,3)) {
    // do something
}

Versioning

This module follows SemVer.

License

MIT. See the LICENSE file for more details.

Testing

You can execute the existing test suite by running the following in your terminal:

yarn install
yarn test

Building From Source

The code that resides in the index.js file is transpiled from an ES6 source. The original source files reside in the src/ directory. These can be built with the following command:

yarn build