hc_localstorage_plus
v1.1.1
Published
A localStorage wrapper that uses JavaScript Proxy to automatically sync changes to the localStorage.
Downloads
7
Readme
How
npm i hc_localstorage_plus
What
避免了繁琐的手动存储操作,并提供了更高的数据访问和修改安全性。 这使得代码更加简洁易读,易于维护和扩展。
why?
Former:
JSON.parse(localStorage.getItem(${key})) || {};
❌
optimization:
myLocalStorage.${key}
✅
Example
const key = "myObject";
const initialData = {
initData: "newData",
};
const myLocalStorage = new ProxiedLocalStorage(key, initialData);
// set it = localStorage.setItem(${key}, ${value})
myLocalStorage.initData = "change";
// get it = localStorage.getItem(${key}, ${value})
console.log(myLocalStorage.initData)