Skip to content

Instantly share code, notes, and snippets.

@xeaone
Last active September 14, 2016 00:41
Show Gist options
  • Save xeaone/da55bff6ee13690d1ab8b49a82c0e3f7 to your computer and use it in GitHub Desktop.
Save xeaone/da55bff6ee13690d1ab8b49a82c0e3f7 to your computer and use it in GitHub Desktop.
Primitive Type Check
/*
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