Created
December 19, 2022 09:44
-
-
Save jkohlin/51bd76b1ea7aa15c3513384265d0773c to your computer and use it in GitHub Desktop.
A more fine grained typeof that returns e.g. 'array' | 'date' | etc
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
/** | |
* Description | |
* @param {any} value | |
* @returns {string} | |
*/ | |
function typeOf(value) { | |
return Object.prototype.toString | |
.call(value) | |
.replace(/^\[object\s+([a-z]+)\]$/i, '$1') | |
.toLowerCase() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment