Class: KeyValueStorage

storage~KeyValueStorage

Class for a key-value storage area, where the key is a string and the value can have any of a number of basic types. The class is modeled on the built-in Map type, but backed by persistent storage and using Promise return values. Create instances of the class with createKeyValueStorage.

Source:

Methods

(async) clear()

Clear all key-value pairs in the storage area. Note that this function loads and iterates all key-value pairs in extension local storage, so it may have performance implications.

Source:

(async) delete(key) → {Promise.<boolean>}

Delete a key-value pair from storage.

Parameters:
Name Type Description
key string

The key to use in the storage area.

Source:
Returns:

Whether the key was in use in the storage area.

Type
Promise.<boolean>

(async) entries() → {Promise.<Object>}

Create an iterator over key-value pairs in the storage area. Note that this function loads and iterates all key-value pairs in extension local storage, so it may have performance implications.

Source:
Returns:

A Promise that resolves to an iterator over the key-value pairs in the storage area.

Type
Promise.<Object>

(async) get(key) → {Promise}

Get a value from storage by its key.

Parameters:
Name Type Description
key string

The key to use in the storage area.

Source:
Returns:

A Promise that resolves to the key's value in the storage area, or null if the key is not in the storage area. Note that this is slightly different behavior from Map, which returns undefined if a key is not present.

Type
Promise

(async) has(key) → {Promise.<boolean>}

Check whether a key is associated with a value in the storage area.

Parameters:
Name Type Description
key string

The key to use in the storage area.

Source:
Returns:

Whether the key is associated with a value in the storage area.

Type
Promise.<boolean>

(async) keys() → {Promise.<Object>}

Create an iterator over keys in the storage area. Note that this function loads and iterates all key-value pairs in extension local storage, so it may have performance implications.

Source:
Returns:

A Promise that resolves to an iterator over the keys in the storage area.

Type
Promise.<Object>

(async) set(key, value)

Set a key-value pair in storage.

Parameters:
Name Type Description
key string

The key to use in the storage area.

value *

The value to store in the storage area for the key.

Source:

(async) toObject() → {Promise.<Object>}

Convert the storage area into an object. Note that this function loads and iterates all key-value pairs in extension local storage, so it may have performance implications.

Source:
Returns:

A promise that resolves to an object where properties are keys in the storage area and values are stored values.

Type
Promise.<Object>

(async) values() → {Promise.<Object>}

Create an iterator over values in the storage area. Note that this function loads and iterates all key-value pairs in extension local storage, so it may have performance implications.

Source:
Returns:

A Promise that resolves to an iterator over the values in the storage area.

Type
Promise.<Object>