Created
April 23, 2014 12:22
-
-
Save inhji/11213135 to your computer and use it in GitHub Desktop.
small type checkign lib
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
(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