Class: Cookie

Cookie()

A Singleton wrapper for the document cookie.

Constructor

NOTE: The cookie cannot be instantiated directly! Use SSC.Cookie.getInstance() instead.
Source:
See:
Example
const cookie = SSC.Cookie.getInstance('testcookie');
cookie
    .set('foo', 'bar')
    .set('baz', 42)
    .setSecure()
    .write();
console.log(cookie.getAll());

Methods

(static) getInstance(nameopt) → {SSC.Cookie}

Get Singleton instance of Cookie, depending on the given name.
Parameters:
Name Type Attributes Default Description
name string <optional>
sscdata The name of the cookie
Source:
Returns:
Singleton instance of Cookie class
Type
SSC.Cookie

(static) isWritable() → {boolean}

Test whether the user's browser accepts cookies.
Source:
Returns:
Are cookies allowed?
Type
boolean

destroy()

Delete the cookie.
Source:

get(key) → {mixed|undefined}

Retrieve the value for the given key.
Parameters:
Name Type Description
key string The key to get the value for
Source:
Returns:
The value for the given key
Type
mixed | undefined

getAll() → {Object}

Return all cookie data as an object.
Source:
Returns:
The cookie's data
Type
Object

remove(key) → {mixed|undefined}

Remove the element with the given key.
Call the write() function to persist the data into the document cookie.
Parameters:
Name Type Description
key string The key of the element to remove
Source:
Returns:
The value of the removed element
Type
mixed | undefined

set(key, value) → {SSC.Cookie}

Set the value of the given key.
Call the write() function to persist the data into the document cookie.
Parameters:
Name Type Description
key string The key to set the value of
value mixed The value to set
Source:
Throws:
If "key" is not a string or "value" is undefined
Type
TypeError
Returns:
The Cookie object (for method chaining)
Type
SSC.Cookie

setDomain(cookieDomain) → {SSC.Cookie}

Set the cookie domain (defaults to current domain).
Call the write() function to persist the setting into the document cookie.
Parameters:
Name Type Description
cookieDomain string The domain to set
Source:
Returns:
The Cookie object (for method chaining)
Type
SSC.Cookie

setExpiry(expiry) → {SSC.Cookie}

Set the cookie's expiry time in RFC-2822 format (DAY, DD MMM YYYY hh:mm:ss GMT) or from an instantiated Date object (defaults to end of session).
Call the write() function to persist the setting into the document cookie.
Parameters:
Name Type Description
expiry string | Date The expiry time to set
Source:
Returns:
The Cookie object (for method chaining)
Type
SSC.Cookie

setExpiryTimestamp(expiry) → {SSC.Cookie}

Set the expiry time as Unix timestamp.
Call the write() function to persist the setting into the document cookie.
Parameters:
Name Type Description
expiry number The expiry time to set
Source:
Returns:
The Cookie object (for method chaining)
Type
SSC.Cookie

setPath(cookiePath) → {SSC.Cookie}

Set the path for which the cookie is active (defaults to "/").
Call the write() function to persist the setting into the document cookie.
Parameters:
Name Type Description
cookiePath string The path to set
Source:
Returns:
The Cookie object (for method chaining)
Type
SSC.Cookie

setSecure(secureopt) → {SSC.Cookie}

Set secure mode (SSL) when sending the cookie to the server (defaults to false).
Call the write() function to persist the setting into the document cookie.
Parameters:
Name Type Attributes Default Description
secure boolean <optional>
true Use secure mode?
Source:
Returns:
The Cookie object (for method chaining)
Type
SSC.Cookie

write()

Persist the set data and all settings into the document cookie.
Source: