@scalar/api-client
Version:
the open source API testing client
21 lines (20 loc) • 1.01 kB
JavaScript
import { extractFilename as f } from "../libs/extractAttachmentFilename.js";
import { computed as n, isRef as c } from "vue";
import v from "whatwg-mimetype";
function R(t) {
const i = (a) => a instanceof Blob, e = n(() => c(t.data) ? t.data.value : t.data), u = n(() => c(t.headers) ? t.headers.value : t.headers), r = n(() => {
const a = u.value.find((o) => o.name.toLowerCase() === "content-type")?.value ?? "";
return new v(a);
}), l = n(() => {
const a = u.value.find((o) => o.name.toLowerCase() === "content-disposition")?.value ?? "";
return f(a);
}), s = n(() => i(e.value) ? URL.createObjectURL(e.value) : typeof e.value == "string" ? URL.createObjectURL(new Blob([e.value], { type: r.value.toString() })) : e.value instanceof Object && Object.keys(e.value).length ? URL.createObjectURL(
new Blob([JSON.stringify(e.value)], {
type: r.value.toString()
})
) : "");
return { mimeType: r, attachmentFilename: l, dataUrl: s };
}
export {
R as useResponseBody
};