CrazySquirrel/EverCookie

View on GitHub
lib/Storages/GlobalStorage.js

Summary

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