This module contains some utility methods to read and write cookies.
The module makes some assumptions on the cookie usage: some cookie options are not configurable and use fixed defaults.
The module makes some assumptions on the cookie usage: some cookie options are not configurable and use fixed defaults.
Method Summary
- areCookiesEnabled
- Checks if the module is able to read and write cookies: when the module is loaded it performs a simple check to verify the functionality.
- getAllCookiesAsSingleString
- Returns document.
- readCookie
- Reads a cookie from the browser
- removeCookie
- Removes a cookie by setting its expire date to "yesterday"
- writeCookie
- Writes a cookie.
Method Detail
-
<static> areCookiesEnabled() → {Boolean}
-
Checks if the module is able to read and write cookies: when the module is loaded it performs a simple check to verify the functionality. When running on Node.js or WebWorkers it is always false.
Returns:
- Type
- Boolean
-
<static> getAllCookiesAsSingleString()
-
Returns document.cookie if areCookiesEnabled is true, null otherwise
Returns:
the document.cookie or null -
<static> readCookie(key) → {String}
-
Reads a cookie from the browser
Parameters:
Name Type Description keyString the name of the cookie to be read. The key is encoded before it is used. Returns:
the cookie value or null if the cookie does not exists or if areCookiesEnabled is false.- Type
- String
-
<static> removeCookie(key)
-
Removes a cookie by setting its expire date to "yesterday"
Parameters:
Name Type Description keyString key the name of the cookie to be deleted. The key is encoded before it is used. -
<static> writeCookie(key, val)
-
Writes a cookie. The path specified in the cookie is always /
Parameters:
Name Type Description keyString the name of the cookie to be written. The key is encoded before it is used. valString the value of the cookie to be written