@mjstahl/fluentstores

Fluent interface for Window.localStorage and Window.sessionStorage

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
10Apr 19, 2019Aug 3, 2018Minified + gzip package size for @mjstahl/fluentstores in KB

Readme

fluentstores

Fluent interface for Window.localStorage and Window.sessionStorage.

Installation

$ npm install --save @mjstahl/fluentstores
const storage = require('@mjstahl/fluentstores');

// localStorage
storage.local

// sessionStorage
storage.session

Storage

Storage.setItem(name: DOMString, value: DOMString) -> Storage

When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.

storage.local
  .setItem('bgcolor', 'yellow')
  .setItem('font', 'Helvetica')
  .setItem('image', 'cats.png');

window.localStorage.length //-> 3

Storage.removeItem(name: DOMString) -> Storage

When passed a key name, will remove that key from the storage.

storage.local
  .removeItem('bgcolor')
  .removeItem('font');

window.localStorage.length //-> 1

Storage.clear() -> Storage

When invoked, will empty all keys out of the storage.

storage.local
  .clear()
  .setItem('bgcolor', 'yellow')
  .getItem('bgcolor') //-> 'yellow'

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.