spotify-ts-wrapper
Version:
Spotify TypeScript wrapper.
24 lines (23 loc) • 872 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCookieString = parseCookieString;
function parseCookieString(cookieString) {
const cookies = cookieString.split(/,\s(?=[^;]+?=)/);
const cookieObj = {};
cookies.forEach((cookie) => {
const parts = cookie.split(";").map((part) => part.trim());
const [key, value] = parts[0].split("=");
cookieObj[key] = { value: decodeURIComponent(value) };
parts.slice(1).forEach((attribute) => {
const [attrKey, attrValue] = attribute.split("=");
const attrName = attrKey.toLowerCase();
if (attrValue) {
cookieObj[key][attrName] = decodeURIComponent(attrValue);
}
else {
cookieObj[key][attrName] = true;
}
});
});
return cookieObj;
}