Skip to content

Instantly share code, notes, and snippets.

@CaptainLiao
Created January 10, 2018 02:09
Show Gist options
  • Save CaptainLiao/cb63693d7ed175d915091e886d9baf9f to your computer and use it in GitHub Desktop.
Save CaptainLiao/cb63693d7ed175d915091e886d9baf9f to your computer and use it in GitHub Desktop.
let typeReg = /^\[object (\w+)\]$/;
module.exports = function type(o) {
if(o === null) return 'null';
if(o === undefined) return 'undefined';
if(o !== o) return 'NaN';
let t = Object.prototype.toString.call(o).match(typeReg);
return t === null ? 'unknown' : t[1].toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment