Skip to main content

@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.

Example​

import { setCookie } from '@rtorcato/browser-common/cookies'
setCookie('theme', 'dark', 30)

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


getCookie()​

getCookie(name): string | null

Defined in: cookies/index.ts:34

Gets a cookie value by name.

Example​

import { getCookie } from '@rtorcato/browser-common/cookies'
const theme = getCookie('theme')

Parameters​

name​

string

The cookie name.

Returns​

string | null

The cookie value or null if not found.


deleteCookie()​

deleteCookie(name, path?): void

Defined in: cookies/index.ts:54

Deletes a cookie by name.

Example​

import { deleteCookie } from '@rtorcato/browser-common/cookies'
deleteCookie('theme')

Parameters​

name​

string

The cookie name.

path?​

string = '/'

The cookie path (default: '/').

Returns​

void


hasCookie()​

hasCookie(name): boolean

Defined in: cookies/index.ts:68

Checks if a cookie exists by name.

Example​

import { hasCookie } from '@rtorcato/browser-common/cookies'
if (hasCookie('session')) refresh()

Parameters​

name​

string

The cookie name.

Returns​

boolean

True if the cookie exists, false otherwise.


getAllCookies()​

getAllCookies(): Record<string, string>

Defined in: cookies/index.ts:81

Gets all cookies as an object.

Example​

import { getAllCookies } from '@rtorcato/browser-common/cookies'
const cookies = getAllCookies()

Returns​

Record<string, string>

An object with cookie names and values.