universal-cookie
Advanced tools
Comparing version 7.2.0 to 7.2.1
{ | ||
"name": "universal-cookie", | ||
"version": "7.2.0", | ||
"version": "7.2.1", | ||
"description": "Universal cookies for JavaScript", | ||
@@ -47,10 +47,10 @@ "types": "cjs/index.d.ts", | ||
"@types/cookie": "^0.6.0", | ||
"cookie": "^0.6.0" | ||
"cookie": "^0.7.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.24.8", | ||
"@babel/cli": "^7.25.7", | ||
"rimraf": "^6.0.1", | ||
"rollup": "^4.19.0", | ||
"typescript": "^5.5.3" | ||
"rollup": "^4.24.0", | ||
"typescript": "^5.6.3" | ||
} | ||
} |
@@ -7,2 +7,4 @@ (function (global, factory) { | ||
var cookie = {}; | ||
/*! | ||
@@ -15,268 +17,339 @@ * cookie | ||
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
var hasRequiredCookie; | ||
var parse_1 = parse; | ||
var serialize_1 = serialize; | ||
function requireCookie () { | ||
if (hasRequiredCookie) return cookie; | ||
hasRequiredCookie = 1; | ||
/** | ||
* Module variables. | ||
* @private | ||
*/ | ||
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
var __toString = Object.prototype.toString; | ||
cookie.parse = parse; | ||
cookie.serialize = serialize; | ||
/** | ||
* RegExp to match field-content in RFC 7230 sec 3.2 | ||
* | ||
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] | ||
* field-vchar = VCHAR / obs-text | ||
* obs-text = %x80-FF | ||
*/ | ||
/** | ||
* Module variables. | ||
* @private | ||
*/ | ||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | ||
var __toString = Object.prototype.toString; | ||
var __hasOwnProperty = Object.prototype.hasOwnProperty; | ||
/** | ||
* Parse a cookie header. | ||
* | ||
* Parse the given cookie header string into an object | ||
* The object has the various cookies as keys(names) => values | ||
* | ||
* @param {string} str | ||
* @param {object} [options] | ||
* @return {object} | ||
* @public | ||
*/ | ||
/** | ||
* RegExp to match cookie-name in RFC 6265 sec 4.1.1 | ||
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2 | ||
* which has been replaced by the token definition in RFC 7230 appendix B. | ||
* | ||
* cookie-name = token | ||
* token = 1*tchar | ||
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / | ||
* "*" / "+" / "-" / "." / "^" / "_" / | ||
* "`" / "|" / "~" / DIGIT / ALPHA | ||
*/ | ||
function parse(str, options) { | ||
if (typeof str !== 'string') { | ||
throw new TypeError('argument str must be a string'); | ||
} | ||
var cookieNameRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/; | ||
var obj = {}; | ||
var opt = options || {}; | ||
var dec = opt.decode || decode; | ||
/** | ||
* RegExp to match cookie-value in RFC 6265 sec 4.1.1 | ||
* | ||
* cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE ) | ||
* cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E | ||
* ; US-ASCII characters excluding CTLs, | ||
* ; whitespace DQUOTE, comma, semicolon, | ||
* ; and backslash | ||
*/ | ||
var index = 0; | ||
while (index < str.length) { | ||
var eqIdx = str.indexOf('=', index); | ||
var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/; | ||
// no more cookie pairs | ||
if (eqIdx === -1) { | ||
break | ||
} | ||
/** | ||
* RegExp to match domain-value in RFC 6265 sec 4.1.1 | ||
* | ||
* domain-value = <subdomain> | ||
* ; defined in [RFC1034], Section 3.5, as | ||
* ; enhanced by [RFC1123], Section 2.1 | ||
* <subdomain> = <label> | <subdomain> "." <label> | ||
* <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ] | ||
* Labels must be 63 characters or less. | ||
* 'let-dig' not 'letter' in the first char, per RFC1123 | ||
* <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str> | ||
* <let-dig-hyp> = <let-dig> | "-" | ||
* <let-dig> = <letter> | <digit> | ||
* <letter> = any one of the 52 alphabetic characters A through Z in | ||
* upper case and a through z in lower case | ||
* <digit> = any one of the ten digits 0 through 9 | ||
* | ||
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173 | ||
* | ||
* > (Note that a leading %x2E ("."), if present, is ignored even though that | ||
* character is not permitted, but a trailing %x2E ("."), if present, will | ||
* cause the user agent to ignore the attribute.) | ||
*/ | ||
var endIdx = str.indexOf(';', index); | ||
var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i; | ||
if (endIdx === -1) { | ||
endIdx = str.length; | ||
} else if (endIdx < eqIdx) { | ||
// backtrack on prior semicolon | ||
index = str.lastIndexOf(';', eqIdx - 1) + 1; | ||
continue | ||
} | ||
/** | ||
* RegExp to match path-value in RFC 6265 sec 4.1.1 | ||
* | ||
* path-value = <any CHAR except CTLs or ";"> | ||
* CHAR = %x01-7F | ||
* ; defined in RFC 5234 appendix B.1 | ||
*/ | ||
var key = str.slice(index, eqIdx).trim(); | ||
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/; | ||
// only assign once | ||
if (undefined === obj[key]) { | ||
var val = str.slice(eqIdx + 1, endIdx).trim(); | ||
/** | ||
* Parse a cookie header. | ||
* | ||
* Parse the given cookie header string into an object | ||
* The object has the various cookies as keys(names) => values | ||
* | ||
* @param {string} str | ||
* @param {object} [opt] | ||
* @return {object} | ||
* @public | ||
*/ | ||
// quoted values | ||
if (val.charCodeAt(0) === 0x22) { | ||
val = val.slice(1, -1); | ||
} | ||
function parse(str, opt) { | ||
if (typeof str !== 'string') { | ||
throw new TypeError('argument str must be a string'); | ||
} | ||
obj[key] = tryDecode(val, dec); | ||
} | ||
var obj = {}; | ||
var len = str.length; | ||
// RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='. | ||
if (len < 2) return obj; | ||
index = endIdx + 1; | ||
} | ||
var dec = (opt && opt.decode) || decode; | ||
var index = 0; | ||
var eqIdx = 0; | ||
var endIdx = 0; | ||
return obj; | ||
} | ||
do { | ||
eqIdx = str.indexOf('=', index); | ||
if (eqIdx === -1) break; // No more cookie pairs. | ||
/** | ||
* Serialize data into a cookie header. | ||
* | ||
* Serialize the a name value pair into a cookie string suitable for | ||
* http headers. An optional options object specified cookie parameters. | ||
* | ||
* serialize('foo', 'bar', { httpOnly: true }) | ||
* => "foo=bar; httpOnly" | ||
* | ||
* @param {string} name | ||
* @param {string} val | ||
* @param {object} [options] | ||
* @return {string} | ||
* @public | ||
*/ | ||
endIdx = str.indexOf(';', index); | ||
function serialize(name, val, options) { | ||
var opt = options || {}; | ||
var enc = opt.encode || encode; | ||
if (endIdx === -1) { | ||
endIdx = len; | ||
} else if (eqIdx > endIdx) { | ||
// backtrack on prior semicolon | ||
index = str.lastIndexOf(';', eqIdx - 1) + 1; | ||
continue; | ||
} | ||
if (typeof enc !== 'function') { | ||
throw new TypeError('option encode is invalid'); | ||
} | ||
var keyStartIdx = startIndex(str, index, eqIdx); | ||
var keyEndIdx = endIndex(str, eqIdx, keyStartIdx); | ||
var key = str.slice(keyStartIdx, keyEndIdx); | ||
if (!fieldContentRegExp.test(name)) { | ||
throw new TypeError('argument name is invalid'); | ||
} | ||
// only assign once | ||
if (!__hasOwnProperty.call(obj, key)) { | ||
var valStartIdx = startIndex(str, eqIdx + 1, endIdx); | ||
var valEndIdx = endIndex(str, endIdx, valStartIdx); | ||
var value = enc(val); | ||
if (str.charCodeAt(valStartIdx) === 0x22 /* " */ && str.charCodeAt(valEndIdx - 1) === 0x22 /* " */) { | ||
valStartIdx++; | ||
valEndIdx--; | ||
} | ||
if (value && !fieldContentRegExp.test(value)) { | ||
throw new TypeError('argument val is invalid'); | ||
} | ||
var val = str.slice(valStartIdx, valEndIdx); | ||
obj[key] = tryDecode(val, dec); | ||
} | ||
var str = name + '=' + value; | ||
index = endIdx + 1; | ||
} while (index < len); | ||
if (null != opt.maxAge) { | ||
var maxAge = opt.maxAge - 0; | ||
return obj; | ||
} | ||
if (isNaN(maxAge) || !isFinite(maxAge)) { | ||
throw new TypeError('option maxAge is invalid') | ||
} | ||
function startIndex(str, index, max) { | ||
do { | ||
var code = str.charCodeAt(index); | ||
if (code !== 0x20 /* */ && code !== 0x09 /* \t */) return index; | ||
} while (++index < max); | ||
return max; | ||
} | ||
str += '; Max-Age=' + Math.floor(maxAge); | ||
} | ||
function endIndex(str, index, min) { | ||
while (index > min) { | ||
var code = str.charCodeAt(--index); | ||
if (code !== 0x20 /* */ && code !== 0x09 /* \t */) return index + 1; | ||
} | ||
return min; | ||
} | ||
if (opt.domain) { | ||
if (!fieldContentRegExp.test(opt.domain)) { | ||
throw new TypeError('option domain is invalid'); | ||
} | ||
/** | ||
* Serialize data into a cookie header. | ||
* | ||
* Serialize a name value pair into a cookie string suitable for | ||
* http headers. An optional options object specifies cookie parameters. | ||
* | ||
* serialize('foo', 'bar', { httpOnly: true }) | ||
* => "foo=bar; httpOnly" | ||
* | ||
* @param {string} name | ||
* @param {string} val | ||
* @param {object} [opt] | ||
* @return {string} | ||
* @public | ||
*/ | ||
str += '; Domain=' + opt.domain; | ||
} | ||
function serialize(name, val, opt) { | ||
var enc = (opt && opt.encode) || encodeURIComponent; | ||
if (opt.path) { | ||
if (!fieldContentRegExp.test(opt.path)) { | ||
throw new TypeError('option path is invalid'); | ||
} | ||
if (typeof enc !== 'function') { | ||
throw new TypeError('option encode is invalid'); | ||
} | ||
str += '; Path=' + opt.path; | ||
} | ||
if (!cookieNameRegExp.test(name)) { | ||
throw new TypeError('argument name is invalid'); | ||
} | ||
if (opt.expires) { | ||
var expires = opt.expires; | ||
var value = enc(val); | ||
if (!isDate(expires) || isNaN(expires.valueOf())) { | ||
throw new TypeError('option expires is invalid'); | ||
} | ||
if (!cookieValueRegExp.test(value)) { | ||
throw new TypeError('argument val is invalid'); | ||
} | ||
str += '; Expires=' + expires.toUTCString(); | ||
} | ||
var str = name + '=' + value; | ||
if (!opt) return str; | ||
if (opt.httpOnly) { | ||
str += '; HttpOnly'; | ||
} | ||
if (null != opt.maxAge) { | ||
var maxAge = Math.floor(opt.maxAge); | ||
if (opt.secure) { | ||
str += '; Secure'; | ||
} | ||
if (!isFinite(maxAge)) { | ||
throw new TypeError('option maxAge is invalid') | ||
} | ||
if (opt.partitioned) { | ||
str += '; Partitioned'; | ||
} | ||
str += '; Max-Age=' + maxAge; | ||
} | ||
if (opt.priority) { | ||
var priority = typeof opt.priority === 'string' | ||
? opt.priority.toLowerCase() | ||
: opt.priority; | ||
if (opt.domain) { | ||
if (!domainValueRegExp.test(opt.domain)) { | ||
throw new TypeError('option domain is invalid'); | ||
} | ||
switch (priority) { | ||
case 'low': | ||
str += '; Priority=Low'; | ||
break | ||
case 'medium': | ||
str += '; Priority=Medium'; | ||
break | ||
case 'high': | ||
str += '; Priority=High'; | ||
break | ||
default: | ||
throw new TypeError('option priority is invalid') | ||
} | ||
} | ||
str += '; Domain=' + opt.domain; | ||
} | ||
if (opt.sameSite) { | ||
var sameSite = typeof opt.sameSite === 'string' | ||
? opt.sameSite.toLowerCase() : opt.sameSite; | ||
if (opt.path) { | ||
if (!pathValueRegExp.test(opt.path)) { | ||
throw new TypeError('option path is invalid'); | ||
} | ||
switch (sameSite) { | ||
case true: | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'lax': | ||
str += '; SameSite=Lax'; | ||
break; | ||
case 'strict': | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'none': | ||
str += '; SameSite=None'; | ||
break; | ||
default: | ||
throw new TypeError('option sameSite is invalid'); | ||
} | ||
} | ||
str += '; Path=' + opt.path; | ||
} | ||
return str; | ||
} | ||
if (opt.expires) { | ||
var expires = opt.expires; | ||
/** | ||
* URL-decode string value. Optimized to skip native call when no %. | ||
* | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
if (!isDate(expires) || isNaN(expires.valueOf())) { | ||
throw new TypeError('option expires is invalid'); | ||
} | ||
function decode (str) { | ||
return str.indexOf('%') !== -1 | ||
? decodeURIComponent(str) | ||
: str | ||
} | ||
str += '; Expires=' + expires.toUTCString(); | ||
} | ||
/** | ||
* URL-encode value. | ||
* | ||
* @param {string} val | ||
* @returns {string} | ||
*/ | ||
if (opt.httpOnly) { | ||
str += '; HttpOnly'; | ||
} | ||
function encode (val) { | ||
return encodeURIComponent(val) | ||
} | ||
if (opt.secure) { | ||
str += '; Secure'; | ||
} | ||
/** | ||
* Determine if value is a Date. | ||
* | ||
* @param {*} val | ||
* @private | ||
*/ | ||
if (opt.partitioned) { | ||
str += '; Partitioned'; | ||
} | ||
function isDate (val) { | ||
return __toString.call(val) === '[object Date]' || | ||
val instanceof Date | ||
} | ||
if (opt.priority) { | ||
var priority = typeof opt.priority === 'string' | ||
? opt.priority.toLowerCase() : opt.priority; | ||
/** | ||
* Try decoding a string using a decoding function. | ||
* | ||
* @param {string} str | ||
* @param {function} decode | ||
* @private | ||
*/ | ||
switch (priority) { | ||
case 'low': | ||
str += '; Priority=Low'; | ||
break | ||
case 'medium': | ||
str += '; Priority=Medium'; | ||
break | ||
case 'high': | ||
str += '; Priority=High'; | ||
break | ||
default: | ||
throw new TypeError('option priority is invalid') | ||
} | ||
} | ||
function tryDecode(str, decode) { | ||
try { | ||
return decode(str); | ||
} catch (e) { | ||
return str; | ||
} | ||
if (opt.sameSite) { | ||
var sameSite = typeof opt.sameSite === 'string' | ||
? opt.sameSite.toLowerCase() : opt.sameSite; | ||
switch (sameSite) { | ||
case true: | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'lax': | ||
str += '; SameSite=Lax'; | ||
break; | ||
case 'strict': | ||
str += '; SameSite=Strict'; | ||
break; | ||
case 'none': | ||
str += '; SameSite=None'; | ||
break; | ||
default: | ||
throw new TypeError('option sameSite is invalid'); | ||
} | ||
} | ||
return str; | ||
} | ||
/** | ||
* URL-decode string value. Optimized to skip native call when no %. | ||
* | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
function decode (str) { | ||
return str.indexOf('%') !== -1 | ||
? decodeURIComponent(str) | ||
: str | ||
} | ||
/** | ||
* Determine if value is a Date. | ||
* | ||
* @param {*} val | ||
* @private | ||
*/ | ||
function isDate (val) { | ||
return __toString.call(val) === '[object Date]'; | ||
} | ||
/** | ||
* Try decoding a string using a decoding function. | ||
* | ||
* @param {string} str | ||
* @param {function} decode | ||
* @private | ||
*/ | ||
function tryDecode(str, decode) { | ||
try { | ||
return decode(str); | ||
} catch (e) { | ||
return str; | ||
} | ||
} | ||
return cookie; | ||
} | ||
var cookieExports = requireCookie(); | ||
function hasDocumentCookie() { | ||
@@ -294,3 +367,3 @@ const testingValue = typeof global === 'undefined' | ||
if (typeof cookies === 'string') { | ||
return parse_1(cookies); | ||
return cookieExports.parse(cookies); | ||
} | ||
@@ -335,3 +408,3 @@ else if (typeof cookies === 'object' && cookies !== null) { | ||
const previousCookies = this.cookies; | ||
this.cookies = parse_1(document.cookie); | ||
this.cookies = cookieExports.parse(document.cookie); | ||
this._checkChanges(previousCookies); | ||
@@ -394,3 +467,3 @@ }; | ||
if (this.HAS_DOCUMENT_COOKIE) { | ||
document.cookie = serialize_1(name, stringValue, options); | ||
document.cookie = cookieExports.serialize(name, stringValue, options); | ||
} | ||
@@ -404,3 +477,3 @@ this._emitChange({ name, value, options }); | ||
if (this.HAS_DOCUMENT_COOKIE) { | ||
document.cookie = serialize_1(name, '', finalOptions); | ||
document.cookie = cookieExports.serialize(name, '', finalOptions); | ||
} | ||
@@ -407,0 +480,0 @@ this._emitChange({ name, value: undefined, options }); |
@@ -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,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";var e,t={}; | ||
/*! | ||
@@ -7,2 +7,2 @@ * cookie | ||
* MIT Licensed | ||
*/var e=function(e,t){if("string"!=typeof e)throw new TypeError("argument str must be a string");var i={},o=(t||{}).decode||n,s=0;for(;s<e.length;){var a=e.indexOf("=",s);if(-1===a)break;var c=e.indexOf(";",s);if(-1===c)c=e.length;else if(c<a){s=e.lastIndexOf(";",a-1)+1;continue}var h=e.slice(s,a).trim();if(void 0===i[h]){var d=e.slice(a+1,c).trim();34===d.charCodeAt(0)&&(d=d.slice(1,-1)),i[h]=r(d,o)}s=c+1}return i},t=function(e,t,n){var r=n||{},a=r.encode||s;if("function"!=typeof a)throw new TypeError("option encode is invalid");if(!o.test(e))throw new TypeError("argument name is invalid");var c=a(t);if(c&&!o.test(c))throw new TypeError("argument val is invalid");var h=e+"="+c;if(null!=r.maxAge){var d=r.maxAge-0;if(isNaN(d)||!isFinite(d))throw new TypeError("option maxAge is invalid");h+="; Max-Age="+Math.floor(d)}if(r.domain){if(!o.test(r.domain))throw new TypeError("option domain is invalid");h+="; Domain="+r.domain}if(r.path){if(!o.test(r.path))throw new TypeError("option path is invalid");h+="; Path="+r.path}if(r.expires){var f=r.expires;if(!function(e){return"[object Date]"===i.call(e)||e instanceof Date}(f)||isNaN(f.valueOf()))throw new TypeError("option expires is invalid");h+="; Expires="+f.toUTCString()}r.httpOnly&&(h+="; HttpOnly");r.secure&&(h+="; Secure");r.partitioned&&(h+="; Partitioned");if(r.priority){switch("string"==typeof r.priority?r.priority.toLowerCase():r.priority){case"low":h+="; Priority=Low";break;case"medium":h+="; Priority=Medium";break;case"high":h+="; Priority=High";break;default:throw new TypeError("option priority is invalid")}}if(r.sameSite){switch("string"==typeof r.sameSite?r.sameSite.toLowerCase():r.sameSite){case!0:h+="; SameSite=Strict";break;case"lax":h+="; SameSite=Lax";break;case"strict":h+="; SameSite=Strict";break;case"none":h+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return h},i=Object.prototype.toString,o=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function n(e){return-1!==e.indexOf("%")?decodeURIComponent(e):e}function s(e){return encodeURIComponent(e)}function r(e,t){try{return t(e)}catch(t){return e}}function a(e,t={}){const i=function(e){if(e&&"j"===e[0]&&":"===e[1])return e.substr(2);return e}(e);if(!t.doNotParse)try{return JSON.parse(i)}catch(e){}return e}return class{constructor(t,i={}){this.changeListeners=[],this.HAS_DOCUMENT_COOKIE=!1,this.update=()=>{if(!this.HAS_DOCUMENT_COOKIE)return;const t=this.cookies;this.cookies=e(document.cookie),this._checkChanges(t)};const o="undefined"==typeof document?"":document.cookie;this.cookies=function(t){return"string"==typeof t?e(t):"object"==typeof t&&null!==t?t:{}}(t||o),this.defaultSetOptions=i,this.HAS_DOCUMENT_COOKIE=function(){const e="undefined"==typeof global?void 0:global.TEST_HAS_DOCUMENT_COOKIE;return"boolean"==typeof e?e:"object"==typeof document&&"string"==typeof document.cookie}()}_emitChange(e){for(let t=0;t<this.changeListeners.length;++t)this.changeListeners[t](e)}_checkChanges(e){new Set(Object.keys(e).concat(Object.keys(this.cookies))).forEach((t=>{e[t]!==this.cookies[t]&&this._emitChange({name:t,value:a(this.cookies[t])})}))}_startPolling(){this.pollingInterval=setInterval(this.update,300)}_stopPolling(){this.pollingInterval&&clearInterval(this.pollingInterval)}get(e,t={}){return t.doNotUpdate||this.update(),a(this.cookies[e],t)}getAll(e={}){e.doNotUpdate||this.update();const t={};for(let i in this.cookies)t[i]=a(this.cookies[i],e);return t}set(e,i,o){o=o?Object.assign(Object.assign({},this.defaultSetOptions),o):this.defaultSetOptions;const n="string"==typeof i?i:JSON.stringify(i);this.cookies=Object.assign(Object.assign({},this.cookies),{[e]:n}),this.HAS_DOCUMENT_COOKIE&&(document.cookie=t(e,n,o)),this._emitChange({name:e,value:i,options:o})}remove(e,i){const o=i=Object.assign(Object.assign(Object.assign({},this.defaultSetOptions),i),{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=t(e,"",o)),this._emitChange({name:e,value:void 0,options:i})}addChangeListener(e){this.changeListeners.push(e),this.HAS_DOCUMENT_COOKIE&&1===this.changeListeners.length&&("object"==typeof window&&"cookieStore"in window?window.cookieStore.addEventListener("change",this.update):this._startPolling())}removeChangeListener(e){const t=this.changeListeners.indexOf(e);t>=0&&this.changeListeners.splice(t,1),this.HAS_DOCUMENT_COOKIE&&0===this.changeListeners.length&&("object"==typeof window&&"cookieStore"in window?window.cookieStore.removeEventListener("change",this.update):this._stopPolling())}}})); | ||
*/var i=function(){if(e)return t;e=1,t.parse=function(e,t){if("string"!=typeof e)throw new TypeError("argument str must be a string");var i={},n=e.length;if(n<2)return i;var r=t&&t.decode||u,s=0,a=0,f=0;do{if(-1===(a=e.indexOf("=",s)))break;if(-1===(f=e.indexOf(";",s)))f=n;else if(a>f){s=e.lastIndexOf(";",a-1)+1;continue}var l=c(e,s,a),p=h(e,a,l),g=e.slice(l,p);if(!o.call(i,g)){var O=c(e,a+1,f),m=h(e,f,O);34===e.charCodeAt(O)&&34===e.charCodeAt(m-1)&&(O++,m--);var y=e.slice(O,m);i[g]=d(y,r)}s=f+1}while(s<n);return i},t.serialize=function(e,t,o){var c=o&&o.encode||encodeURIComponent;if("function"!=typeof c)throw new TypeError("option encode is invalid");if(!n.test(e))throw new TypeError("argument name is invalid");var h=c(t);if(!r.test(h))throw new TypeError("argument val is invalid");var u=e+"="+h;if(!o)return u;if(null!=o.maxAge){var d=Math.floor(o.maxAge);if(!isFinite(d))throw new TypeError("option maxAge is invalid");u+="; Max-Age="+d}if(o.domain){if(!s.test(o.domain))throw new TypeError("option domain is invalid");u+="; Domain="+o.domain}if(o.path){if(!a.test(o.path))throw new TypeError("option path is invalid");u+="; Path="+o.path}if(o.expires){var f=o.expires;if(!function(e){return"[object Date]"===i.call(e)}(f)||isNaN(f.valueOf()))throw new TypeError("option expires is invalid");u+="; Expires="+f.toUTCString()}o.httpOnly&&(u+="; HttpOnly");o.secure&&(u+="; Secure");o.partitioned&&(u+="; Partitioned");if(o.priority){switch("string"==typeof o.priority?o.priority.toLowerCase():o.priority){case"low":u+="; Priority=Low";break;case"medium":u+="; Priority=Medium";break;case"high":u+="; 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:u+="; SameSite=Strict";break;case"lax":u+="; SameSite=Lax";break;case"strict":u+="; SameSite=Strict";break;case"none":u+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return u};var i=Object.prototype.toString,o=Object.prototype.hasOwnProperty,n=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,r=/^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/,s=/^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i,a=/^[\u0020-\u003A\u003D-\u007E]*$/;function c(e,t,i){do{var o=e.charCodeAt(t);if(32!==o&&9!==o)return t}while(++t<i);return i}function h(e,t,i){for(;t>i;){var o=e.charCodeAt(--t);if(32!==o&&9!==o)return t+1}return i}function u(e){return-1!==e.indexOf("%")?decodeURIComponent(e):e}function d(e,t){try{return t(e)}catch(t){return e}}return t}();function o(e,t={}){const i=function(e){if(e&&"j"===e[0]&&":"===e[1])return e.substr(2);return e}(e);if(!t.doNotParse)try{return JSON.parse(i)}catch(e){}return e}return class{constructor(e,t={}){this.changeListeners=[],this.HAS_DOCUMENT_COOKIE=!1,this.update=()=>{if(!this.HAS_DOCUMENT_COOKIE)return;const e=this.cookies;this.cookies=i.parse(document.cookie),this._checkChanges(e)};const o="undefined"==typeof document?"":document.cookie;this.cookies=function(e){return"string"==typeof e?i.parse(e):"object"==typeof e&&null!==e?e:{}}(e||o),this.defaultSetOptions=t,this.HAS_DOCUMENT_COOKIE=function(){const e="undefined"==typeof global?void 0:global.TEST_HAS_DOCUMENT_COOKIE;return"boolean"==typeof e?e:"object"==typeof document&&"string"==typeof document.cookie}()}_emitChange(e){for(let t=0;t<this.changeListeners.length;++t)this.changeListeners[t](e)}_checkChanges(e){new Set(Object.keys(e).concat(Object.keys(this.cookies))).forEach((t=>{e[t]!==this.cookies[t]&&this._emitChange({name:t,value:o(this.cookies[t])})}))}_startPolling(){this.pollingInterval=setInterval(this.update,300)}_stopPolling(){this.pollingInterval&&clearInterval(this.pollingInterval)}get(e,t={}){return t.doNotUpdate||this.update(),o(this.cookies[e],t)}getAll(e={}){e.doNotUpdate||this.update();const t={};for(let i in this.cookies)t[i]=o(this.cookies[i],e);return t}set(e,t,o){o=o?Object.assign(Object.assign({},this.defaultSetOptions),o):this.defaultSetOptions;const n="string"==typeof t?t:JSON.stringify(t);this.cookies=Object.assign(Object.assign({},this.cookies),{[e]:n}),this.HAS_DOCUMENT_COOKIE&&(document.cookie=i.serialize(e,n,o)),this._emitChange({name:e,value:t,options:o})}remove(e,t){const o=t=Object.assign(Object.assign(Object.assign({},this.defaultSetOptions),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=i.serialize(e,"",o)),this._emitChange({name:e,value:void 0,options:t})}addChangeListener(e){this.changeListeners.push(e),this.HAS_DOCUMENT_COOKIE&&1===this.changeListeners.length&&("object"==typeof window&&"cookieStore"in window?window.cookieStore.addEventListener("change",this.update):this._startPolling())}removeChangeListener(e){const t=this.changeListeners.indexOf(e);t>=0&&this.changeListeners.splice(t,1),this.HAS_DOCUMENT_COOKIE&&0===this.changeListeners.length&&("object"==typeof window&&"cookieStore"in window?window.cookieStore.removeEventListener("change",this.update):this._stopPolling())}}})); |
Sorry, the diff of this file is not supported yet
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
52849
1217
+ Addedcookie@0.7.2(transitive)
- Removedcookie@0.6.0(transitive)
Updatedcookie@^0.7.2