1.4.1 • Published 7 years ago

storage-helper v1.4.1

Weekly downloads
452
License
ISC
Repository
github
Last release
7 years ago

Build Status npm version npm

storage-helper

A very simple way to manage browser storage.

If the browser doesn't support localStorage, data will be saved in a cookie. If the browser then doesn't support cookies either (not a lucky day!), it will be saved in a plain object! It also handles the QuotaExceeded error, silently logging it in the console and saving the data in the object.

Installation

npm install storage-helper

Usage

import storageHelper from 'storage-helper'

const storageKey = 'foo'
const value = 'bar'

// set item
storageHelper.setItem(storageKey, value)

// set an item not permanently  
storageHelper.setItem(storageKey, value, false)

// get item
const foo = storageHelper.getItem(storageKey)

// get item parsed
const foo = storageHelper.getItem(storageKey, true)

// remove item
storageHelper.removeItem(storageKey)

// remove all items
storageHelper.clear()

It's also possible to export single functions from the module

import { clear } from 'storage-helper'

clear()

The logger is by default set to false, so if you want to see logs during development, you can just do like so

import { showStorageLogger } from 'storage-helper'

showStorageLogger(true)
1.4.1

7 years ago

1.4.0

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.1-b

8 years ago

0.0.1

8 years ago