cookie icon indicating copy to clipboard operation
cookie copied to clipboard

Serialize objects of key/value pairs

Open gatkin opened this issue 9 years ago • 5 comments

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

gatkin avatar Oct 25 '15 18:10 gatkin

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.

gatkin avatar Oct 26 '15 20:10 gatkin

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

jgornick avatar Aug 04 '16 16:08 jgornick

Was looking around for something like this today, happy to take this over if it's something still of interest to people?

TomVance avatar Aug 16 '19 12:08 TomVance

@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

export-mike avatar Jan 13 '21 01:01 export-mike

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.

dougwilson avatar Mar 30 '22 05:03 dougwilson