
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
@sifrr/storage
Advanced tools
Browser key-value(JSON) storage library with cow powers. ~2KB alternative to localForage
| Type | Size |
|---|---|
Minified (dist/sifrr.storage.min.js) | |
Minified + Gzipped (dist/sifrr.storage.min.js) |
Add script tag in your website.
<script src="https://unpkg.com/@sifrr/storage@{version}/dist/sifrr.storage.min.js"></script>
// Adds window.Sifrr.Storage
| APIs | caniuse | polyfills |
|---|---|---|
| Promises API | https://caniuse.com/#feat=promises | https://github.com/stefanpenner/es6-promise |
| IndexedDB | https://caniuse.com/#feat=indexeddb | N/A |
| WebSQL | https://caniuse.com/#feat=sql-storage | N/A |
| LocalStorage | https://caniuse.com/#feat=namevalue-storage | N/A |
| Cookies | 100% | N/A |
Do npm i @sifrr/storage or yarn add @sifrr/storage or add the package to your package.json file.
example, put in your frontend js module (compatible with webpack/rollup/etc):
const Storage = require('@sifrr/storage');
import { getStorage } from '@sifrr/storage';
// or Sifrr.Storage.getStorage (script tag)
// or Storage.getStorage (node js import)
// or
// if you want to use one type of store without support checking based on priority
import { IndexedDB, WebSQL, LocalStorage, Cookies, JsonStorage } from '@sifrr/storage';
Sifrr.Storage uses Promises.
let storage = getStorage(type);
where type is one of indexeddb, websql, localstorage, cookies, jsonstorage.
Note: If that type is not supported in the browser, then first supported storage will be selected based on priority order.
// Options with default values
let options = {
priority: ['indexeddb', 'websql', 'localstorage', 'cookies', 'jsonstorage'], // Priority Array of type of storages to use
name: 'SifrrStorage', // name of table (treat this as a variable name, i.e. no Spaces or special characters allowed)
version: 1, // version number (integer / float / string), 1 is treated same as '1'
desciption: 'Sifrr Storage', // description (text)
size: 5 * 1024 * 1024, // Max db size in bytes only for websql (integer)
ttl: 0 // Time to live/expire for data in table (in ms), 0 = forever, data will expire ttl ms after saving
};
storage = getStorage(options);
Initializing with same priority, name and version will give same instance.
storage.type; // type of storage
storage.name; // name of storage
storage.version; // version number
// insert single key-value
let key = 'key';
let value = { value: 'value' };
storage.set(key, value).then(() => {
/* Do something here */
});
// insert multiple key-values
let data = { a: 'b', c: { d: 'e' } };
storage.set(data).then(() => {
/* Do something here */
});
// inserting with different ttl (30 seconds in example) than set in options
storage.set(key, { value, ttl: 30 * 1000 ).then(() => {
/* Do something here */
});
Note Cookies are trucated after ~628 characters in chrome (total of key + value characters), other browsers may tructae at other values as well. Use cookies for small data only
Set cookie that can be sent
storage.store = `key=value; expires=...; path=/`;
// get single key-value
storage.get('key').then(value => console.log(value)); // > { key: { value: 'value' } }
// get multiple key-values
storage.get(['a', 'c']).then(value => console.log(value)); // > { a: 'b', c: { d: 'e' } }
// delete single key-value
storage.del('key').then(() => {
/* Do something here */
});
// delete multiple key-values
storage.del(['a', 'c']).then(() => {
/* Do something here */
});
.set() will update the value as well.
storage.all().then(data => console.log(data)); // > { key: { value: 'value' }, a: 'b', c: { d: 'e' } }
storage.keys().then(keys => console.log(keys)); // > ['key', 'a', 'c']
storage.clear().then(() => {
// checking if data is deleted
storage.all().then(data => console.log(data)); // > {}
});
function some(a, b, c, d) {
// expensive computation
return 'a';
}
const memoizedSome = storage.memoize(some); // cache key is unique for unique first function argument
// custom cache key function, should return string
function cacheKeyFunction(a, b, c, d) {
return JSON.stringify(c);
}
const memoizedSomeCustomCache = storage.memoize(some, cacheKeyFunction);
Sifrr.Storage.all;
should be string
can be any of these types:
Array,ArrayBuffer,Blob,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Number,Object,Uint8Array,Uint16Array,Uint32Array,Uint8ClampedArray,Stringundefined when key is not present in the object, undefined is not supported as a value.null value has buggy behaviour in localstorage, as it returns null when value is not present.false or 0 which are supported by all storages.FAQs
Frontend key-value(JSON to JSON) persisted storage library
We found that @sifrr/storage 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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.