Skip to content
Wrapper around the window.localStorage with useful functionality apart from normal get/set value. For example: JSON/Boolean/Number accessors, event registering for type create/update/remove/clear events.
JavaScript HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
LS.js
LS_Test.js
README.md
gulpfile.js
package.json
test.html

README.md

LS

Continuous Integration: Build Status
License: Apache 2.0

Wrapper around the window.localStorage with useful functionality apart from normal get/set value.

For example

  • Accessors for JSON/Boolean/Number,
  • Event registering for type create/update/remove/clear events

###API functions

LS.set(key, value)
LS.setJson(key, jsonObject)
LS.remove(key)
LS.clear()

LS.get(key): String
LS.getJson(key): JsonObject
LS.getNumber(key): Int
LS.getBoolean(key): Boolean


//Event API
LS.on(event, listenerFunction, scope): function //this return function can be used for unregistering from event

//different type and listeners callback param
events type: 'create'	listenerFunction callback param: key, value
events type: 'update'	listenerFunction callback param: key, newValue, oldValue
events type: 'remove'	listenerFunction callback param: key
events type: 'clear'	listenerFunction callback param:

//remove all the registered event for given event type
LS.removeAllEventListeners(eventType) 

Event registering/unregistering example

//registering listener
var updateListenerFn = LS.on('update', function(key, newValue, oldValue){
	//code	
});

//unregistering listener
LS.un('update', updateListenerFn);
You can’t perform that action at this time.