1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-24 06:33:54 +02:00

add data import/export (#11)

This commit is contained in:
Morris Brodersen
2024-06-24 07:25:56 +02:00
parent 7204404fdc
commit 46932737bc
5 changed files with 101 additions and 0 deletions

View File

@@ -84,3 +84,16 @@ export const MONTH_NAMES = [
export function formatMonth(date) {
return MONTH_NAMES[date.getMonth()];
}
/**
* https://developer.mozilla.org/en-US/docs/Glossary/Base64
* @param {BlobPart} input
*/
export async function toDataURL(input, type) {
return await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener('load', () => resolve(reader.result));
reader.addEventListener('error', () => reject(reader.error));
reader.readAsDataURL(new File([input], '', { type }));
});
}