Skip to content

Instantly share code, notes, and snippets.

@mmgj
Last active June 8, 2018 20:18
Show Gist options
  • Save mmgj/171a0381e84367e3f161d53a982c9cfe to your computer and use it in GitHub Desktop.
Save mmgj/171a0381e84367e3f161d53a982c9cfe to your computer and use it in GitHub Desktop.
Get type for any object
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