You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
801 B
JavaScript

export function utils() {
const base64ToBlob = async (dataUrl, fileName) => {
const res = await fetch(dataUrl);
const blob = await res.blob();
return new File([blob], fileName, { type: 'image/jpeg' });
}
const blobToBase64 = (blob) => {
return new Promise((resolve, _) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(blob)
})
}
const download = (content, fileName, contentType) => {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
return {base64ToBlob, blobToBase64, download}
}