Flexible Storage
Module for front-end storage using LocalStorage (or any another Storage).
It introduces some features:
- allows choose between localStorage and sessionStorage
- define expiration date (using Moment or native Date instance)
- define storage key prefix or filter
- store any object as JSON
- written on TypeScript and includes TypeScript definition files
Installation
Using NPM:
npm i --save flexible-cache
Usage
You can use default import to use FlexibleStorage with Local
Instantiating
; // Using Session Storage and some string prefix; // Using Local Storage and function prefix;;
Note: prefix may be skipped
Caching values
; ; // also can be Moment.js instance; flexibleStorage.push'key', , expires;
Getting values
; ;// Value will be stored array or empty array if nothing stored;// Just to pull value with validating only key expiringvalue = flexibleStorage.pull'key';
Find more validators here
Other
; ;flexibleStorage.exists'key'; // will try to find and validate `prefix_key` in LocalStorageflexibleStorage.remove'key'; // will remove `prefix_key` from LocalStorage
Testing
npm test