-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.js
More file actions
30 lines (25 loc) · 791 Bytes
/
storage.js
File metadata and controls
30 lines (25 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const KEY = "maturityTracker_v1";
export function loadState() {
const raw = localStorage.getItem(KEY);
if (!raw) return null;
try { return JSON.parse(raw); } catch { return null; }
}
export function saveState(state) {
localStorage.setItem(KEY, JSON.stringify(state));
}
export function resetState() {
localStorage.removeItem(KEY);
}
export function downloadJson(state, filename = "maturityTracker-export.json") {
const blob = new Blob([JSON.stringify(state, null, 2)], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
export async function importJsonFile(file) {
const text = await file.text();
return JSON.parse(text);
}