Skip to content

Instantly share code, notes, and snippets.

@crapthings
Created January 11, 2018 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crapthings/4aaecb00c53609fdd4b3aaa336b6c35f to your computer and use it in GitHub Desktop.
Save crapthings/4aaecb00c53609fdd4b3aaa336b6c35f to your computer and use it in GitHub Desktop.
check type
function isString(target) {
return isType(target, 'String')
}
function isNumber(target) {
return isType(target, 'Number')
}
function isDate(target) {
return isType(target, 'Date')
}
function isFunction(target) {
return isType(target, 'Function')
}
function isObject(target) {
return isType(target, 'Object')
}
function isArray(target) {
return isType(target, 'Array')
}
function isType(target, type) {
return Object.prototype.toString.call(target) === `[object ${type}]` ? true : false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment