/localstorage

Simple localStorage abstraction

Primary LanguageJavaScriptMIT LicenseMIT

putainde-localstorage

Build Status

browser support

A simple localStorage abstraction

localstorage allows you to easily store & use JSON data.

Installation

You can install putainde-localstorage from npm

$ npm install putainde-localstorage (--save)

putainde-localstorage can obviously be downloaded directly.

Usage

var localstorage = require("putainde-localstorage")

// create instance
var storage = localstorage.create({namespace: "myComponent"})
// same as
var LocalStorage = require("putainde-localstorage")
var storage = new LocalStorage({namespace: "myComponent"})

// set & get
storage.set("foo", {bar: "baz"})
storage.get("foo") // => {bar: "baz"}

// remove
storage.remove("foo")

// remove all
storage.clear()

localstorage.create(options) > storage

Create a new instance (== new localstorage(options))

options

options.namespace

Use a namespace for all your data stored (default storage.)

storage.set(key, value)

Setter. Accept string, numeric, object...

storage.set({key: value})

Alternative way to set (multiple) value(s).

storage.get(key)

Getter.

storage.get()

Returns all values.

storage.remove(key)

Remove a value.

storage.clear()

Remove all values.


Contributing

Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.

git clone https://github.com/putaindecode/localstorage.git
git checkout -b patch-1
npm install
npm test