Cookie

Table of Contents
Examples
Basic Usage
JavaScript Reference
saveCookie
getCookie
deleteCookie

Description

The Cookie utility provides functions to manage cookies in the browser.

Basic Usage

import { saveCookie, getCookie, deleteCookie } from '../src/utils/cookie.js';

// Save a cookie
saveCookie('username', 'john_doe');

// Get a cookie
const username = getCookie('username');
console.log(username);

// Delete a cookie
deleteCookie('username');

JavaScript Reference

saveCookie

saveCookie(name string, value string, minutes number, path string)

Parameters

name: string

The name of the cookie.

value: string

The value of the cookie.

minutes: number

The expiration time of the cookie in minutes. Default is 30 days.

path: string

The path where the cookie is accessible. Default is '/'.

getCookie

getCookie(name string)

Parameters

name: string

The name of the cookie to retrieve.

Returns

The value of the cookie, or null if the cookie does not exist.

deleteCookie

deleteCookie(name string)

Parameters

name: string

The name of the cookie to delete.