@rtorcato/browser-common / cookies
cookies
Functions
setCookie()
setCookie(
name,value,days?,path?):void
Defined in: cookies/index.ts:13
Sets a cookie in the browser.
Parameters
name
string
The cookie name.
value
string
The cookie value.
days?
number
Number of days until the cookie expires (optional).
path?
string = '/'
The cookie path (default: '/').
Returns
void
Example
import { setCookie } from '@rtorcato/browser-common/cookies'
setCookie('theme', 'dark', 30)
getCookie()
getCookie(
name):string|null
Defined in: cookies/index.ts:34
Gets a cookie value by name.
Parameters
name
string
The cookie name.
Returns
string | null
The cookie value or null if not found.
Example
import { getCookie } from '@rtorcato/browser-common/cookies'
const theme = getCookie('theme')
deleteCookie()
deleteCookie(
name,path?):void
Defined in: cookies/index.ts:54
Deletes a cookie by name.
Parameters
name
string
The cookie name.
path?
string = '/'
The cookie path (default: '/').
Returns
void
Example
import { deleteCookie } from '@rtorcato/browser-common/cookies'
deleteCookie('theme')
hasCookie()
hasCookie(
name):boolean
Defined in: cookies/index.ts:68
Checks if a cookie exists by name.
Parameters
name
string
The cookie name.
Returns
boolean
True if the cookie exists, false otherwise.
Example
import { hasCookie } from '@rtorcato/browser-common/cookies'
if (hasCookie('session')) refresh()
getAllCookies()
getAllCookies():
Record<string,string>
Defined in: cookies/index.ts:81
Gets all cookies as an object.
Returns
Record<string, string>
An object with cookie names and values.
Example
import { getAllCookies } from '@rtorcato/browser-common/cookies'
const cookies = getAllCookies()