sugarcookie

A sweet little HTTP cookie parser/serializer for Node.js and the browser.


License
MIT
Install
npm install sugarcookie@1.0.0

Documentation

sugarcookie

npm version test coverage npm bundle size

A sweet little HTTP cookie parser/serializer for Node.js and the browser.

npm i sugarcookie

Usage

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.

Serializer options

  • domain - string
  • expires - Date or string
  • httpOnly - boolean
  • maxAge - number in seconds
  • path - string
  • sameSite - Strict, Lax, or None
  • secure - boolean

Aliases

Of course, you can also use the aliases.

import { thaw, bake } from 'sugarcookie'

License

MIT License © Sure Thing