1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 19:01:42 +00:00
Files
seahub/frontend/src/metadata/metadata-view/_basic/utils/local-storage.js

29 lines
572 B
JavaScript
Raw Normal View History

class LocalStorage {
constructor(baseName) {
this.baseName = baseName || 'sf-metadata';
}
getStorage() {
try {
return JSON.parse(window.localStorage.getItem(this.baseName) || '{}');
} catch (error) {
return '';
}
}
setItem(key, value) {
const storage = this.getStorage();
const newValue = { ...storage, [key]: value };
return window.localStorage.setItem(this.baseName, JSON.stringify(newValue));
}
getItem(key) {
const storage = this.getStorage();
return storage[key];
}
}
export default LocalStorage;