Storage that can be used like a localStorage easy-to-use on ServiceWorker.
npm install --save serviceworker-storage
create instance.
- name: your storage name.
- version: version number.
import ServiceWorkerStorage from 'serviceworker-storage';
const storage = new ServiceWorkerStoarge('MyStorage', 1);
get storage length.
storage.length().then(len => {
console.log(len);
});
get key by index.
- index: An integer representing the number of the key you want to get the name of.
storage.key(0).then(key => {
console.log(key);
});
get item by key.
- key: storage unique key.
storage.getItem('key').then(value => {
console.log(value);
});
set item to key.
- key: storage unique key.
- value: value you want to save.
storage.setItem(key, value);
remove item by key.
- key: storage unique key.
storage.removeItem(key);
clean storage.
storage.clear();