CrazySquirrel/EverCookie

View on GitHub
lib/Storages/DOMStorage.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=35)}({2: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,this.domStorage=document.getElementById(this.hash),this.domStorage||(this.domStorage=document.createElement("div"),this.domStorage.id=this.hash),document.body&&(document.body.appendChild(this.domStorage),this.domStorage=document.getElementById(this.hash),this.isSupported()&&(this.domStorage.style.behavior="url(#default#userData)"))}return i(t,[{key:"isSupported",value:function(){return"object"===n(this.domStorage)&&"object"===n(this.domStorage.parentNode)&&void 0!==this.domStorage.addBehavior}},{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.domStorage.setAttribute(o,r),this.domStorage.save(this.hash),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;this.domStorage.load(this.hash);var o=this.domStorage.getAttribute(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.domStorage.removeAttribute(r),this.domStorage.save(this.hash),!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=this.domStorage.XMLDocument.documentElement.attributes,o=0;o<r.length;o++){var n=r[o].name;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},35:function(t,e,r){t.exports=r(2)}})});