API Docs for: 3.18.1

Cookie Class

Module: cookie

Cookie utility.

Item Index

Methods

Methods

exists

(
  • name
)
Boolean static

Determines if the cookie with the given name exists. This is useful for Boolean cookies (those that do not follow the name=value convention).

Parameters:

  • name String

    The name of the cookie to check.

Returns:

Boolean:

True if the cookie exists, false if not.

get

(
  • name
  • options
)
Any static

Returns the cookie value for the given name.

Parameters:

  • name String

    The name of the cookie to retrieve.

  • options Function | Object

    (Optional) An object containing one or more cookie options: raw (true/false), reverseCookieLoading (true/false) and converter (a function). The converter function is run on the value before returning it. The function is not used if the cookie doesn't exist. The function can be passed instead of the options object for backwards compatibility. When raw is set to true, the cookie value is not URI decoded.

Returns:

Any:

If no converter is specified, returns a string or null if the cookie doesn't exist. If the converter is specified, returns the value returned from the converter or null if the cookie doesn't exist.

getSub

(
  • name
  • subName
  • converter
  • options
)
Any static

Returns the value of a subcookie.

Parameters:

  • name String

    The name of the cookie to retrieve.

  • subName String

    The name of the subcookie to retrieve.

  • converter Function

    (Optional) A function to run on the value before returning it. The function is not used if the cookie doesn't exist.

  • options Object

    (Optional) Containing one or more settings for cookie parsing.

Returns:

Any:

If the cookie doesn't exist, null is returned. If the subcookie doesn't exist, null if also returned. If no converter is specified and the subcookie exists, a string is returned. If a converter is specified and the subcookie exists, the value returned from the converter is returned.

getSubs

(
  • name
  • options
)
Object static

Returns an object containing name-value pairs stored in the cookie with the given name.

Parameters:

  • name String

    The name of the cookie to retrieve.

  • options Object

    (Optional) Containing one or more settings for cookie parsing.

Returns:

Object:

An object of name-value pairs if the cookie with the given name exists, null if it does not.

remove

(
  • name
  • options
)
String static

Removes a cookie from the machine by setting its expiration date to sometime in the past.

Parameters:

  • name String

    The name of the cookie to remove.

  • options Object

    (Optional) An object containing one or more cookie options: path (a string), domain (a string), and secure (true/false). The expires option will be overwritten by the method.

Returns:

String:

The created cookie string.

removeSub

(
  • name
  • subName
  • options
)
String static

Removes a sub cookie with a given name.

Parameters:

  • name String

    The name of the cookie in which the subcookie exists.

  • subName String

    The name of the subcookie to remove.

  • options Object

    (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), removeIfEmpty (true/false), and secure (true/false). This must be the same settings as the original subcookie.

Returns:

String:

The created cookie string.

set

(
  • name
  • value
  • options
)
String static

Sets a cookie with a given name and value.

Parameters:

  • name String

    The name of the cookie to set.

  • value Any

    The value to set for the cookie.

  • options Object

    (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), secure (true/false), and raw (true/false). Setting raw to true indicates that the cookie should not be URI encoded before being set.

Returns:

String:

The created cookie string.

setSub

(
  • name
  • subName
  • value
  • options
)
String static

Sets a sub cookie with a given name to a particular value.

Parameters:

  • name String

    The name of the cookie to set.

  • subName String

    The name of the subcookie to set.

  • value Any

    The value to set.

  • options Object

    (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), and secure (true/false).

Returns:

String:

The created cookie string.

setSubs

(
  • name
  • value
  • options
)
String static

Sets a cookie with a given name to contain a hash of name-value pairs.

Parameters:

  • name String

    The name of the cookie to set.

  • value Object

    An object containing name-value pairs.

  • options Object

    (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), and secure (true/false).

Returns:

String:

The created cookie string.