Created
January 26, 2016 22:48
-
-
Save raphamorim/f1ba6936f247fd3bcd5f 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
// From QUnit.js | |
function objectType( obj ) { | |
if ( typeof obj === "undefined" ) { | |
return "undefined"; | |
} | |
// Consider: typeof null === object | |
if ( obj === null ) { | |
return "null"; | |
} | |
var match = toString.call( obj ).match( /^\[object\s(.*)\]$/ ), | |
type = match && match[ 1 ]; | |
switch ( type ) { | |
case "Number": | |
if ( isNaN( obj ) ) { | |
return "nan"; | |
} | |
return "number"; | |
case "String": | |
case "Boolean": | |
case "Array": | |
case "Set": | |
case "Map": | |
case "Date": | |
case "RegExp": | |
case "Function": | |
case "Symbol": | |
return type.toLowerCase(); | |
} | |
if ( typeof obj === "object" ) { | |
return "object"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment