sessionStorage made easy
If you ever had the pleasure of creating a sessionStorage you probably noticed a couple of things. For example: You might just be botherd by the lenghty name you have to type to save stuff in the sessionStoroge like: window.sessionStorage.setItem('key', 'value'). Or you might just want to add more key value pairs in the sessionStorage at once and do not want to loop over an array or object.
sessionJS might just be the solution, with short and flexible ways to enter or retrieve data from your sessionStorage.
Download this small script and add it to your HTML or require config. After this you just have four methods to add and remove data from window.sessionStorage
You can add data to the sessionStorage by calling S.set() with an object as parameter. This object needs to contain one or more key value pairs to add to the sessionStorage. Per examle:
var obj = {
"breed": "Border Collie",
"name": "Blaze",
"gender": "male"
};
S.set(obj);
Retrieve one, more or all data from the sessionStorage. S.get expects a string or array as parameter. When you do not send a parameter you will retrieve all data from the sessionStorage. S.get returns an object (key value pairs) with the data from sessionStorage.
var dogInfo = S.get();
var dogName = S.get('name'); //dogName == Blaze
var dog = S.get(['name', 'gender']);
Remove one or more items from the sessionStorage. S.clear expects a string or an array as parameter. When you do not send a parameter nothing will happen.
S.clear('name');
S.clear(['name', 'gender']);
Cleanup the sessionStorage deleting all data from the sessionStorage
S.destroy();