@icebro/actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
22 lines (21 loc) • 636 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCookies = void 0;
/**
* Transform the cookie headers of a node HTTP `req` Object into a hash.
*/
function parseCookies(req) {
const cookies = {};
if (req.headers.cookie) {
(Array.isArray(req.headers.cookie)
? req.headers.cookie.join("")
: req.headers.cookie)
.split(";")
.forEach((cookie) => {
const parts = cookie.split("=");
cookies[parts[0].trim()] = (parts[1] || "").trim();
});
}
return cookies;
}
exports.parseCookies = parseCookies;