Closed danielroe closed 5 months ago
This library is for parsing Cookie
header (incoming) which is multi value. Not sure to understand are you proposing to support Set-Cookie
possible values too?
Just like serialize
serialises only a single cookie, we could optionally decode only a single value (that is, skip calling the decode
function for the other ones).
Like the difference between getRequestHeaders
and getRequestHeader
.
@danielroe As an alternate solution, what if the decode function had access to the cookie key? Something like decode?(value: string, key: string)
. That way existing behaviour can be retained while allowing upstream to handle filtering by key to decode only a single value.
https://github.com/unjs/cookie-es/pull/35 is a little bit more verbose but also gives more flexibility.
@danielroe one thing i would suggest for Nuxt use btw if perf of not parsing everytime matters, we could cache the value of parses Cookie
value (string) and only reparse when changed but i guess filter would work too.
I delay next release to finish work on #33 but please let me know if need it earlier or have an opinion about new api.
No worries at all; there's no rush. I like the perf suggestion too!
original issue: https://github.com/nuxt/nuxt/issues/27246
It might be worth considering an option or separate function to return/decode only a single cookie.
What do you think @pi0?