tru
Version:
```javascript tru(true) .then(function() { console.log('true'); }) .otherwise(function() { console.log('true'); }) .end(); ```
29 lines (24 loc) • 1.28 kB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.tru=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var noop = function() {};
function tru(condition) {
if (!(this instanceof tru)) return new tru(condition);
this.is = !!condition;
this.truth = noop;
this.falsity = noop;
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() {
this.is ? this.truth() : this.falsity();
return this;
};
module.exports = tru;
},{}]},{},[1])(1)
});