@beenotung/tslib
Version:
utils library in Typescript
29 lines • 885 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.is2xxResponse = exports.is2xxResponseStatus = exports.decodeResponse = void 0;
function decodeResponse(res) {
const contentType = res.headers.get('content-type');
if (!contentType) {
return res.blob();
}
if (contentType.includes('json')) {
return res.json();
}
if (contentType.includes('form')) {
return res.formData();
}
if (contentType.startsWith('text')) {
return res.text();
}
return res.blob();
}
exports.decodeResponse = decodeResponse;
function is2xxResponseStatus(status) {
return 200 <= status && status < 300;
}
exports.is2xxResponseStatus = is2xxResponseStatus;
function is2xxResponse(res) {
return is2xxResponseStatus(res.status);
}
exports.is2xxResponse = is2xxResponse;
//# sourceMappingURL=response.js.map