cookie.set(name, value, daysToLive)
Sets a cookie with the provided name, value, and optional daysToLive.
Parameters:
- name (string): The name of the cookie.
- value (string): The value to set for the cookie.
- daysToLive (number, optional): Number of days until the cookie expires. If not provided, the cookie will be session-based.
Usage:
cookie.set("username", "john_doe", 7);
cookie.get(name)
Gets the value of the cookie with the specified name.
Parameters:
- name (string): The name of the cookie to retrieve.
Returns:
- (string | null): Returns the value of the cookie if found, or null if the cookie does not exist.
Usage:
var username = cookie.get("username");
cookie.delete(name)
Deletes the cookie with the specified name.
Parameters:
- name (string): The name of the cookie to delete.
Usage:
cookie.delete("username");
cookie.exists(name)
Checks if a cookie with the specified name exists.
Parameters:
- name (string): The name of the cookie to check.
Returns:
- (boolean): Returns true if the cookie exists, otherwise false.
Usage:
var exists = cookie.exists("username");