Last active
August 29, 2015 13:59
-
-
Save mariabitsch/10832299 to your computer and use it in GitHub Desktop.
Node modules for basic type checking
This file contains hidden or 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
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); | |
}; |
This file contains hidden or 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
["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