@splitsoftware/splitio
Version:
27 lines (26 loc) • 879 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFetch = exports.__setFetch = void 0;
var nodeFetch;
try {
nodeFetch = require('node-fetch');
// Handle node-fetch issue https://github.com/node-fetch/node-fetch/issues/1037
if (typeof nodeFetch !== 'function')
nodeFetch = nodeFetch.default;
}
catch (error) {
// Try to access global fetch if `node-fetch` package couldn't be imported (e.g., not in a Node environment)
nodeFetch = typeof fetch === 'function' ? fetch : undefined;
}
// This function is only exposed for testing purposes.
function __setFetch(fetch) {
nodeFetch = fetch;
}
exports.__setFetch = __setFetch;
/**
* Retrieves 'node-fetch', a Fetch API polyfill for Node.js, with fallback to global 'fetch' if available.
*/
function getFetch() {
return nodeFetch;
}
exports.getFetch = getFetch;