Last active
December 27, 2016 12:15
-
-
Save msudgh/34e1fef36b62eee04af0a8faa4b1c0f2 to your computer and use it in GitHub Desktop.
A module to detect the environment of the scripts is running
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
/** | |
* | |
* An module to detect the environment of the scripts is running. | |
* if the value of the module was true, the script is running on browser environment otherwise it's on Node.js | |
* | |
* @returns {boolean} - return a boolean object | |
* | |
* @example - import the module in your scripts and just call it. | |
* let detectENV = require('./detectENV.js') | |
* | |
* // return true or false according to the environment | |
* console.log(detectENV()) | |
*/ | |
module.exports = function () { | |
try { | |
return this === window | |
} catch (e) { | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment