Module: hcje/storage

Functions for managing localStorage.

All keys in the storage are prefixed to prevent clashes with other apps on the same domain.

The keys used for storing items are created as follows:

  • storageKeyPrefix_variantId_itemKey
Source:

Methods

(static) clear()

Clear all storage associated with this application. Note only keys associated with this app are removed. That is keys that begin with the current storage key prefix and variant id; see setStorageKeyPrefix and setVariantId.

Source:

(static) getItem(key) → {*}

Get item from localStorage. The data is assumed to be json and is parsed prior to returning. If the value cannot be parsed, it is removed from storage.

Parameters:
Name Type Description
key string

Item key. NB this will be modified before storage by prefixing with the primary storage key prefix and variant ID; see setStorageKeyPrefix and setVariantId.

Source:
Returns:

Undefined on error or non-existence.

Type
*

(static) removeItem(key)

Remove item from local storage.

Parameters:
Name Type Description
key string

Item key. NB this will be modified before storage by prefixing with the primary storage key prefix and variant ID; see setStorageKeyPrefix and setVariantId.

Source:

(static) setItem(key, value)

Store an item.

Parameters:
Name Type Description
key string

Item key. NB this will be modified before storage by prefixing with the primary storage key prefix and variant ID; see setStorageKeyPrefix and setVariantId.

value *

Value to store. This is stringified before storage.

Source:

(static) setStorageKeyPrefix(prefix)

Set the primary storage prefix. All keys begin with this prefix. Non-word characters are replaced with an underscore. This function must be called prior to using the storage or an exception will be thrown when attempts are made to access the storage.

Parameters:
Name Type Description
prefix string

Prefix for keys.

Source:

(static) setVariantId(idopt)

Set the variant ID. This is added to the key just after the primary storage prefix. Non word characters are replaced with an underscore.

Parameters:
Name Type Attributes Default Description
id string <optional>
''

Variant id.

Source: