angular-swx-session-storage
Version:
$sessionStorage service for use in your AngularJS applications.
11 lines (10 loc) • 1.3 kB
JavaScript
/**
* angular-swx-session-storage - $sessionStorage service for use in your AngularJS applications.
* @author Paul Massey, paul.massey@scriptwerx.io
* @version v1.0.0
* @build 30 - Tue Feb 09 2016 10:26:09 GMT+0000 (GMT)
* @link http://www.scriptwerx.io
* @license http://opensource.org/licenses/MIT
*/
!function(e){"use strict";function t(t,n,o){var r,s=n.host().substring(0,n.host().indexOf("."))+"_",i=6e4,a=!0,u=o("session-cache"),c=this;c.prefix=function(e){s=e+"_",u.destroy(),u=o(s+"cache")},c.put=function(t,n){var o={data:n};return arguments.length>2&&e.isNumber(arguments[2])&&(o.expires=(new Date).getTime()+arguments[2]*i),u.put(t,o),a&&r.setItem(s+t,e.toJson(o,!1)),n},c.get=function(t){var n;return u.get(t)?n=u.get(t):a&&(n=e.fromJson(r.getItem(s+t))),n?n.expires&&n.expires<(new Date).getTime()?void c.remove(t):(u.put(t,n),n.data):void 0},c.remove=function(e){c.put(e,void 0),a&&r.removeItem(s+e),u.remove(e)},c.empty=function(){a&&r.clear(),u.removeAll()},function(){try{r=t.sessionStorage;var e="swxTest_"+Math.round(1e7*Math.random());r.setItem(e,"test"),r.removeItem(e)}catch(n){a=!1}}()}t.$inject=["$window","$location","$cacheFactory"],e.module("swxSessionStorage",[]).service("$sessionStorage",t)}(window.angular);
//# sourceMappingURL=swx-session-storage.min.js.map