Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

LocalStorage like storage, simply use in service worker

License

Notifications You must be signed in to change notification settings

RyotaSugawara/serviceworker-storage

Repository files navigation

serviceworker-storage

Storage that can be used like a localStorage easy-to-use on ServiceWorker.

install

npm install --save serviceworker-storage

usage

new ServiceWorkerStorage(name, version)

create instance.

  • name: your storage name.
  • version: version number.
import ServiceWorkerStorage from 'serviceworker-storage';
const storage = new ServiceWorkerStoarge('MyStorage', 1);

length()

get storage length.

storage.length().then(len => {
  console.log(len);
});

key(index)

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);
});

getItem(key)

get item by key.

  • key: storage unique key.
storage.getItem('key').then(value => {
  console.log(value);
});

setItem(key, value)

set item to key.

  • key: storage unique key.
  • value: value you want to save.
storage.setItem(key, value);

removeItem(key)

remove item by key.

  • key: storage unique key.
storage.removeItem(key);

clear()

clean storage.

storage.clear();