A sweet little HTTP cookie parser/serializer for Node.js and the browser.
npm i sugarcookie
import { parse, serialize } from 'sugarcookie'
parse('foo=bar')
// { foo: 'bar' }
serialize('foo', 'bar', {
expires: new Date(2021, 11, 25),
sameSite: 'Lax',
httpOnly: true,
secure: true,
})
// `foo=bar; Expires=Sat, 25 Dec 2021 06:00:00 GMT; SameSite=Lax; HttpOnly; Secure
Note: sugarcookie
doesn't validate the values you pass in. Typescript will
give you guidance, but ultimately ensuring your values match spec is up to you.
domain
-string
expires
-Date
orstring
httpOnly
-boolean
maxAge
-number
in secondspath
-string
sameSite
-Strict
,Lax
, orNone
secure
-boolean
Of course, you can also use the aliases.
import { thaw, bake } from 'sugarcookie'
MIT License © Sure Thing