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
; // it's a good idea to prefix storage keysconst storageKey = 'myapp-coords'; // retrieve from local storage (discard if older than a day)let coords = ;if !coords // ... get the coords coords = latitude: 33441792 longitude: -94037689 ; // save to local storage ; else console; // manually clear from local storage ; // retrieve from session storage (disable expiration)const loginStorageKey = 'myapp-login';let loginData = ;if !loginData // ... get login data loginData = uid: '021947' ; // save to session storage ; else console; // manually clear from session storage ;
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
- node: 10.16.3
- pnpm: 5.3.0