Skip to content

Instantly share code, notes, and snippets.

@BeauBouchard
Created October 2, 2019 20:22
Show Gist options
  • Save BeauBouchard/c370b345b699683fe89c70d0c1ce1b33 to your computer and use it in GitHub Desktop.
Save BeauBouchard/c370b345b699683fe89c70d0c1ce1b33 to your computer and use it in GitHub Desktop.
/**
* @return {boolean} true whether inside a node application or not.
**/
function isNode () {
try {
return "object" === typeof process && Object.prototype.toString.call(process) === "[object process]";
} catch(e) {}
return false;
}
/**
* @return {boolean} true if inside a chrome extension or not
**/
function isExtension () {
try {
return window.chrome && chrome.runtime && chrome.runtime.id;
} catch(e) {}
return false;
}
/**
* @return {boolean} true if inside a react native app
**/
function isReactNative () {
try {
return navigator && navigator.product == "ReactNative";
} catch(e) {}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment