Fork me on GitHub

jsper by rob.mcvey

jsper documentation

Translate this page

Attributes

storage_engine [string]

String representation of current storage engine

support [bool]

Returns if the browser supports jsper

Methods

NOTE: All non-getters return this and are chainable

engine( optional storageEngine )

Sets or retrieves current storage engine depending on whether or not there is a storageEngine argument

jsper.engine();//localStorage
jsper.engine('session');//sessionStorage
            

set( key [string], value [string], optional session_lifetime [bool] )

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( key [array|string], optional callback [function], optional context [object])

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'));

            

raw_value( key [string] )

Returns the string value stored in key


jsper.raw_value('object');//{a:'foo', b:{value:'bar'}}

            

all()

Retrieves all objects stored in the current storage engine


var all = jsper.all();

            

clear()

Removes all items in current storage engine


//remove all items stored in current engine
jsper.clear();

            

remove( key [string] )

Remove a key from the current storage engine


jsper.remove('user');

            

remove_item( key [string], index [string|integer], optional callback [function], optional context [object] )

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));

            

each( key [array|string], )


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
});

            

Download

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