20 lines
615 B
TypeScript
20 lines
615 B
TypeScript
|
export const saveToLocalStorage = (key: string, data: any) => {
|
||
|
localStorage.setItem(key, JSON.stringify(data));
|
||
|
};
|
||
|
|
||
|
export const getFromLocalStorage = (key: string) => {
|
||
|
const data = localStorage.getItem(key);
|
||
|
return data ? JSON.parse(data) : null;
|
||
|
};
|
||
|
|
||
|
export const exportData = (data: any, filename: string) => {
|
||
|
const blob = new Blob([JSON.stringify(data, 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);
|
||
|
};
|
||
|
|
||
|
|