env.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getEnvVariable = void 0;
  4. const hasCloudflareProxyContext = (context) => {
  5. var _a;
  6. return !!((_a = context === null || context === void 0 ? void 0 : context.cloudflare) === null || _a === void 0 ? void 0 : _a.env);
  7. };
  8. const hasCloudflareContext = (context) => {
  9. return !!(context === null || context === void 0 ? void 0 : context.env);
  10. };
  11. const getEnvVariable = (name, context) => {
  12. if (typeof process !== 'undefined' && process.env && typeof process.env[name] === 'string') {
  13. return process.env[name];
  14. }
  15. if (hasCloudflareProxyContext(context)) {
  16. return context.cloudflare.env[name] || '';
  17. }
  18. if (hasCloudflareContext(context)) {
  19. return context.env[name] || '';
  20. }
  21. if (context && typeof context[name] === 'string') {
  22. return context[name];
  23. }
  24. try {
  25. return globalThis[name];
  26. }
  27. catch (_) {
  28. }
  29. return '';
  30. };
  31. exports.getEnvVariable = getEnvVariable;