- Source:
Methods
(static) cookieExpirationDate(days)
Returns a string with the expiration date for a cookie.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
days |
int
|
Returns:
string - The expiration date for a cookie in UTC format or an empty string if days is not provided
Example
cookieExpirationDate(7) // Returns a string in the format '; expires=Thu, 01 Jan 1970 00:00:00 UTC' for 7 days from now
(static) deleteCookie(name)
Erases a cookie with the given name.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
Returns:
void
Example
setCookie('foo', 'bar', 7)
deleteCookie('foo') // Erases the cookie named 'foo'
getCookie('foo') // Returns null
(static) getCookie(name)
Gets a cookie with the given name.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
Returns:
string|null
Example
setCookie('foo', 'bar', 7)
getCookie('foo') // Returns the value of the cookie named 'foo'
getCookie('bar') // Returns null if the cookie named 'bar' doesn't exist
(static) hasCookie(name)
Checks if a cookie with the given name exists.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
Returns:
boolean
Example
setCookie('foo', 'bar', 7)
hasCookie('foo') // Returns true
hasCookie('bar') // Returns false
(static) setCookie(name, value, days)
Sets a cookie with the given name and value. If days is provided, it will set the expiration date.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
|
value |
string
|
|
days |
int
|
Returns:
void
Example
setCookie('foo', 'bar', 7) // Sets a cookie named 'foo' with the value 'bar' that expires in 7 days
(static) updateCookie(name, value, days)
Updates a cookie with the given name and value. If days is provided, it will set the expiration date.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string
|
|
value |
string
|
number
|
|
days |
int
|
Returns:
void
Example
setCookie('foo', 'bar', 7)
updateCookie('foo', 'baz', 7) // Updates the cookie named 'foo' with the value 'baz' that expires in 7 days
getCookie('foo') // Returns 'baz'