Skip to main content

cookies

Read, write, and delete document.cookie entries without hand-rolling the parsing and encoding.

Import: @rtorcato/browser-common/cookies

๐Ÿ“– MDN: Document.cookie ยท ๐Ÿ“Š caniuse: cookies

Exampleโ€‹

import { setCookie, getCookie, hasCookie, deleteCookie } from '@rtorcato/browser-common/cookies'

setCookie('theme', 'dark', 30)

if (hasCookie('theme')) {
const theme = getCookie('theme')
}

deleteCookie('theme')

Exportsโ€‹

  • setCookie(name, value, days?, path?) โ€” sets a cookie, optionally with an expiry
  • getCookie(name) โ€” returns the cookie value, or null if not found
  • deleteCookie(name, path?) โ€” deletes a cookie
  • hasCookie(name) โ€” true if the cookie exists
  • getAllCookies() โ€” returns all cookies as a Record<string, string>

See the API reference for full signatures.