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 expirygetCookie(name)โ returns the cookie value, ornullif not founddeleteCookie(name, path?)โ deletes a cookiehasCookie(name)โtrueif the cookie existsgetAllCookies()โ returns all cookies as aRecord<string, string>
See the API reference for full signatures.