@scalar/api-client
Version:
the open source API testing client
17 lines (16 loc) • 762 B
JavaScript
import s from "whatwg-mimetype";
import { extractFilename as p } from "./extract-filename.js";
const f = (e) => e instanceof Blob;
function y({ data: e, headers: o }) {
const i = o.find((n) => n.name.toLowerCase() === "content-type"), t = i?.value ? new s(i.value) : void 0, r = p(
o.find((n) => n.name.toLowerCase() === "content-disposition")?.value ?? ""
), c = f(e) ? URL.createObjectURL(e) : typeof e == "string" ? URL.createObjectURL(new Blob([e], { type: t ? t.toString() : void 0 })) : e instanceof Object && Object.keys(e).length ? URL.createObjectURL(
new Blob([JSON.stringify(e)], {
type: t ? t.toString() : void 0
})
) : "";
return { mimeType: t, attachmentFilename: r, dataUrl: c };
}
export {
y as processResponseBody
};