UNPKG

showcar-storage

Version:

This module provides an abstraction layer for storing information on the client-side.

2 lines 4.21 kB
!function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f={local:c(1),session:c(2),cookie:c(3)},g=function(){function a(b){var c=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],e=c.silent,g=void 0===e?!0:e;d(this,a),b in f||this.fail("Storage: Unsupported type "+b),this.silent=!!g,this.store=new f[b]}return e(a,[{key:"get",value:function(a){var b=arguments.length<=1||void 0===arguments[1]?null:arguments[1];try{var c=this.store.get(a);return null===c?b:c}catch(d){return this.fail(d)}}},{key:"set",value:function(a,b,c){try{return this.store.set(a,b,c),this}catch(d){return this.fail(d)}}},{key:"has",value:function(a){try{return this.store.has(a)}catch(b){return this.fail(b)}}},{key:"remove",value:function(a){try{return this.store.remove(a),this}catch(b){return this.fail(b)}}},{key:"fail",value:function(a){if(this.silent)return!1;throw!a instanceof Error&&(a=new Error(a)),a}}]),a}();a.exports=g},function(a,b){"use strict";function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var d=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();a.exports=function(){function a(){c(this,a)}return d(a,[{key:"get",value:function(a){return localStorage.getItem(a)}},{key:"set",value:function(a,b){localStorage.setItem(a,b)}},{key:"has",value:function(a){return null!==localStorage.getItem(a)}},{key:"remove",value:function(a){localStorage.removeItem(a)}}]),a}()},function(a,b){"use strict";function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var d=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();a.exports=function(){function a(){c(this,a)}return d(a,[{key:"get",value:function(a){return sessionStorage.getItem(a)}},{key:"set",value:function(a,b){sessionStorage.setItem(a,b)}},{key:"has",value:function(a){return null!==sessionStorage.getItem(a)}},{key:"remove",value:function(a){sessionStorage.removeItem(a)}}]),a}()},function(a,b){"use strict";function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var d=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();a.exports=function(){function a(){c(this,a)}return d(a,[{key:"get",value:function(a){var b=this.matchSingleCookie(document.cookie,a);if(b instanceof Array&&void 0!==b[1])try{return decodeURIComponent(b[1])}catch(c){return b[1]}return null}},{key:"set",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],d=c.expires,e=void 0===d?"Fri, 31 Dec 9999 23:59:59 GMT":d,f=c.path,g=void 0===f?"/":f;!isNaN(parseFloat(e))&&isFinite(e)&&(e=new Date(Date.now()+1e3*parseInt(e)).toUTCString()),e instanceof Date&&(e=e.toUTCString()),document.cookie=[encodeURIComponent(a)+"="+encodeURIComponent(b),"expires="+e,"path="+g].join("; ")}},{key:"has",value:function(a){return null!==this.get(a)}},{key:"remove",value:function(a){this.set(a,"","Thu, 01 Jan 1970 00:00:00 GMT")}},{key:"matchSingleCookie",value:function(a,b){var c=encodeURIComponent(b).replace(/[-\.+\*]/g,"$&"),d=new RegExp("(?:(?:^|.*;)s*"+c+"s*=s*([^;]*).*$)|^.*$");return a.match(d)}}]),a}()}]); //# sourceMappingURL=showcar-storage.min.js.map