Last active
June 8, 2018 20:18
-
-
Save mmgj/171a0381e84367e3f161d53a982c9cfe to your computer and use it in GitHub Desktop.
Get type for any object
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
export function getBaseType(input) { | |
return ({}).toString.call(input).match(/\s([a-zA-Z]+)/)[1]; | |
} | |
export function getType(input, restricted = false) { | |
let output = getBaseType(input); | |
if (restricted) return output; | |
if (output.toLowerCase() === 'object') output = input.type ? input.type.name : input.constructor.name; | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment