Skip to content

Davide-Gheri/storage

Repository files navigation

Storage

Build Status Coverage Status npm version GitHub version Greenkeeper badge

Small browser storage API library

Usage

    var storage = new Storage('localstorage');
    storage.set('key', 'hello world'); // true
    storage.get('key') // hello world

Available adapters:

  • localstorage : Use the window.localstorage
  • sessionstorage : Use the window.sessionstorage
  • cookie : Use the document.cookie string
Methods

set(key, value, options? (cookie only)): boolean

set the given value in the storage by the given key, options: for cookie storage you can pass storing options that overwrites the defaults

get(key, default?): any

get the value from the storage by the given key, optional default value is returned if nothing is found

delete(key): boolean

remove the value from the storage by the given key

clear(): void

remove all values from the storage