node-cond

0.0.1 • Public • Published

node-cond

Install

npm install node-cond

Usage

var cond = require("node-cond");
/*
    cond(
        condition1, Then1,
        condition2, Then2,
        ...
        conditionN, ThenN,
        [defaultThen]
    )
*/
 
// ternary operator emulation
var test = cond(
    true, "t", "f"
);
// now test equal "t"
 
// usind function
var test = cond(
    true, () => "t", "f"
);
// test still equal "t"
// if Then is function it will be called with condition as arg
 
var test = cond(
    false, "no",
    null, "no",
    () => "this is default value. it will be returned"
)

cond.all

cond.all exec all Then after truthy conditionals and return the last. If default Then is defined it will be returned

cond.doif

cond.doif(Then, Else)(conditional)

Package Sidebar

Install

npm i node-cond

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • alv