mini-stash
A less-featured local/session storage wrapper.
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 data = {
latitude: 33.441792,
longitude: -94.037689
};
const storageKey = 'myapp-coords';
stash(storageKey, data);
stash(data, false);
let coords = retrieve(storageKey, 60 * 24);
if (!coords) {
}
let sessionCoords = retrieve(storageKey, 0, true);
clear(storageKey);
clear(storageKey, 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