String representation of current storage engine
Returns if the browser supports jsper
Sets or retrieves current storage engine depending on whether or not there is a storageEngine argument
jsper.engine();//localStorage jsper.engine('session');//sessionStorage
Inserts value into storage block labeled with key
jsper.set('foo', {bar:'baz',boz:{bez:'biz'}}); jsper.set('arr', ['a', 'b', 'c', 'd']); jsper.set('message', 'hello world!'); //setting multiple items at the same time var obj = { line1:"This makes things", line2:"a bit easier" }; jsper.set( obj ); jsper.set( 'temporary', 'gone when session ends', true);
Get an item by key, note that if the key is not found in the current engine, jsper will check all available storage engines
// pass a string var an_obj = jsper.get('foo'); // pass an array var two_keys = jsper.get(['key1', 'key2']); var link = "<a href='http://www.badsite.com'>Bad link</a>"; jsper.set('link', link); // pass a callback to the get method var stripped = jsper.get('link', function(data){ return data.replace(/<.*?>/g, ''); }); // pass a callback and a context (context is an object of any kind, typically a DOM object though) jpser.get('link', function(data){ this.html( data ); }, $('#link_container'));
Returns the string value stored in key
jsper.raw_value('object');//{a:'foo', b:{value:'bar'}}
Retrieves all objects stored in the current storage engine
var all = jsper.all();
Removes all items in current storage engine
//remove all items stored in current engine jsper.clear();
Remove a key from the current storage engine
jsper.remove('user');
Removes an individual array element or object attribute from key, optionally performs a callback
//remove the third element from the array jsper.remove_item('my_array', 3); //remove the b key from my_object jsper.remove_item('my_object', 'b'); // using callback and context jsper.remove_item('rows', 4, function(data){ this.fadeOut(); }, $('#table').eq(4));
var total = 0; jsper.each('scores', function(score, index){ total += score; }); // each with array argument jsper.each(['first_round', 'second_round'], function(score, index){ total += score });
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/rmcvey/jsper