@mjstahl/fluentstores

0.4.3 • Public • Published

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'

Package Sidebar

Install

npm i @mjstahl/fluentstores

Weekly Downloads

0

Version

0.4.3

License

MIT

Unpacked Size

3.29 kB

Total Files

4

Last publish

Collaborators

  • mjstahl