Last active
September 14, 2016 00:41
-
-
Save xeaone/da55bff6ee13690d1ab8b49a82c0e3f7 to your computer and use it in GitHub Desktop.
Primitive Type Check
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
/* | |
type: constructor name ('String', 'Array', 'Object', 'Function') | |
value: variable | |
*/ | |
function is (type, value) { | |
return !value ? false : value.constructor.name === type; | |
} | |
/* | |
use above function | |
*/ | |
function isArray (value) { | |
return !value ? false : value.constructor.name === 'Array'; | |
} | |
function isMap (value) { | |
return !value ? false : value.constructor.name === 'Map'; | |
} | |
function isObject (value) { | |
return !value ? false : value.constructor.name === 'Object'; | |
} | |
function isString (value) { | |
return !value ? false : value.constructor.name === 'String'; | |
} | |
function isNumber (value) { | |
return !value ? false : value.constructor.name === 'Number'; | |
} | |
function isFunction (value) { | |
return !value ? false : value.constructor.name === 'Function'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment