@zero-dependency/cookie
TypeScript icon, indicating that this package has built-in type declarations

1.13.7 • Public • Published

@zero-dependency/cookie

npm version npm bundle size (scoped) npm license

Installation

npm install @zero-dependency/cookie
yarn add @zero-dependency/cookie
pnpm add @zero-dependency/cookie

Usage

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' })

Package Sidebar

Install

npm i @zero-dependency/cookie

Weekly Downloads

20

Version

1.13.7

License

MIT

Unpacked Size

20 kB

Total Files

10

Last publish

Collaborators

  • crashmax