tru
Version:
```javascript tru(true) .then(function() { console.log('true'); }) .otherwise(function() { console.log('true'); }) .end(); ```
26 lines (22 loc) • 441 B
JavaScript
function tru(condition) {
if (!(this instanceof tru)) return new tru(condition);
this.is = !!condition;
return this;
}
tru.prototype.then = function(fn) {
this.truth = fn;
return this;
};
tru.prototype.otherwise = function(fn) {
this.falsity = fn;
return this;
}
tru.prototype.end = function() {
if (this.is) {
if (this.truth) this.truth()
} else {
if (this.falsity) this.falsity();
}
return this;
};
module.exports = tru;