Last active
August 29, 2015 14:04
-
-
Save inhji/047ebba3ace0ad94d54a to your computer and use it in GitHub Desktop.
Isso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isso = (function(root){ | |
var value = undefined; | |
function isso(v){ | |
return (v)? new inner(v): ex; | |
} | |
function inner(v){ | |
this.value = v; | |
return this; | |
} | |
// Undefined? | |
inner.prototype.undef = function undef(){ | |
return (this.value === null || this.value === undefined); | |
} | |
// Defined? | |
inner.prototype.def = function def(){ | |
return !this.undef(); | |
} | |
inner.prototype.empty = function(){ | |
return (this.def() || this.value === {} || this.value === "" || this.value === []); | |
} | |
inner.prototype.falsy = function falsy(){ | |
return (this.undef() || this.empty() || this.value === 0 || this.value === false); | |
}; | |
inner.prototype.truthy = function truthy(){ | |
return !this.falsy(); | |
}; | |
inner.prototype.type = function type(){ | |
return Object.prototype.toString.call(this.value).slice(8, -1).toLowerCase(); | |
}; | |
var ex = { | |
extend: function(name, fn) { | |
inner.prototype[name] = fn; | |
} | |
}; | |
return isso; | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment