@bundled-es-modules/cookie
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -34,4 +34,8 @@ var __create = Object.create; | ||
var __toString = Object.prototype.toString; | ||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; | ||
function parse(str, options) { | ||
var __hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var cookieNameRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/; | ||
var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/; | ||
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; | ||
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/; | ||
function parse(str, opt) { | ||
if (typeof str !== "string") { | ||
@@ -41,52 +45,72 @@ throw new TypeError("argument str must be a string"); | ||
var obj = {}; | ||
var opt = options || {}; | ||
var dec = opt.decode || decode; | ||
var len = str.length; | ||
if (len < 2) return obj; | ||
var dec = opt && opt.decode || decode; | ||
var index = 0; | ||
while (index < str.length) { | ||
var eqIdx = str.indexOf("=", index); | ||
if (eqIdx === -1) { | ||
break; | ||
} | ||
var endIdx = str.indexOf(";", index); | ||
var eqIdx = 0; | ||
var endIdx = 0; | ||
do { | ||
eqIdx = str.indexOf("=", index); | ||
if (eqIdx === -1) break; | ||
endIdx = str.indexOf(";", index); | ||
if (endIdx === -1) { | ||
endIdx = str.length; | ||
} else if (endIdx < eqIdx) { | ||
endIdx = len; | ||
} else if (eqIdx > endIdx) { | ||
index = str.lastIndexOf(";", eqIdx - 1) + 1; | ||
continue; | ||
} | ||
var key = str.slice(index, eqIdx).trim(); | ||
if (void 0 === obj[key]) { | ||
var val = str.slice(eqIdx + 1, endIdx).trim(); | ||
if (val.charCodeAt(0) === 34) { | ||
val = val.slice(1, -1); | ||
var keyStartIdx = startIndex(str, index, eqIdx); | ||
var keyEndIdx = endIndex(str, eqIdx, keyStartIdx); | ||
var key = str.slice(keyStartIdx, keyEndIdx); | ||
if (!__hasOwnProperty.call(obj, key)) { | ||
var valStartIdx = startIndex(str, eqIdx + 1, endIdx); | ||
var valEndIdx = endIndex(str, endIdx, valStartIdx); | ||
if (str.charCodeAt(valStartIdx) === 34 && str.charCodeAt(valEndIdx - 1) === 34) { | ||
valStartIdx++; | ||
valEndIdx--; | ||
} | ||
var val = str.slice(valStartIdx, valEndIdx); | ||
obj[key] = tryDecode(val, dec); | ||
} | ||
index = endIdx + 1; | ||
} | ||
} while (index < len); | ||
return obj; | ||
} | ||
function serialize(name, val, options) { | ||
var opt = options || {}; | ||
var enc = opt.encode || encode; | ||
function startIndex(str, index, max) { | ||
do { | ||
var code = str.charCodeAt(index); | ||
if (code !== 32 && code !== 9) return index; | ||
} while (++index < max); | ||
return max; | ||
} | ||
function endIndex(str, index, min) { | ||
while (index > min) { | ||
var code = str.charCodeAt(--index); | ||
if (code !== 32 && code !== 9) return index + 1; | ||
} | ||
return min; | ||
} | ||
function serialize(name, val, opt) { | ||
var enc = opt && opt.encode || encodeURIComponent; | ||
if (typeof enc !== "function") { | ||
throw new TypeError("option encode is invalid"); | ||
} | ||
if (!fieldContentRegExp.test(name)) { | ||
if (!cookieNameRegExp.test(name)) { | ||
throw new TypeError("argument name is invalid"); | ||
} | ||
var value = enc(val); | ||
if (value && !fieldContentRegExp.test(value)) { | ||
if (!cookieValueRegExp.test(value)) { | ||
throw new TypeError("argument val is invalid"); | ||
} | ||
var str = name + "=" + value; | ||
if (!opt) return str; | ||
if (null != opt.maxAge) { | ||
var maxAge = opt.maxAge - 0; | ||
if (isNaN(maxAge) || !isFinite(maxAge)) { | ||
var maxAge = Math.floor(opt.maxAge); | ||
if (!isFinite(maxAge)) { | ||
throw new TypeError("option maxAge is invalid"); | ||
} | ||
str += "; Max-Age=" + Math.floor(maxAge); | ||
str += "; Max-Age=" + maxAge; | ||
} | ||
if (opt.domain) { | ||
if (!fieldContentRegExp.test(opt.domain)) { | ||
if (!domainValueRegExp.test(opt.domain)) { | ||
throw new TypeError("option domain is invalid"); | ||
@@ -97,3 +121,3 @@ } | ||
if (opt.path) { | ||
if (!fieldContentRegExp.test(opt.path)) { | ||
if (!pathValueRegExp.test(opt.path)) { | ||
throw new TypeError("option path is invalid"); | ||
@@ -116,2 +140,5 @@ } | ||
} | ||
if (opt.partitioned) { | ||
str += "; Partitioned"; | ||
} | ||
if (opt.priority) { | ||
@@ -157,7 +184,4 @@ var priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority; | ||
} | ||
function encode(val) { | ||
return encodeURIComponent(val); | ||
} | ||
function isDate(val) { | ||
return __toString.call(val) === "[object Date]" || val instanceof Date; | ||
return __toString.call(val) === "[object Date]"; | ||
} | ||
@@ -164,0 +188,0 @@ function tryDecode(str, decode2) { |
{ | ||
"name": "@bundled-es-modules/cookie", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "mirror of cookie, bundled and exposed as ES module", | ||
@@ -8,2 +8,6 @@ "author": "Pascal Schilp <pascalschilp@gmail.com>", | ||
"type": "module", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bundled-es-modules/cookie" | ||
}, | ||
"exports": { | ||
@@ -17,3 +21,3 @@ ".": { | ||
"dev": "node --watch dev.js", | ||
"build": "esbuild source.js --bundle --format=esm --outfile=index.js" | ||
"build": "esbuild source.js --bundle --format=esm --outfile=index-esm.js" | ||
}, | ||
@@ -27,7 +31,7 @@ "keywords": [], | ||
"dependencies": { | ||
"cookie": "^0.5.0" | ||
"cookie": "^0.7.2" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "^0.17.17" | ||
"esbuild": "^0.24.0" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8147
206
0
+ Addedcookie@0.7.2(transitive)
- Removedcookie@0.5.0(transitive)
Updatedcookie@^0.7.2