Comparing version 0.5.1 to 0.5.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createCookies(req, res) { | ||
const result = {}; | ||
const values = {}; | ||
function get(key) { | ||
var _a, _b; | ||
if (Object.prototype.hasOwnProperty.call(values, key)) | ||
return values[key]; | ||
const cookies = (_b = (_a = req.headers.cookie) === null || _a === void 0 ? void 0 : _a.split('; ')) !== null && _b !== void 0 ? _b : []; | ||
const cookie = cookies.find(cookie => cookie.startsWith(`${key}=`)); | ||
return cookie === null || cookie === void 0 ? void 0 : cookie.split('=')[1]; | ||
return cookie === null || cookie === void 0 ? void 0 : cookie.split('=', 2)[1]; | ||
} | ||
@@ -13,9 +17,9 @@ function set(key, value, options) { | ||
if (options) { | ||
if (options.expires) | ||
if (options.expires !== undefined) | ||
attrs.push(`Expires=${formatExpires(options.expires)}`); | ||
if (options.maxAge) | ||
if (options.maxAge !== undefined) | ||
attrs.push(`Max-Age=${options.maxAge}`); | ||
if (options.domain) | ||
if (options.domain !== undefined) | ||
attrs.push(`Domain=${options.domain}`); | ||
if (options.path) | ||
if (options.path !== undefined) | ||
attrs.push(`Path=${options.path}`); | ||
@@ -28,9 +32,12 @@ if (options.secure) | ||
attrs.push('Partitioned'); | ||
if (options.sameSite) | ||
if (options.sameSite !== undefined) | ||
attrs.push(`SameSite=${options.sameSite}`); | ||
} | ||
res.setHeader('Set-Cookie', attrs.join('; ')); | ||
result[key] = attrs.join('; '); | ||
values[key] = value; | ||
res.setHeader('Set-Cookie', Object.values(result)); | ||
} | ||
function remove(key) { | ||
set(key, '', { maxAge: 0 }); | ||
values[key] = undefined; | ||
} | ||
@@ -37,0 +44,0 @@ return { get, set, remove }; |
{ | ||
"name": "kequapp", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Non-intrusive Node JavaScript web app framework", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
117769
2212