Created
January 10, 2018 02:09
-
-
Save CaptainLiao/cb63693d7ed175d915091e886d9baf9f to your computer and use it in GitHub Desktop.
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
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