Shaku

Shaku JS

Back To Table of Content

Storage

Storage

A thin wrapper layer around storage utility.

Kind: global class

new Storage(adapters, prefix, valuesAsBase64, keysAsBase64)

Create the storage.

Param Type Description
adapters Array.<StorageAdapter> List of storage adapters to pick from. Will use the first option returning ‘isValid()’ = true.
prefix String Optional prefix to add to all keys under this storage instance.
valuesAsBase64 Boolean If true, will encode and decode data as base64.
keysAsBase64 Boolean If true, will encode and decode keys as base64.

storage.persistent ⇒ Boolean

Return if this storage adapter is persistent storage or not.

Kind: instance property of Storage
Returns: Boolean - True if this storage type is persistent.

storage.isValid ⇒ Boolean

Check if this storage instance has a valid adapter.

Kind: instance property of Storage
Returns: Boolean - True if found a valid adapter to use, false otherwise.

storage.exists(key) ⇒ Boolean

Check if a key exists.

Kind: instance method of Storage
Returns: Boolean - True if key exists in storage.

Param Type Description
key String Key to check.

storage.setItem(key, value)

Set value.

Kind: instance method of Storage

Param Type Description
key String Key to set.
value String Value to set.

storage.getItem(key) ⇒ String

Get value.

Kind: instance method of Storage
Returns: String - Value or null if not set.

Param Type Description
key String Key to get.

storage.getJson(key) ⇒ \*

Get value and JSON parse it.

Kind: instance method of Storage
Returns: \* - Value as a dictionary object or null if not set.

Param Type Description
key String Key to get.

storage.setJson(key, value)

Set value as JSON.

Kind: instance method of Storage

Param Type Description
key String Key to set.
value \* Value to set as a dictionary.

storage.deleteItem(key)

Delete value.

Kind: instance method of Storage

Param Type Description
key String Key to delete.

storage.clear()

Clear all values from this storage instance, based on prefix + adapter type.

Kind: instance method of Storage

Storage.defaultAdapters

Default adapters to use when no adapters list is provided.

Kind: static property of Storage