get-global.util.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getGlobal = void 0;
  4. /**
  5. * This function returns the global object across Node and browsers.
  6. *
  7. * Note: `globalThis` is the standardized approach however it has been added to
  8. * Node.js in version 12. We need to include this snippet until Node 12 EOL.
  9. */
  10. function getGlobal() {
  11. if (typeof globalThis !== 'undefined') {
  12. return globalThis;
  13. }
  14. if (typeof global !== 'undefined') {
  15. return global;
  16. }
  17. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  18. // @ts-ignore: Cannot find name 'window'.
  19. if (typeof window !== 'undefined') {
  20. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  21. // @ts-ignore: Cannot find name 'window'.
  22. return window;
  23. }
  24. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  25. // @ts-ignore: Cannot find name 'self'.
  26. if (typeof self !== 'undefined') {
  27. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  28. // @ts-ignore: Cannot find name 'self'.
  29. return self;
  30. }
  31. }
  32. exports.getGlobal = getGlobal;
  33. //# sourceMappingURL=get-global.util.js.map