Skip to content

Instantly share code, notes, and snippets.

@ilya-korotya
Created October 25, 2018 06:56
Show Gist options
  • Save ilya-korotya/566691814f1901f0303a6de92e245b2a to your computer and use it in GitHub Desktop.
Save ilya-korotya/566691814f1901f0303a6de92e245b2a to your computer and use it in GitHub Desktop.
JS type verifier
function getTag(any) {
if (typeof any === 'object' && any !== null) {
if (typeof any[Symbol.toStringTag] === 'string') {
return any[Symbol.toStringTag];
}
if (typeof any.constructor === 'function'
&& typeof any.constructor.name === 'string') {
return any.constructor.name;
}
}
return Object.prototype.toString.call(any).match(/\[object\s(\w+)]/)[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment