conditionally-execute

1.0.0 • Public • Published

conditionally-execute

Lets you abandon "if" keyword

Install

Install with npm:

npm install bopke/conditionaly-execute

Usage

const ConditionallyExecute = require('conditionally-execute');

It's extremely easy to start using conditionally-execute, with its simple, straightforward and intelligible design.

Just take a look on that piece of code:

function thatsTrue(){
    console.log("True!");
}
function thatsNotTrue(){
    console.log("False!");
}
 
new ConditionallyExecute().condition(1===1).onTrue(thatsTrue).onFalse(thatsNotTrue).execute();

The above code will, obviously, print out "True!".

It doesn't matter how we order method calls, as long as execute() method is the last one of our chain. Method calls from the above example can be as well ordered like this:

new ConditionallyExecute().onFalse(thatsNotTrue).condition(1===1).onTrue(thatsTrue).execute();

Usage with existing code

Obviously, this library does not collide with any existing if statements. It's also ultra-easy to refactor your existing code to make it make a good use of conditionally-execute. Just look on that example:

old, ugly iffed code:

if(condition){
    console.log("yes");
}else{
    console.log("no");
}

new, beautiful conditionally-executed code:

new ConditionallyExecute().condition(condition).onTrue(()=>{console.log("yes");}).onFalse(()=>{console.log("no");}).execute();

Package Sidebar

Install

npm i conditionally-execute

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.04 kB

Total Files

4

Last publish

Collaborators

  • bopke