universal-cookie
Advanced tools
Comparing version 6.0.1 to 6.1.0
@@ -6,2 +6,3 @@ import { Cookie, CookieChangeListener, CookieGetOptions, CookieSetOptions } from './types'; | ||
private changeListeners; | ||
private pollingInterval?; | ||
private HAS_DOCUMENT_COOKIE; | ||
@@ -11,2 +12,4 @@ constructor(cookies?: string | object | null, defaultSetOptions?: CookieSetOptions); | ||
private _checkChanges; | ||
private _startPolling; | ||
private _stopPolling; | ||
get(name: string, options?: CookieGetOptions): any; | ||
@@ -18,5 +21,5 @@ get<T>(name: string, options?: CookieGetOptions): T; | ||
remove(name: string, options?: CookieSetOptions): void; | ||
update(): void; | ||
update: () => void; | ||
addChangeListener(callback: CookieChangeListener): void; | ||
removeChangeListener(callback: CookieChangeListener): void; | ||
} |
@@ -20,2 +20,3 @@ "use strict"; | ||
function Cookies(cookies) { | ||
var _this = this; | ||
var defaultSetOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -25,2 +26,10 @@ _classCallCheck(this, Cookies); | ||
this.HAS_DOCUMENT_COOKIE = false; | ||
this.update = function () { | ||
if (!_this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
var previousCookies = _this.cookies; | ||
_this.cookies = cookie.parse(document.cookie); | ||
_this._checkChanges(previousCookies); | ||
}; | ||
var domCookies = typeof document === 'undefined' ? '' : document.cookie; | ||
@@ -41,7 +50,7 @@ this.cookies = (0, _utils.parseCookies)(cookies || domCookies); | ||
value: function _checkChanges(newCookies) { | ||
var _this = this; | ||
var _this2 = this; | ||
var names = new Set(Object.keys(newCookies).concat(Object.keys(this.cookies))); | ||
names.forEach(function (name) { | ||
if (newCookies[name] !== _this.cookies[name]) { | ||
_this._emitChange({ | ||
if (newCookies[name] !== _this2.cookies[name]) { | ||
_this2._emitChange({ | ||
name: name, | ||
@@ -54,2 +63,14 @@ value: (0, _utils.readCookie)(newCookies[name]) | ||
}, { | ||
key: "_startPolling", | ||
value: function _startPolling() { | ||
this.pollingInterval = setInterval(this.update, 300); | ||
} | ||
}, { | ||
key: "_stopPolling", | ||
value: function _stopPolling() { | ||
if (this.pollingInterval) { | ||
clearInterval(this.pollingInterval); | ||
} | ||
} | ||
}, { | ||
key: "get", | ||
@@ -114,15 +135,12 @@ value: function get(name) { | ||
}, { | ||
key: "update", | ||
value: function update() { | ||
if (!this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
var previousCookies = this.cookies; | ||
this.cookies = cookie.parse(document.cookie); | ||
this._checkChanges(previousCookies); | ||
} | ||
}, { | ||
key: "addChangeListener", | ||
value: function addChangeListener(callback) { | ||
this.changeListeners.push(callback); | ||
if (this.changeListeners.length === 1) { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.addEventListener('change', this.update); | ||
} else { | ||
this._startPolling(); | ||
} | ||
} | ||
} | ||
@@ -136,2 +154,9 @@ }, { | ||
} | ||
if (this.changeListeners.length === 0) { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.removeEventListener('change', this.update); | ||
} else { | ||
this._stopPolling(); | ||
} | ||
} | ||
} | ||
@@ -138,0 +163,0 @@ }]); |
@@ -6,2 +6,3 @@ import { Cookie, CookieChangeListener, CookieGetOptions, CookieSetOptions } from './types'; | ||
private changeListeners; | ||
private pollingInterval?; | ||
private HAS_DOCUMENT_COOKIE; | ||
@@ -11,2 +12,4 @@ constructor(cookies?: string | object | null, defaultSetOptions?: CookieSetOptions); | ||
private _checkChanges; | ||
private _startPolling; | ||
private _stopPolling; | ||
get(name: string, options?: CookieGetOptions): any; | ||
@@ -18,5 +21,5 @@ get<T>(name: string, options?: CookieGetOptions): T; | ||
remove(name: string, options?: CookieSetOptions): void; | ||
update(): void; | ||
update: () => void; | ||
addChangeListener(callback: CookieChangeListener): void; | ||
removeChangeListener(callback: CookieChangeListener): void; | ||
} |
@@ -7,2 +7,10 @@ import * as cookie from 'cookie'; | ||
this.HAS_DOCUMENT_COOKIE = false; | ||
this.update = () => { | ||
if (!this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
const previousCookies = this.cookies; | ||
this.cookies = cookie.parse(document.cookie); | ||
this._checkChanges(previousCookies); | ||
}; | ||
const domCookies = typeof document === 'undefined' ? '' : document.cookie; | ||
@@ -29,2 +37,10 @@ this.cookies = parseCookies(cookies || domCookies); | ||
} | ||
_startPolling() { | ||
this.pollingInterval = setInterval(this.update, 300); | ||
} | ||
_stopPolling() { | ||
if (this.pollingInterval) { | ||
clearInterval(this.pollingInterval); | ||
} | ||
} | ||
get(name, options = {}) { | ||
@@ -69,12 +85,12 @@ if (!options.doNotUpdate) { | ||
} | ||
update() { | ||
if (!this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
const previousCookies = this.cookies; | ||
this.cookies = cookie.parse(document.cookie); | ||
this._checkChanges(previousCookies); | ||
} | ||
addChangeListener(callback) { | ||
this.changeListeners.push(callback); | ||
if (this.changeListeners.length === 1) { | ||
if (typeof window === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.addEventListener('change', this.update); | ||
} | ||
else { | ||
this._startPolling(); | ||
} | ||
} | ||
} | ||
@@ -86,3 +102,11 @@ removeChangeListener(callback) { | ||
} | ||
if (this.changeListeners.length === 0) { | ||
if (typeof window === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.removeEventListener('change', this.update); | ||
} | ||
else { | ||
this._stopPolling(); | ||
} | ||
} | ||
} | ||
} |
@@ -6,2 +6,3 @@ import { Cookie, CookieChangeListener, CookieGetOptions, CookieSetOptions } from './types'; | ||
private changeListeners; | ||
private pollingInterval?; | ||
private HAS_DOCUMENT_COOKIE; | ||
@@ -11,2 +12,4 @@ constructor(cookies?: string | object | null, defaultSetOptions?: CookieSetOptions); | ||
private _checkChanges; | ||
private _startPolling; | ||
private _stopPolling; | ||
get(name: string, options?: CookieGetOptions): any; | ||
@@ -18,5 +21,5 @@ get<T>(name: string, options?: CookieGetOptions): T; | ||
remove(name: string, options?: CookieSetOptions): void; | ||
update(): void; | ||
update: () => void; | ||
addChangeListener(callback: CookieChangeListener): void; | ||
removeChangeListener(callback: CookieChangeListener): void; | ||
} |
@@ -20,2 +20,3 @@ "use strict"; | ||
function Cookies(cookies) { | ||
var _this = this; | ||
var defaultSetOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -25,2 +26,10 @@ _classCallCheck(this, Cookies); | ||
this.HAS_DOCUMENT_COOKIE = false; | ||
this.update = function () { | ||
if (!_this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
var previousCookies = _this.cookies; | ||
_this.cookies = cookie.parse(document.cookie); | ||
_this._checkChanges(previousCookies); | ||
}; | ||
var domCookies = typeof document === 'undefined' ? '' : document.cookie; | ||
@@ -41,7 +50,7 @@ this.cookies = (0, _utils.parseCookies)(cookies || domCookies); | ||
value: function _checkChanges(newCookies) { | ||
var _this = this; | ||
var _this2 = this; | ||
var names = new Set(Object.keys(newCookies).concat(Object.keys(this.cookies))); | ||
names.forEach(function (name) { | ||
if (newCookies[name] !== _this.cookies[name]) { | ||
_this._emitChange({ | ||
if (newCookies[name] !== _this2.cookies[name]) { | ||
_this2._emitChange({ | ||
name: name, | ||
@@ -54,2 +63,14 @@ value: (0, _utils.readCookie)(newCookies[name]) | ||
}, { | ||
key: "_startPolling", | ||
value: function _startPolling() { | ||
this.pollingInterval = setInterval(this.update, 300); | ||
} | ||
}, { | ||
key: "_stopPolling", | ||
value: function _stopPolling() { | ||
if (this.pollingInterval) { | ||
clearInterval(this.pollingInterval); | ||
} | ||
} | ||
}, { | ||
key: "get", | ||
@@ -114,15 +135,12 @@ value: function get(name) { | ||
}, { | ||
key: "update", | ||
value: function update() { | ||
if (!this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
var previousCookies = this.cookies; | ||
this.cookies = cookie.parse(document.cookie); | ||
this._checkChanges(previousCookies); | ||
} | ||
}, { | ||
key: "addChangeListener", | ||
value: function addChangeListener(callback) { | ||
this.changeListeners.push(callback); | ||
if (this.changeListeners.length === 1) { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.addEventListener('change', this.update); | ||
} else { | ||
this._startPolling(); | ||
} | ||
} | ||
} | ||
@@ -136,2 +154,9 @@ }, { | ||
} | ||
if (this.changeListeners.length === 0) { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.removeEventListener('change', this.update); | ||
} else { | ||
this._stopPolling(); | ||
} | ||
} | ||
} | ||
@@ -138,0 +163,0 @@ }]); |
{ | ||
"name": "universal-cookie", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"description": "Universal cookies for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "cjs/index.js", |
@@ -101,3 +101,3 @@ <h3 align="center"> | ||
Read back the cookies and trigger changes accordingly. Useful is you change cookies server side or with other parties. | ||
Read back the cookies from the browser and triggers the change listeners. This should normally not be necessary because this library detects cookie changes automatically. | ||
@@ -104,0 +104,0 @@ ## Browser Example |
@@ -358,2 +358,3 @@ (function (global, factory) { | ||
function Cookies(cookies) { | ||
var _this = this; | ||
var defaultSetOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -363,2 +364,10 @@ _classCallCheck(this, Cookies); | ||
this.HAS_DOCUMENT_COOKIE = false; | ||
this.update = function () { | ||
if (!_this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
var previousCookies = _this.cookies; | ||
_this.cookies = cookie.parse(document.cookie); | ||
_this._checkChanges(previousCookies); | ||
}; | ||
var domCookies = typeof document === 'undefined' ? '' : document.cookie; | ||
@@ -379,7 +388,7 @@ this.cookies = (0, _utils.parseCookies)(cookies || domCookies); | ||
value: function _checkChanges(newCookies) { | ||
var _this = this; | ||
var _this2 = this; | ||
var names = new Set(Object.keys(newCookies).concat(Object.keys(this.cookies))); | ||
names.forEach(function (name) { | ||
if (newCookies[name] !== _this.cookies[name]) { | ||
_this._emitChange({ | ||
if (newCookies[name] !== _this2.cookies[name]) { | ||
_this2._emitChange({ | ||
name: name, | ||
@@ -392,2 +401,14 @@ value: (0, _utils.readCookie)(newCookies[name]) | ||
}, { | ||
key: "_startPolling", | ||
value: function _startPolling() { | ||
this.pollingInterval = setInterval(this.update, 300); | ||
} | ||
}, { | ||
key: "_stopPolling", | ||
value: function _stopPolling() { | ||
if (this.pollingInterval) { | ||
clearInterval(this.pollingInterval); | ||
} | ||
} | ||
}, { | ||
key: "get", | ||
@@ -452,15 +473,12 @@ value: function get(name) { | ||
}, { | ||
key: "update", | ||
value: function update() { | ||
if (!this.HAS_DOCUMENT_COOKIE) { | ||
return; | ||
} | ||
var previousCookies = this.cookies; | ||
this.cookies = cookie.parse(document.cookie); | ||
this._checkChanges(previousCookies); | ||
} | ||
}, { | ||
key: "addChangeListener", | ||
value: function addChangeListener(callback) { | ||
this.changeListeners.push(callback); | ||
if (this.changeListeners.length === 1) { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.addEventListener('change', this.update); | ||
} else { | ||
this._startPolling(); | ||
} | ||
} | ||
} | ||
@@ -474,2 +492,9 @@ }, { | ||
} | ||
if (this.changeListeners.length === 0) { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && 'cookieStore' in window) { | ||
window.cookieStore.removeEventListener('change', this.update); | ||
} else { | ||
this._stopPolling(); | ||
} | ||
} | ||
} | ||
@@ -476,0 +501,0 @@ }]); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).UniversalCookie=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t={},r={exports:{}},o={ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).UniversalCookie=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t={},n={exports:{}},o={ | ||
/*! | ||
@@ -8,2 +8,2 @@ * cookie | ||
*/ | ||
parse:function(e,t){if("string"!=typeof e)throw new TypeError("argument str must be a string");var r={},o=(t||{}).decode||a,n=0;for(;n<e.length;){var i=e.indexOf("=",n);if(-1===i)break;var u=e.indexOf(";",n);if(-1===u)u=e.length;else if(u<i){n=e.lastIndexOf(";",i-1)+1;continue}var c=e.slice(n,i).trim();if(void 0===r[c]){var f=e.slice(i+1,u).trim();34===f.charCodeAt(0)&&(f=f.slice(1,-1)),r[c]=s(f,o)}n=u+1}return r},serialize:function(e,t,r){var o=r||{},a=o.encode||u;if("function"!=typeof a)throw new TypeError("option encode is invalid");if(!i.test(e))throw new TypeError("argument name is invalid");var s=a(t);if(s&&!i.test(s))throw new TypeError("argument val is invalid");var c=e+"="+s;if(null!=o.maxAge){var f=o.maxAge-0;if(isNaN(f)||!isFinite(f))throw new TypeError("option maxAge is invalid");c+="; Max-Age="+Math.floor(f)}if(o.domain){if(!i.test(o.domain))throw new TypeError("option domain is invalid");c+="; Domain="+o.domain}if(o.path){if(!i.test(o.path))throw new TypeError("option path is invalid");c+="; Path="+o.path}if(o.expires){var l=o.expires;if(!function(e){return"[object Date]"===n.call(e)||e instanceof Date}(l)||isNaN(l.valueOf()))throw new TypeError("option expires is invalid");c+="; Expires="+l.toUTCString()}o.httpOnly&&(c+="; HttpOnly");o.secure&&(c+="; Secure");if(o.priority){switch("string"==typeof o.priority?o.priority.toLowerCase():o.priority){case"low":c+="; Priority=Low";break;case"medium":c+="; Priority=Medium";break;case"high":c+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(o.sameSite){switch("string"==typeof o.sameSite?o.sameSite.toLowerCase():o.sameSite){case!0:c+="; SameSite=Strict";break;case"lax":c+="; SameSite=Lax";break;case"strict":c+="; SameSite=Strict";break;case"none":c+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return c}},n=Object.prototype.toString,i=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function a(e){return-1!==e.indexOf("%")?decodeURIComponent(e):e}function u(e){return encodeURIComponent(e)}function s(e,t){try{return t(e)}catch(t){return e}}var c={};Object.defineProperty(c,"__esModule",{value:!0}),c.cleanCookies=function(){document.cookie.split(";").forEach((function(e){document.cookie=e.replace(/^ +/,"").replace(/=.*/,"=;expires="+(new Date).toUTCString()+";path=/")}))},c.hasDocumentCookie=function(){return"object"===("undefined"==typeof document?"undefined":p(document))&&"string"==typeof document.cookie},c.parseCookies=function(e){return"string"==typeof e?f.parse(e):"object"===p(e)&&null!==e?e:{}},c.readCookie=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=function(e){if(e&&"j"===e[0]&&":"===e[1])return e.substr(2);return e}(e);if(!t.doNotParse)try{return JSON.parse(r)}catch(e){}return e};var f=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==p(e)&&"function"!=typeof e)return{default:e};var r=l(t);if(r&&r.has(e))return r.get(e);var o={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var a=n?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(o,i,a):o[i]=e[i]}o.default=e,r&&r.set(e,o);return o}(o);function l(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(l=function(e){return e?r:t})(e)}function p(e){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p(e)}!function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==a(e)&&"function"!=typeof e)return{default:e};var r=i(t);if(r&&r.has(e))return r.get(e);var o={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var s=n?Object.getOwnPropertyDescriptor(e,u):null;s&&(s.get||s.set)?Object.defineProperty(o,u,s):o[u]=e[u]}o.default=e,r&&r.set(e,o);return o}(o),n=c;function i(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(i=function(e){return e?r:t})(e)}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function u(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}function s(e){var t=function(e,t){if("object"!==a(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!==a(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===a(t)?t:String(t)}var f=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.changeListeners=[],this.HAS_DOCUMENT_COOKIE=!1;var o="undefined"==typeof document?"":document.cookie;this.cookies=(0,n.parseCookies)(t||o),this.defaultSetOptions=r,this.HAS_DOCUMENT_COOKIE=(0,n.hasDocumentCookie)()}var t,o,i;return t=e,o=[{key:"_emitChange",value:function(e){for(var t=0;t<this.changeListeners.length;++t)this.changeListeners[t](e)}},{key:"_checkChanges",value:function(e){var t=this;new Set(Object.keys(e).concat(Object.keys(this.cookies))).forEach((function(r){e[r]!==t.cookies[r]&&t._emitChange({name:r,value:(0,n.readCookie)(e[r])})}))}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.doNotUpdate||this.update(),(0,n.readCookie)(this.cookies[e],t)}},{key:"getAll",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.doNotUpdate||this.update();var t={};for(var r in this.cookies)t[r]=(0,n.readCookie)(this.cookies[r],e);return t}},{key:"set",value:function(e,t,o){o=o?Object.assign(Object.assign({},this.defaultSetOptions),o):this.defaultSetOptions;var n="string"==typeof t?t:JSON.stringify(t);this.cookies=Object.assign(Object.assign({},this.cookies),function(e,t,r){return(t=s(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},e,n)),this.HAS_DOCUMENT_COOKIE&&(document.cookie=r.serialize(e,n,o)),this._emitChange({name:e,value:t,options:o})}},{key:"remove",value:function(e,t){var o=t=Object.assign(Object.assign({},t),{expires:new Date(1970,1,1,0,0,1),maxAge:0});this.cookies=Object.assign({},this.cookies),delete this.cookies[e],this.HAS_DOCUMENT_COOKIE&&(document.cookie=r.serialize(e,"",o)),this._emitChange({name:e,value:void 0,options:t})}},{key:"update",value:function(){if(this.HAS_DOCUMENT_COOKIE){var e=this.cookies;this.cookies=r.parse(document.cookie),this._checkChanges(e)}}},{key:"addChangeListener",value:function(e){this.changeListeners.push(e)}},{key:"removeChangeListener",value:function(e){var t=this.changeListeners.indexOf(e);t>=0&&this.changeListeners.splice(t,1)}}],o&&u(t.prototype,o),i&&u(t,i),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=f,e.exports=t.default}(r,r.exports);var d=r.exports,y={};return Object.defineProperty(y,"__esModule",{value:!0}),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t={};e.default=void 0;var r,o=(r=d)&&r.__esModule?r:{default:r},n=y;Object.keys(n).forEach((function(r){"default"!==r&&"__esModule"!==r&&(Object.prototype.hasOwnProperty.call(t,r)||r in e&&e[r]===n[r]||Object.defineProperty(e,r,{enumerable:!0,get:function(){return n[r]}}))}));var i=o.default;e.default=i}(t),e(t)})); | ||
parse:function(e,t){if("string"!=typeof e)throw new TypeError("argument str must be a string");var n={},o=(t||{}).decode||a,i=0;for(;i<e.length;){var r=e.indexOf("=",i);if(-1===r)break;var s=e.indexOf(";",i);if(-1===s)s=e.length;else if(s<r){i=e.lastIndexOf(";",r-1)+1;continue}var c=e.slice(i,r).trim();if(void 0===n[c]){var f=e.slice(r+1,s).trim();34===f.charCodeAt(0)&&(f=f.slice(1,-1)),n[c]=u(f,o)}i=s+1}return n},serialize:function(e,t,n){var o=n||{},a=o.encode||s;if("function"!=typeof a)throw new TypeError("option encode is invalid");if(!r.test(e))throw new TypeError("argument name is invalid");var u=a(t);if(u&&!r.test(u))throw new TypeError("argument val is invalid");var c=e+"="+u;if(null!=o.maxAge){var f=o.maxAge-0;if(isNaN(f)||!isFinite(f))throw new TypeError("option maxAge is invalid");c+="; Max-Age="+Math.floor(f)}if(o.domain){if(!r.test(o.domain))throw new TypeError("option domain is invalid");c+="; Domain="+o.domain}if(o.path){if(!r.test(o.path))throw new TypeError("option path is invalid");c+="; Path="+o.path}if(o.expires){var l=o.expires;if(!function(e){return"[object Date]"===i.call(e)||e instanceof Date}(l)||isNaN(l.valueOf()))throw new TypeError("option expires is invalid");c+="; Expires="+l.toUTCString()}o.httpOnly&&(c+="; HttpOnly");o.secure&&(c+="; Secure");if(o.priority){switch("string"==typeof o.priority?o.priority.toLowerCase():o.priority){case"low":c+="; Priority=Low";break;case"medium":c+="; Priority=Medium";break;case"high":c+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(o.sameSite){switch("string"==typeof o.sameSite?o.sameSite.toLowerCase():o.sameSite){case!0:c+="; SameSite=Strict";break;case"lax":c+="; SameSite=Lax";break;case"strict":c+="; SameSite=Strict";break;case"none":c+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return c}},i=Object.prototype.toString,r=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function a(e){return-1!==e.indexOf("%")?decodeURIComponent(e):e}function s(e){return encodeURIComponent(e)}function u(e,t){try{return t(e)}catch(t){return e}}var c={};Object.defineProperty(c,"__esModule",{value:!0}),c.cleanCookies=function(){document.cookie.split(";").forEach((function(e){document.cookie=e.replace(/^ +/,"").replace(/=.*/,"=;expires="+(new Date).toUTCString()+";path=/")}))},c.hasDocumentCookie=function(){return"object"===("undefined"==typeof document?"undefined":p(document))&&"string"==typeof document.cookie},c.parseCookies=function(e){return"string"==typeof e?f.parse(e):"object"===p(e)&&null!==e?e:{}},c.readCookie=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=function(e){if(e&&"j"===e[0]&&":"===e[1])return e.substr(2);return e}(e);if(!t.doNotParse)try{return JSON.parse(n)}catch(e){}return e};var f=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==p(e)&&"function"!=typeof e)return{default:e};var n=l(t);if(n&&n.has(e))return n.get(e);var o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var a=i?Object.getOwnPropertyDescriptor(e,r):null;a&&(a.get||a.set)?Object.defineProperty(o,r,a):o[r]=e[r]}o.default=e,n&&n.set(e,o);return o}(o);function l(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(l=function(e){return e?n:t})(e)}function p(e){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p(e)}!function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==a(e)&&"function"!=typeof e)return{default:e};var n=r(t);if(n&&n.has(e))return n.get(e);var o={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if("default"!==s&&Object.prototype.hasOwnProperty.call(e,s)){var u=i?Object.getOwnPropertyDescriptor(e,s):null;u&&(u.get||u.set)?Object.defineProperty(o,s,u):o[s]=e[s]}o.default=e,n&&n.set(e,o);return o}(o),i=c;function r(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(r=function(e){return e?n:t})(e)}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function s(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,u(o.key),o)}}function u(e){var t=function(e,t){if("object"!==a(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!==a(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===a(t)?t:String(t)}var f=function(){function e(t){var o=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.changeListeners=[],this.HAS_DOCUMENT_COOKIE=!1,this.update=function(){if(o.HAS_DOCUMENT_COOKIE){var e=o.cookies;o.cookies=n.parse(document.cookie),o._checkChanges(e)}};var a="undefined"==typeof document?"":document.cookie;this.cookies=(0,i.parseCookies)(t||a),this.defaultSetOptions=r,this.HAS_DOCUMENT_COOKIE=(0,i.hasDocumentCookie)()}var t,o,r;return t=e,o=[{key:"_emitChange",value:function(e){for(var t=0;t<this.changeListeners.length;++t)this.changeListeners[t](e)}},{key:"_checkChanges",value:function(e){var t=this;new Set(Object.keys(e).concat(Object.keys(this.cookies))).forEach((function(n){e[n]!==t.cookies[n]&&t._emitChange({name:n,value:(0,i.readCookie)(e[n])})}))}},{key:"_startPolling",value:function(){this.pollingInterval=setInterval(this.update,300)}},{key:"_stopPolling",value:function(){this.pollingInterval&&clearInterval(this.pollingInterval)}},{key:"get",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t.doNotUpdate||this.update(),(0,i.readCookie)(this.cookies[e],t)}},{key:"getAll",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e.doNotUpdate||this.update();var t={};for(var n in this.cookies)t[n]=(0,i.readCookie)(this.cookies[n],e);return t}},{key:"set",value:function(e,t,o){o=o?Object.assign(Object.assign({},this.defaultSetOptions),o):this.defaultSetOptions;var i="string"==typeof t?t:JSON.stringify(t);this.cookies=Object.assign(Object.assign({},this.cookies),function(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}({},e,i)),this.HAS_DOCUMENT_COOKIE&&(document.cookie=n.serialize(e,i,o)),this._emitChange({name:e,value:t,options:o})}},{key:"remove",value:function(e,t){var o=t=Object.assign(Object.assign({},t),{expires:new Date(1970,1,1,0,0,1),maxAge:0});this.cookies=Object.assign({},this.cookies),delete this.cookies[e],this.HAS_DOCUMENT_COOKIE&&(document.cookie=n.serialize(e,"",o)),this._emitChange({name:e,value:void 0,options:t})}},{key:"addChangeListener",value:function(e){this.changeListeners.push(e),1===this.changeListeners.length&&("object"===("undefined"==typeof window?"undefined":a(window))&&"cookieStore"in window?window.cookieStore.addEventListener("change",this.update):this._startPolling())}},{key:"removeChangeListener",value:function(e){var t=this.changeListeners.indexOf(e);t>=0&&this.changeListeners.splice(t,1),0===this.changeListeners.length&&("object"===("undefined"==typeof window?"undefined":a(window))&&"cookieStore"in window?window.cookieStore.removeEventListener("change",this.update):this._stopPolling())}}],o&&s(t.prototype,o),r&&s(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();t.default=f,e.exports=t.default}(n,n.exports);var d=n.exports,h={};return Object.defineProperty(h,"__esModule",{value:!0}),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t={};e.default=void 0;var n,o=(n=d)&&n.__esModule?n:{default:n},i=h;Object.keys(i).forEach((function(n){"default"!==n&&"__esModule"!==n&&(Object.prototype.hasOwnProperty.call(t,n)||n in e&&e[n]===i[n]||Object.defineProperty(e,n,{enumerable:!0,get:function(){return i[n]}}))}));var r=o.default;e.default=r}(t),e(t)})); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68418
1317