Light(ish) wrapper around HTML5 localStorage that does useful things
JavaScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is 5 commits ahead of joshje:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
SmartStorage.js
SmartStorage.min.js

README.md

SmartStorage Light

This is a lightweight version of @ahume's HTML5 localStorage wrapper. It supports get, set and remove, including expiry dates and JSON objects.

Examples

var store = new SmartStorage("my_store");

// Store string.
store.set("key", "value");
store.get("key"); //=> "value"

// Remove string.
store.remove("key");
store.get("key"); //=> null

Expiry

Store object/hash with expiry time of 2 minutes.

store.set("my_object", {"key1": "value1", "key2": "value2"}, 120 * 1000); // Expires in 120*1000 = 2 minutes.
store.get("my_object").key2; //=> "value2"

Methods

  • set(key, val, [expiry]) - Set key to the value. Optional expiry time in milliseconds. Overrides anything that is already set.
  • get(key) - Get value for passed in key. Returns null if it doesn't exist.
  • remove(key) - Remove value for passed in key.