mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
24 lines
590 B
TypeScript
24 lines
590 B
TypeScript
type MimeType = "image/svg+xml" | "application/zip";
|
|
|
|
interface Download {
|
|
content: string | Blob;
|
|
filename: string;
|
|
mimeType: MimeType;
|
|
}
|
|
|
|
export const download = ({ content, filename, mimeType }: Download) => {
|
|
const blob =
|
|
typeof content === "string"
|
|
? new Blob([content], { type: mimeType })
|
|
: content;
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.style.display = "none";
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(url);
|
|
};
|