Skip to content

Instantly share code, notes, and snippets.

@mariabitsch
Last active August 29, 2015 13:59
Show Gist options
  • Save mariabitsch/10832299 to your computer and use it in GitHub Desktop.
Save mariabitsch/10832299 to your computer and use it in GitHub Desktop.
Node modules for basic type checking
exports.isKindOf = function(duck, obj) {
var fn = function(obj) {
return Object.getOwnPropertyNames(duck).every(function(name) {
return obj.hasOwnProperty(name);
});
};
return obj === undefined ? fn : fn(obj);
};
["Object", "String", "Number", "Boolean", "Array", "Date", "RegExp"].forEach(function(type) {
exports["is" + type] = function(obj) {
return Object.prototype.toString.apply(obj) === "[object " + type + "]";
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment