
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
localstorage-enhance
Advanced tools
English | δΈζ
PS: Do not do loop reference object or a large amount of data this violation.
npm install --save localstorage-enhance
import LocalStorage from 'localstorage-enhance';
// data can be of the following types
type Data = string | number | boolean | undefined | null | object;
LocalStorage.setItem({ key: 'demo', data: { test: 234 }});
const item = LocalStorage.getItem('demo'); // { test: 234 }
const unsettedItem = LocalStorage.getItem('unsetted'); // null
LocalStorage.removeItem('demo');
const item2 = LocalStorage.getItem('demo'); // null
import LocalStorage from 'localstorage-enhance';
LocalStorage.setItem({ key: 'namespace-demo', value: 'in-default'});
LocalStorage.setItem({ key: 'namespace-demo', value: 'in-namespace', namespace: 'some-namespace' });
const item1 = LocalStorage.getItem('namespace-demo'); // 'in-default'
const item2 = LocalStorage.getItem('namespace-demo', 'some-namespace'); // 'in-namespace'
import LocalStorage from 'localstorage-enhance';
LocalStorage.setItem({ key: 'maxAgeDemo', data: 'maxAge1000', maxAge: 1000 });
const item1 = LocalStorage.getItem('maxAgeDemo'); // 'maxAge1000'
setTimeout(() => {
const item2 = LocalStorage.getItem('maxAgeDemo'); // null
}, 1500);
If you want to customize the capacity of the LRU elimination mechanism, you can manually generate an instance and specify the storageKey and capacity.
import LocalStorage, { LocalStorageClass } from 'localstorage-enhance';
import from 'localstorage-enhance';
// default LocalStorage instance
// LocalStorage = new LocalStorageClass({ storageKey: 'localStorage_enhance', capacity: 200, encrypt: false });
const MyLocalStorage = new LocalStorageClass({ storageKey: 'my_localStorage', capacity: 50 });
Manually generate an instance, set encrypt to true and it will encrypt the data in base64
import { { LocalStorageClass } } from 'localstorage-enhance';
const MyLocalStorage = new LocalStorageClass({ storageKey: 'encrypt_localStorage', encrypt: true });
LocalStorage.setMuilty([{ key: 'string', data: 'string' }, { key: 'boolean', data: false }, { key: 'object', data: { test: 324} }]);
const muiltyRes = LocalStorage.getMuilty(['string', 'boolean', 'object', 'unset']);
// muiltyRes = { string: 'string', boolean: false, object: { test: 324 }, unset: null }
// Chain call
LocalStorage
.setItem({ key: '1', data: 1 })
.setItem({ key: '2', data: 2 });
interface LocalStorage {
setItem: ({ key, data, maxAge, namespace }: {
key: string;
data: Data;
maxAge?: number | undefined;
namespace?: string | undefined;
}) => this;
setMuilty: (dataObjs: Array<{
key: string;
data: Data;
maxAge?: number;
namespace?: string;
}>) => this;
getItem: (key: string, namespace?: string) => Data;
getMuilty: <T extends string>(keys: T[], namespace?: string) => { [K in T]: Data; };
removeItem: (key: string, namespace?: string) => Data;
removeMuilty: <T extends string>(keys: T[], namespace?: string) => { [K in T]: Data; };
clearNamespace: (namespace: string) => this;
clearAll: () => this;
}
Run the demos:
npm install
npm run test
npm install
npm run build
MIT
FAQs
Enhanced version of localStorage
The npm package localstorage-enhance receives a total of 79 weekly downloads. As such, localstorage-enhance popularity was classified as not popular.
We found that localstorage-enhance demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.