mini-stash
A less-featured local/session storage wrapper. Read More.
Exported methods
stash
parameters:
- storageKey (string) - key assigned to data
- data (any) - value/object to store
- useSessionStorage (boolean, optional) - whether to use session vs local storage
retrieve
parameters:
- storageKey (string) - key assigned to data
- minutesToExpiration (number) - number of minutes till invalidation of stash data (pass 0 to disable expiration)
- useSessionStorage (boolean, optional) - whether to use sesssion vs local storage
clear
parameters:
- storageKey (string) - key assigned to data
- useSessionStorage (boolean, optional) - whether to use session vs local storage
Install
npm install mini-stash
Example
import { clear, stash, retrieve } from 'mini-stash';
const storageKey = 'myapp-coords';
let coords = retrieve(storageKey, 60 * 24);
if (!coords) {
coords = {
latitude: 33.441792,
longitude: -94.037689
};
stash(storageKey, coords);
} else {
console.log('retrieved from local storage');
clear(storageKey);
}
const loginStorageKey = 'myapp-login';
let loginData = retrieve(loginStorageKey, 0, true);
if (!loginData) {
loginData = {
uid: '021947'
};
stash(loginStorageKey, loginData, true);
} else {
console.log('retrieved from session storage');
clear(loginStorageKey, true);
}
Development
- Notes
- Written in TypeScript
- Compiled to UMD via WebPack
- Compiled to ES6 via TSC
- Typings generated by TSC
- Setup:
pnpm install
- Serve:
pnpm run start
See index.ejs
Runtimes
Latest tested runtimes