cookie
cookie copied to clipboard
Serialize objects of key/value pairs
Updates the serialize method to accept objects of key-value pairs. ~~If the object of key/value pairs contains multiple pairs, then allow the optional options object to specify only an encoding. If the object of key/value pairs contains only one pair, then the options object may specify cookie parameters as well as an encoding.~~ Resolves #30
What would you think about having separate methods for parsing/serializing the Set-Cookie response header and the Cookie request header? Something like parseSetCookie
, serializeSetCookie
, parseCookieRequest
, serializeCookieRequest
? If this is a worthwhile change, I can make an issue and work on a pr for this.
To follow up on this, my workaround was to do something like:
const cookies = { foo: 'bar', cat: 'meow', dog: 'ruff' };
const serializedCookies = Object.keys(cookies).map(key => cookie.serialize(key, cookies[key]);
The serializedCookies
is now an array of serialized key/value pairs (as string).
The single line of using Object.keys
and Array.map
made me think if there's really a need to overload the serialize
method with this ability.
If anything, instead of overloading the method, I would maybe add a serializeObject
method with a type of serializeObject :: Object -> Array
Was looking around for something like this today, happy to take this over if it's something still of interest to people?
@TomVance @jgornick @NedalEldeen @gatkin @dougwilson
I have wanted this feature recently and updated a new PR against the current state of the main branch.
https://github.com/jshttp/cookie/pull/119
Hi @gatkin I know this is old, but I'm trying to rebase and merge your changes. It seems I don't have the ability to push the rebase to your branch. If you're still around and can check the box on the right-hand side in this PR to allow me to push, that would be awesome. If not, no problem. I'll still get the changes landed, they just won't appear as the PR is merged.