JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q49530F
  • License MIT

Cookie parser and serializer

Package Exports

  • @zero-dependency/cookie

Readme

@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 cookies = new Cookie(/* options */)

// Create a cookie.
cookies.set('name', 'value')

// Create a cookie that expires 7 days from now.
cookies.set('name', 'value', { expires: 7 })

// Create an expiring cookie, valid to the path of the current page.
cookies.set('name', 'value', { expires: 7, path: '' })

// Read cookie.
cookies.get('name')

// Read all visible cookies.
cookies.list()

// Remove cookie.
cookies.remove('name')

// Remove a cookie valid to the path of the current page.
cookies.set('name', 'value', { path: '/some-path' })
cookies.remove('name'); // fail!
cookies.remove('name', { path: '/some-path' }); // success!

// Cookie attribute defaults can be set globally.
cookies.withAttributes({ path: '/', domain: '.example.com' })