https://github.com/zero-dependency/cookie
🍪 Document.cookie wrapper
https://github.com/zero-dependency/cookie
api cookie cookies javascript package typescript zero-dependency
Last synced: about 1 year ago
JSON representation
🍪 Document.cookie wrapper
- Host: GitHub
- URL: https://github.com/zero-dependency/cookie
- Owner: zero-dependency
- Created: 2022-10-07T17:34:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-30T11:41:19.000Z (about 2 years ago)
- Last Synced: 2025-01-27T04:18:30.542Z (about 1 year ago)
- Topics: api, cookie, cookies, javascript, package, typescript, zero-dependency
- Language: TypeScript
- Homepage:
- Size: 87.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @zero-dependency/cookie
[](https://npm.im/@zero-dependency/cookie)
[](https://bundlephobia.com/package/@zero-dependency/cookie@latest)

## Installation
```sh
npm install @zero-dependency/cookie
```
```sh
yarn add @zero-dependency/cookie
```
```sh
pnpm add @zero-dependency/cookie
```
## Usage
```js
import { Cookie } from '@zero-dependency/cookie'
const cookie = new Cookie({ /* options */ })
// Create a cookie.
cookie.set('name', 'value')
// Create a cookie that expires 7 days from now.
cookie.set('name', 'value', { expires: 7 })
// Create a cookie.
cookie.get('name')
// Get all cookies.
cookie.list()
// Check if a cookie exists.
cookie.has('name')
// Remove a cookie.
cookie.remove('name')
// Remove a cookie by passing the exact same path and domain as when the cookie was set.
cookie.set('name', 'value', { path: '/some-path' })
cookie.remove('name'); // ❌
cookie.remove('name', { path: '/some-path' }); // ✅
// Cookie attribute defaults can be set globally.
cookie.setAttributes({ path: '/', domain: '.example.com' })
```