jose/dist/browser/runtime/global.js
2021-09-10 11:21:11 +02:00

27 lines
725 B
JavaScript

function getGlobal() {
if (typeof globalThis !== 'undefined')
return globalThis;
if (typeof self !== 'undefined')
return self;
if (typeof window !== 'undefined')
return window;
throw new Error('unable to locate global object');
}
export default getGlobal();
export function isCloudflareWorkers() {
try {
return getGlobal().WebSocketPair !== undefined;
}
catch (_a) {
return false;
}
}
export function isNodeJs() {
var _a, _b;
try {
return ((_b = (_a = getGlobal().process) === null || _a === void 0 ? void 0 : _a.versions) === null || _b === void 0 ? void 0 : _b.node) !== undefined;
}
catch (_c) {
return false;
}
}