Expand all

mediawiki.storage~SafeStorage

A wrapper for the HTML5 Storage interface (localStorage or sessionStorage) that is safe to call in all browsers.

The constructor is not publicly accessible. An instance can be accessed from mw.storage or module:mediawiki.storage.

Methods

get(key) → {string|null|boolean} #

Retrieve value from device storage.

Parameters:

Name Type Description
key string

Key of item to retrieve

Returns:

String value, null if no value exists, or false if storage is not available.

Type
string | null | boolean
Source:
Retrieve value from device storage.

getObject(key) → {Object|null|boolean} #

Retrieve JSON object from device storage.

Parameters:

Name Type Description
key string

Key of item to retrieve

Returns:

Object, null if no value exists or value is not JSON-parseable, or false if storage is not available.

Type
Object | null | boolean
Source:
Retrieve JSON object from device storage.

remove(key) → {boolean} #

Remove a value from device storage.

Parameters:

Name Type Description
key string

Key of item to remove

Returns:

Whether the key was removed

Type
boolean
Source:
Remove a value from device storage.

set(key, value, [expiry]) → {boolean} #

Set a value in device storage.

Parameters:

Name Type Attributes Description
key string

Key name to store under

value string

Value to be stored

expiry number optional

Number of seconds after which this item can be deleted

Returns:

The value was set

Type
boolean
Source:
Set a value in device storage.

setExpires(key, [expiry]) → {boolean} #

Set the expiry time for an item in the store.

Parameters:

Name Type Attributes Description
key string

Key name

expiry number optional

Number of seconds after which this item can be deleted, omit to clear the expiry (either making the item never expire, or to clean up when deleting a key).

Returns:

The expiry was set (or cleared) [since 1.41]

Type
boolean
Source:
Set the expiry time for an item in the store.

setObject(key, value, [expiry]) → {boolean} #

Set an object value in device storage by JSON encoding.

Parameters:

Name Type Attributes Description
key string

Key name to store under

value Object

Object value to be stored

expiry number optional

Number of seconds after which this item can be deleted

Returns:

The value was set

Type
boolean
Source:
Set an object value in device storage by JSON encoding.