mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-26 03:26:41 +07:00
25 lines
431 B
JavaScript
25 lines
431 B
JavaScript
const canStore = typeof window.localStorage !== 'undefined'
|
|
|
|
export const storeData = (key, data) => {
|
|
if (!canStore) return;
|
|
|
|
const value = JSON.stringify(data);
|
|
|
|
localStorage.setItem(key, value);
|
|
};
|
|
|
|
export const getData = key => {
|
|
if (!canStore) return;
|
|
|
|
let result = null;
|
|
|
|
try {
|
|
result = JSON.parse(localStorage.getItem(key));
|
|
} catch(e) {
|
|
result = null;
|
|
}
|
|
|
|
if (!result) return;
|
|
|
|
return result;
|
|
};
|