UNPKG

@splitsoftware/splitio-commons

Version:
27 lines (26 loc) 930 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEventSource = exports.__restore = exports.__setEventSource = void 0; var __isCustom = false; var __eventSource; // This function is only exposed for testing purposes. function __setEventSource(eventSource) { __eventSource = eventSource; __isCustom = true; } exports.__setEventSource = __setEventSource; function __restore() { __isCustom = false; } exports.__restore = __restore; function getEventSource() { // returns EventSource at `eventsource` package. If not available, return global EventSource or undefined try { return __isCustom ? __eventSource : require('./eventsource'); } catch (error) { // eslint-disable-next-line no-undef -- Feature detection for EventSource return typeof EventSource === 'function' ? EventSource : undefined; } } exports.getEventSource = getEventSource;