Skip to content

Instantly share code, notes, and snippets.

@vokeio vokeio/is.js
Last active Sep 14, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.