Skip to content

bopke/conditionally-execute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conditionally-execute

Lets you abandon "if" keyword

Install

Install with npm:

npm install 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();

About

Lets you abandon "if" keyword

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published