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.
30 lines
727 B
TypeScript
30 lines
727 B
TypeScript
import type { AST } from './ast'
|
|
import type { Store } from './store'
|
|
|
|
const STORAGE_KEY = 'cg_store';
|
|
|
|
export function saveStore(store: Store) {
|
|
const data: Record<string, any> = {};
|
|
for (const [name, entry] of store) {
|
|
data[name] = {
|
|
body: entry.body,
|
|
source: 'file'
|
|
};
|
|
}
|
|
// localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
|
|
}
|
|
|
|
export function loadStore(): Record<string, { body: AST, source: string }> | null {
|
|
try {
|
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
if (!raw) return null;
|
|
return JSON.parse(raw);
|
|
} catch(e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function clearStore() {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
}
|