Skip to content

Instantly share code, notes, and snippets.

@inhji
Created April 23, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inhji/11213135 to your computer and use it in GitHub Desktop.
Save inhji/11213135 to your computer and use it in GitHub Desktop.
small type checkign lib
(function (root) {
"use strict";
var nativeToString = Object.prototype.toString,
callToString = function (v) {
return nativeToString.call(v)
.replace(/\[object\s{1}|\]/g, "")
.toLowerCase();
},
compareToType = function (v, type) {
var s = callToString(v);
return s === type || s.substr(0, 3) === type;
};
function BaseClass(arg) {
var self = this;
self.value = arg;
self.type = callToString(arg);
self.is = function (type) {
if (type) { return compareToType(self.value, type); }
return callToString(self.value);
};
}
function wrapper(arg) {
return new BaseClass(arg);
}
if (typeof exports !== "undefined") {
if (typeof module !== "undefined" && module.exports) {
exports = module.exports = wrapper;
}
exports.\u00df = wrapper;
} else {
root.\u00df = wrapper;
}
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment