mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
25 lines
675 B
JavaScript
25 lines
675 B
JavaScript
import getLocalStorageMap from './localStorageKeyMap.js';
|
|
|
|
const updateLocalStorage = function(){
|
|
// Return if no window and thus no local storage
|
|
if(typeof window === 'undefined') return;
|
|
|
|
// Return if the local storage key map has no content
|
|
const localStorageKeyMap = getLocalStorageMap();
|
|
if(Object.keys(localStorageKeyMap).length == 0) return;
|
|
|
|
const storage = window.localStorage;
|
|
|
|
Object.keys(localStorageKeyMap).forEach((key)=>{
|
|
if(storage[key]){
|
|
if(!storage[localStorageKeyMap[key]]){
|
|
const data = storage.getItem(key);
|
|
storage.setItem(localStorageKeyMap[key], data);
|
|
};
|
|
storage.removeItem(key);
|
|
}
|
|
});
|
|
|
|
};
|
|
|
|
export { updateLocalStorage }; |