Skip to content

Instantly share code, notes, and snippets.

@inhji
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inhji/047ebba3ace0ad94d54a to your computer and use it in GitHub Desktop.
Save inhji/047ebba3ace0ad94d54a to your computer and use it in GitHub Desktop.
Isso
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