@tinyhttp/cookie
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -17,10 +17,7 @@ const pairSplitRegExp = /; */; | ||
let eqIdx = pair.indexOf("="); | ||
if (eqIdx < 0) | ||
continue; | ||
const key = pair.substr(0, eqIdx).trim(); | ||
let val = pair.substr(++eqIdx, pair.length).trim(); | ||
if ('"' == val[0]) | ||
val = val.slice(1, -1); | ||
if (obj[key] == null) | ||
obj[key] = tryDecode(val, options.decode); | ||
if (eqIdx < 0) continue; | ||
const key = pair.slice(0, eqIdx).trim(); | ||
let val = pair.slice(++eqIdx, pair.length).trim(); | ||
if ('"' === val[0]) val = val.slice(1, -1); | ||
if (obj[key] == null) obj[key] = tryDecode(val, options.decode); | ||
} | ||
@@ -30,32 +27,23 @@ return obj; | ||
function serialize(name, val, opt = {}) { | ||
if (!opt.encode) | ||
opt.encode = encodeURIComponent; | ||
if (!fieldContentRegExp.test(name)) | ||
throw new TypeError("argument name is invalid"); | ||
if (!opt.encode) opt.encode = encodeURIComponent; | ||
if (!fieldContentRegExp.test(name)) throw new TypeError("argument name is invalid"); | ||
const value = opt.encode(val); | ||
if (value && !fieldContentRegExp.test(value)) | ||
throw new TypeError("argument val is invalid"); | ||
let str = name + "=" + value; | ||
if (value && !fieldContentRegExp.test(value)) throw new TypeError("argument val is invalid"); | ||
let str = `${name}=${value}`; | ||
if (null != opt.maxAge) { | ||
const maxAge = opt.maxAge - 0; | ||
if (isNaN(maxAge) || !isFinite(maxAge)) | ||
throw new TypeError("option maxAge is invalid"); | ||
str += "; Max-Age=" + Math.floor(maxAge); | ||
if (Number.isNaN(maxAge) || !Number.isFinite(maxAge)) throw new TypeError("option maxAge is invalid"); | ||
str += `; Max-Age=${Math.floor(maxAge)}`; | ||
} | ||
if (opt.domain) { | ||
if (!fieldContentRegExp.test(opt.domain)) | ||
throw new TypeError("option domain is invalid"); | ||
str += "; Domain=" + opt.domain; | ||
if (!fieldContentRegExp.test(opt.domain)) throw new TypeError("option domain is invalid"); | ||
str += `; Domain=${opt.domain}`; | ||
} | ||
if (opt.path) { | ||
if (!fieldContentRegExp.test(opt.path)) | ||
throw new TypeError("option path is invalid"); | ||
str += "; Path=" + opt.path; | ||
if (!fieldContentRegExp.test(opt.path)) throw new TypeError("option path is invalid"); | ||
str += `; Path=${opt.path}`; | ||
} | ||
if (opt.expires) | ||
str += "; Expires=" + opt.expires.toUTCString(); | ||
if (opt.httpOnly) | ||
str += "; HttpOnly"; | ||
if (opt.secure) | ||
str += "; Secure"; | ||
if (opt.expires) str += `; Expires=${opt.expires.toUTCString()}`; | ||
if (opt.httpOnly) str += "; HttpOnly"; | ||
if (opt.secure) str += "; Secure"; | ||
if (opt.sameSite) { | ||
@@ -84,1 +72,2 @@ const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@tinyhttp/cookie", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "HTTP cookie parser and serializer for Node.js", |
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
16986
7
91