CrazySquirrel/EverCookie

View on GitHub
lib/Storages/LocalStorage.js

Summary

Maintainability
A
0 mins
Test Coverage
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("EverCookie",[],t):"object"==typeof exports?exports.EverCookie=t():e.EverCookie=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=37)}({37:function(e,t,r){e.exports=r(4)},4:function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=function(){function e(t){n(this,e),this.regValidKey=new RegExp("([a-zA-Z0-9_-]{0,})","i"),this.hash=t||location.hostname}return o(e,[{key:"isSupported",value:function(){return void 0!==window.localStorage}},{key:"setItem",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=arguments[1],r=arguments[2];try{if("boolean"==typeof e&&"string"==typeof t&&this.regValidKey.test(t)&&"string"==typeof r&&(""===r||this.regValidKey.test(r))){if(!e||this.isSupported()){var n=this.hash+"_"+t;return window.localStorage.setItem(n,r),this.getItem(e,t)===r}return!1}return!1}catch(e){return!1}}},{key:"getItem",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=arguments[1];try{if("boolean"==typeof e&&"string"==typeof t&&this.regValidKey.test(t)){if(!e||this.isSupported()){var r=this.hash+"_"+t,n=window.localStorage.getItem(r);return n||!1}return!1}return!1}catch(e){return!1}}},{key:"removeItem",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=arguments[1];try{if("boolean"==typeof e&&"string"==typeof t&&this.regValidKey.test(t)){if(!e||this.isSupported()){var r=this.hash+"_"+t;return window.localStorage.removeItem(r),!1===this.getItem(e,t)}return!1}return!1}catch(e){return!1}}},{key:"getKeys",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];try{if("boolean"==typeof e){if(!e||this.isSupported()){for(var t=[],r=0;r<window.localStorage.length;r++)0===window.localStorage.key(r).indexOf(this.hash)&&t.push(window.localStorage.key(r).substr(this.hash.length+1));return t}return[]}return[]}catch(e){return[]}}},{key:"clear",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];try{if("boolean"==typeof e){if(!e||this.isSupported()){var t=this.getKeys(e);if(t)for(var r=0;r<t.length;r++){var n=t[r];this.removeItem(e,n)}return 0===this.getKeys(e).length}return!0}return!1}catch(e){return!1}}}]),e}();t.default=i}})});