UNPKG

@beenotung/tslib

Version:
25 lines 847 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkedFetch = exports.polyfillFetch = exports.fetch = void 0; const tslib_1 = require("tslib"); const cross_fetch_1 = tslib_1.__importDefault(require("cross-fetch")); const runtime_1 = require("./runtime"); exports.fetch = cross_fetch_1.default; function polyfillFetch() { const win = runtime_1.getWindowOrGlobal(); win.fetch = win.fetch || exports.fetch; } exports.polyfillFetch = polyfillFetch; /** * check if the status code is 2xx * */ function checkedFetch({ input, init, on2xx, non2xx, }) { return exports.fetch(input, init).then(res => { if (200 <= res.status && res.status < 300) { return on2xx(res); } return non2xx(res); }); } exports.checkedFetch = checkedFetch; //# sourceMappingURL=fetch.js.map