Created
October 25, 2018 06:56
-
-
Save ilya-korotya/566691814f1901f0303a6de92e245b2a to your computer and use it in GitHub Desktop.
JS type verifier
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
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