1 | export const fileDownload = (href, filename = "") => {
|
2 | const a = document.createElement("a");
|
3 | a.target = "_blank";
|
4 | a.href = href;
|
5 | a.download = filename;
|
6 | document.body.appendChild(a);
|
7 | a.dispatchEvent(new MouseEvent("click"));
|
8 | document.body.removeChild(a);
|
9 | };
|
10 | export const textDownload = (text, filename = "") => {
|
11 | const blob = new Blob([text], { type: "text/plain" });
|
12 | const url = URL.createObjectURL(blob);
|
13 | fileDownload(url, filename);
|
14 | setTimeout(() => URL.revokeObjectURL(url), 0);
|
15 | };
|