UNPKG

1.06 kBJavaScriptView Raw
1/**
2 * This function returns the global object across Node and browsers.
3 *
4 * Note: `globalThis` is the standardized approach however it has been added to
5 * Node.js in version 12. We need to include this snippet until Node 12 EOL.
6 */
7export function getGlobal() {
8 if (typeof globalThis !== 'undefined') {
9 return globalThis;
10 }
11 if (typeof global !== 'undefined') {
12 return global;
13 }
14 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15 // @ts-ignore: Cannot find name 'window'.
16 if (typeof window !== 'undefined') {
17 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18 // @ts-ignore: Cannot find name 'window'.
19 return window;
20 }
21 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22 // @ts-ignore: Cannot find name 'self'.
23 if (typeof self !== 'undefined') {
24 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
25 // @ts-ignore: Cannot find name 'self'.
26 return self;
27 }
28}
29//# sourceMappingURL=get-global.util.js.map
\No newline at end of file