Class: LocalStorage

just.LocalStorage(consentopt, isExplicitopt)

A mixin of properties that access to some kind of storage in the browser.
Source:
core.js, line 1082

Parameters:

Name Type Default Description
consent
[optional]
boolean false A boolean indicating that the user allowed the access to some kind of local storage.
isExplicit
[optional]
boolean typeof consent !== 'undefined' A value to indicate if the given consent was specified by the user.

Members

DNT :boolean|undefined

The DoNotTrack header formatted as `true`, `false` or `undefined` (for "unspecified").
Source:
core.js, line 1106
Type:

boolean or undefined

Methods

cookieExists(cookie) → {boolean}

Checks if cookie is in document.cookie.
Source:
core.js, line 1141
Parameters:
Name Type Description
cookie
string The name of the cookie or the cookie itself.
Returns:
`true` if it exists, `false` otherwise.
Type
boolean
Example
document.cookie += 'a=b; c=d;';
cookieExists('a'); // true
cookieExists('b'); // false
cookieExists('a=b'); // true
cookieExists('a=d'); // false

getCookie(name) → {string|null}

Returns a cookie from document.cookie.
Source:
core.js, line 1157
Parameters:
Name Type Description
name
string The cookie name.
Returns:
The cookie if it exists or null.
Type
string or null

isStorageAvailable(type, tempKeyopt, tempValueopt) → {boolean}

Tests if the specified storage does not throw.
Source:
core.js, line 1250
Parameters:
Name Type Default Description
type
just.LocalStorage~isStorageAvailable_type A type of storage.
tempKey
[optional]
string '_' Storage will save this key with tempValue as a value.
tempValue
[optional]
string '_' Storage will save this value with tempKey as a key.
Returns:
`true` if the function does not throw and is allowed by the user, `false` otherwise.
Type
boolean

removeCookie(name, optsopt) → {boolean}

Overrides a cookie by setting an empty value and expiring it.
Source:
core.js, line 1220
Parameters:
Name Type Description
name
string The name of the cookie.
opts
[optional]
object Some extra options.
Properties
Name Type Default Description
expires
[optional]
Date new Date(0) A date in the past.
Returns:
`true` if was overriden or the cookie does not exist, `false` otherwise.
Type
boolean

setCookie(name, value, optsopt, non-null) → {boolean}

Concatenates a value to document.cookie.
Source:
core.js, line 1181
Parameters:
Name Type Description
name
string The name of the cookie.
value
string The value of the cookie.
opts
[optional]
object Cookie options.
Properties
Name Type Default Description
secure
[optional]
string location.protocol === 'https:' "secure" flag for the cookie.
Returns:
`true` if was set, `false` otherwise.
Type
boolean

Type Definitions

isStorageAvailable_type

Any of "cookie", "localStorage", "sessionStorage"...
Source:
core.js, line 1232
Type:

string