CrazySquirrel/EverCookie

View on GitHub
lib/Storages/Cookies.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(n){if(o[n])return o[n].exports;var r=o[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var o={};return e.m=t,e.c=o,e.i=function(t){return t},e.d=function(t,o,n){e.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=34)}({1:function(t,e,o){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r="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 o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,o,n){return o&&t(e.prototype,o),n&&t(e,n),e}}(),u=function(){function t(e){n(this,t),this.regValidKey=new RegExp("([a-zA-Z0-9_-]{0,})","i"),this.hash=e||location.hostname}return i(t,[{key:"isSupported",value:function(){return"object"===("undefined"==typeof document?"undefined":r(document))&&"string"==typeof document.cookie}},{key:"setItem",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],e=arguments[1],o=arguments[2],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:30,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"/",i=arguments.length>5&&void 0!==arguments[5]?arguments[5]:void 0,u=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"https:"===location.protocol;try{if(void 0===i){var s=location.hostname.split(".");i=(s.length>2?".":"")+s.join(".")}if("boolean"==typeof t&&"string"==typeof e&&this.regValidKey.test(e)&&"string"==typeof o&&(""===o||this.regValidKey.test(o))&&"number"==typeof n&&n<365&&"string"==typeof r&&"string"==typeof i&&-1!==i.indexOf(location.hostname)&&"boolean"==typeof u&&u===("https:"===location.protocol)){var a=document.createElement("a");if(a.href="http://"+i+r,a.hostname===i||a.path===r){if(!t||this.isSupported()){var f=this.hash+"_"+e,c=new Date;c.setTime(c.getTime()+24*n*60*60*1e3);var l=c.toUTCString();return o=encodeURIComponent(o),document.cookie=f+"="+o+(l?"; expires="+l:"")+(r?"; path="+r:"")+(i?"; domain="+i:"")+(u?"; secure":""),this.getItem(t,e)===decodeURIComponent(o)}return!1}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()){e=this.hash+"_"+e;for(var o=document.cookie.split(";"),n=0;n<o.length;n++){var r=o[n],i=r.trim().split("=",2);if(i[0]===e)return decodeURIComponent(i[1])}return!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{return!("boolean"!=typeof t||"string"!=typeof e||!this.regValidKey.test(e))&&(!(t&&!this.isSupported())&&(this.setItem(t,e,"",-86400),!1===this.getItem(t,e)))}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=[],o=document.cookie.split(";"),n=0;n<o.length;n++){var r=o[n],i=r.trim().split("=",2);0===i[0].indexOf(this.hash)&&e.push(i[0].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 o=0;o<e.length;o++){var n=e[o];this.removeItem(t,n)}return 0===this.getKeys(t).length}return!0}return!1}catch(t){return!1}}}]),t}();e.default=u},34:function(t,e,o){t.exports=o(1)}})});