dsql-admin/dsql-app/package-shared/utils/serialize-cookies.js
Benjamin Toby bc037e839f Updates
2024-12-15 12:27:16 +01:00

49 lines
1.3 KiB
JavaScript

// @ts-check
/**
*
* @param {object} params
* @param {import("../types").CookieObject[]} params.cookies
* @returns {string[]}
*/
function serializeCookies({ cookies }) {
/** @type {string[]} */
let cookiesStringsArray = [];
for (let i = 0; i < cookies.length; i++) {
const cookieObject = cookies[i];
let cookieString = `${cookieObject.name}=${cookieObject.value}`;
if (cookieObject.maxAge) {
cookieString += `;Max-Age=${cookieObject.maxAge}`;
}
if (cookieObject.path) {
cookieString += `;Path=${cookieObject.path}`;
}
if (cookieObject.domain) {
cookieString += `;Domain=${cookieObject.domain}`;
}
if (cookieObject.secure) {
cookieString += ";Secure";
}
if (cookieObject.httpOnly) {
cookieString += ";HttpOnly";
}
if (cookieObject.sameSite) {
cookieString += `;SameSite=${cookieObject.sameSite}`;
}
if (cookieObject.expires) {
cookieString += `;expires=${cookieObject.expires}`;
}
if (cookieObject.priority) {
cookieString += `;priority=${cookieObject.priority}`;
}
cookiesStringsArray.push(cookieString);
}
return cookiesStringsArray;
}
module.exports = serializeCookies;