https://github.com/front-of-house/sugarcookie
Sweet little HTTP cookie parser/serializer for Node.js and the browser.
https://github.com/front-of-house/sugarcookie
Last synced: 26 days ago
JSON representation
Sweet little HTTP cookie parser/serializer for Node.js and the browser.
- Host: GitHub
- URL: https://github.com/front-of-house/sugarcookie
- Owner: front-of-house
- Created: 2021-12-26T22:40:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-26T23:03:03.000Z (over 3 years ago)
- Last Synced: 2025-03-15T10:31:50.050Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 44.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sugarcookie
[](https://www.npmjs.com/package/sugarcookie) [](https://coveralls.io/github/sure-thing/sugarcookie?branch=main) [](https://bundlephobia.com/result?p=sugarcookie)
A sweet little HTTP cookie parser/serializer for Node.js and the browser.
```
npm i sugarcookie
```## Usage
```javascript
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.
```javascript
import { thaw, bake } from 'sugarcookie'
```### License
MIT License © [Sure Thing](https://github.com/sure-thing)