Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
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 13 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.