UNPKG

1.3 kBJavaScriptView Raw
1import checkGlobal from './_checkGlobal';
2
3/** Used to determine if values are of the language type `Object`. */
4var objectTypes = {
5 'function': true,
6 'object': true
7};
8
9/** Detect free variable `exports`. */
10var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
11 ? exports
12 : undefined;
13
14/** Detect free variable `module`. */
15var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
16 ? module
17 : undefined;
18
19/** Detect free variable `global` from Node.js. */
20var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
21
22/** Detect free variable `self`. */
23var freeSelf = checkGlobal(objectTypes[typeof self] && self);
24
25/** Detect free variable `window`. */
26var freeWindow = checkGlobal(objectTypes[typeof window] && window);
27
28/** Detect `this` as the global object. */
29var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
30
31/**
32 * Used as a reference to the global object.
33 *
34 * The `this` value is used if it's the global object to avoid Greasemonkey's
35 * restricted `window` object, otherwise the `window` object is used.
36 */
37var root = freeGlobal ||
38 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
39 freeSelf || thisGlobal || Function('return this')();
40
41export default root;