Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Created June 18, 2013 11:25
Show Gist options
  • Save vladimir-ivanov/5804619 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/5804619 to your computer and use it in GitHub Desktop.
AngularJs browser session storage wrapper
/*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, forin:true, latedef:true, newcap:true, noarg:true,
noempty:true, nonew:true, undef:true, unused:true, strict:true, browser:true, camelcase:false */
/*globals
_: false
*/
/*exported
BrowserStorageFactory
*/
var BrowserStorageFactory = function () {
'use strict';
var storage = sessionStorage;
return {
get: function (item) {
if (_.isFunction(storage.getItem)) {
return JSON.parse(storage.getItem(item) || null);
}
},
set: function (item, value) {
if (_.isFunction(storage.setItem)) {
storage.setItem(item, JSON.stringify(value));
}
},
clear: function () {
if (_.isFunction(storage.clear)) {
storage.clear();
}
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment