Skip to content

Instantly share code, notes, and snippets.

@msudgh
Last active December 27, 2016 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msudgh/34e1fef36b62eee04af0a8faa4b1c0f2 to your computer and use it in GitHub Desktop.
Save msudgh/34e1fef36b62eee04af0a8faa4b1c0f2 to your computer and use it in GitHub Desktop.
A module to detect the environment of the scripts is running
/**
*
* 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