@otterhttp/cookie
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -9,3 +9,3 @@ /** | ||
declare function parse(str: string, options?: { | ||
decode: (str: string) => string; | ||
decode?: ((str: string) => string) | undefined; | ||
}): Record<string, string>; | ||
@@ -19,7 +19,7 @@ type SerializeOptions = Partial<{ | ||
secure: boolean; | ||
sameSite: boolean | 'Strict' | 'strict' | 'Lax' | 'lax' | 'None' | 'none' | string; | ||
sameSite: boolean | "Strict" | "strict" | "Lax" | "lax" | "None" | "none" | string; | ||
expires: Date; | ||
}>; | ||
declare function serialize(name: string, val: string, opt?: SerializeOptions): string; | ||
declare function serialize(name: string, val: string, options?: SerializeOptions): string; | ||
export { type SerializeOptions, parse, serialize }; |
@@ -11,5 +11,4 @@ // src/index.ts | ||
} | ||
function parse(str, options = { | ||
decode: decodeURIComponent | ||
}) { | ||
function parse(str, options = {}) { | ||
options.decode ??= decodeURIComponent; | ||
const obj = {}; | ||
@@ -27,26 +26,26 @@ const pairs = str.split(pairSplitRegExp); | ||
} | ||
function serialize(name, val, opt = {}) { | ||
if (!opt.encode) opt.encode = encodeURIComponent; | ||
function serialize(name, val, options = {}) { | ||
options.encode ??= encodeURIComponent; | ||
if (!fieldContentRegExp.test(name)) throw new TypeError("argument name is invalid"); | ||
const value = opt.encode(val); | ||
const value = options.encode(val); | ||
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 (null != options.maxAge) { | ||
const maxAge = options.maxAge - 0; | ||
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 (options.domain) { | ||
if (!fieldContentRegExp.test(options.domain)) throw new TypeError("option domain is invalid"); | ||
str += `; Domain=${options.domain}`; | ||
} | ||
if (opt.path) { | ||
if (!fieldContentRegExp.test(opt.path)) throw new TypeError("option path is invalid"); | ||
str += `; Path=${opt.path}`; | ||
if (options.path) { | ||
if (!fieldContentRegExp.test(options.path)) throw new TypeError("option path is invalid"); | ||
str += `; Path=${options.path}`; | ||
} | ||
if (opt.expires) str += `; Expires=${opt.expires.toUTCString()}`; | ||
if (opt.httpOnly) str += "; HttpOnly"; | ||
if (opt.secure) str += "; Secure"; | ||
if (opt.sameSite) { | ||
const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite; | ||
if (options.expires) str += `; Expires=${options.expires.toUTCString()}`; | ||
if (options.httpOnly) str += "; HttpOnly"; | ||
if (options.secure) str += "; Secure"; | ||
if (options.sameSite) { | ||
const sameSite = typeof options.sameSite === "string" ? options.sameSite.toLowerCase() : options.sameSite; | ||
switch (sameSite) { | ||
@@ -53,0 +52,0 @@ case true: |
{ | ||
"name": "@otterhttp/cookie", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "HTTP cookie parser and serializer for Node.js", |
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
11269
91