Created
November 3, 2013 02:24
-
-
Save thekarel/7285807 to your computer and use it in GitHub Desktop.
Testing functions for JS types -- more @ https://github.com/thekarel/jstypes
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.isString = function(v) { | |
return (typeof v === 'string'); | |
} | |
exports.isInteger = function(v) { | |
return (parseInt(v) === v) | |
} | |
exports.isFloat = function(v) { | |
return ((v % 1) > 0) | |
} | |
exports.isBoolean = function(v) { | |
return (typeof v === 'boolean') | |
} | |
exports.isNull = function(v) { | |
return (v === null) | |
} | |
exports.isUndefined = function(v) { | |
return (typeof v === 'undefined') | |
} | |
exports.isNan = function(v) { | |
return (isNaN(v) && typeof v === 'number') | |
} | |
exports.isArray = function(v) { | |
return (v !== null && typeof v === 'object' && typeof v.length === 'number') | |
} | |
exports.isObject = function(v) { | |
return (v !== null && typeof v === 'object' && v.length === undefined) | |
} | |
exports.isFunction = function(v) { | |
return (typeof v === 'function') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment