
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
persistore
Advanced tools
The Persistore
is primary designed to use a very easy API (get
, set
, remove
)
to store any string with fallback strategies that apply automatically to each
client browser. So if localStorage
is not accessible it falls back internally to cookies
.
And if this would be neither possible, it will just use local variables, which is as
persistent as possible in this situation without any backend support.
TypeScript
support includednpm i --save persistore
import { Persistore } from 'persistore';
Persistore.set('my-key', '{"here": "comes your data"}');
console.log(Persistore.get('my-key')); // prints: '{"here": "comes your data"}'
Persistore.remove('my-key');
console.log(Persistore.get('my-key')); // prints: undefined
Same is possible for persistence restricted to session lifetime:
import { Persistore } from 'persistore';
Persistore.session.set('my-key', '{"here": "comes your data"}');
console.log(Persistore.session.get('my-key')); // prints: '{"here": "comes your data"}'
Persistore.session.remove('my-key');
console.log(Persistore.session.get('my-key')); // prints: undefined
And additional features to handle cookies is also included:
import { CookieUtil } from 'persistore';
CookieUtil.set('my-key', '{"here": "comes your data"}');
console.log(CookieUtil.get('my-key')); // prints: '{"here": "comes your data"}'
CookieUtil.remove('my-key');
console.log(CookieUtil.get('my-key')); // prints: undefined
// access all cookies
CookieUtil.getAll().forEach(([name, value]) => console.log(name, value)); // prints all cookies
HINT: Since most browsers have a strict cookie size limitation, the Persistore will throw an error if it would try to insert a cookie which exceeds the maximum size of 4093 bytes (iOS Safari reserves 3 additional bytes). The actual browser behaviour in that case would be to silently do nothing, what can lead to strange behaviour of your application. Therefore you should catch the possibly thrown error if you want to store large strings to handle this special case. Another useful information for you might be: localStorage and sessionStorage are not available on some browsers. The most common cases are iOS-Safari-Private-Mode users, where the Persistore will always fallback to cookies.
It is also possible to make some configuration. For now it is only the key prefixing and an opt-out for secure cookies (useful for localhost development).
import { Persistore } from 'persistore';
Persistore.config({ prefix: 'myApp.', insecure: IS_LOCALHOST });
FAQs
Automatically applying persistent storage with fallback strategies
The npm package persistore receives a total of 1,306 weekly downloads. As such, persistore popularity was classified as popular.
We found that persistore 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.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.