plinth/javascript/storage

Bindings to local and session storage.

Types

A Storage object (local or session).

See https://developer.mozilla.org/en-US/docs/Web/API/Storage.

pub type Storage

Functions

pub fn clear(storage: Storage) -> Nil

Clears the storage of all items.

pub fn get_item(
  storage: Storage,
  key: String,
) -> Result(String, Nil)

Returns the item with the specified key, if it exists.

pub fn key(storage: Storage, index: Int) -> Result(String, Nil)

Returns the key of the item with the index index, if it exists.

pub fn length(storage: Storage) -> Int

Returns the amount of items in the storage.

pub fn local() -> Result(Storage, Nil)

Attempts to get the local storage object, fails if it’s not available.

pub fn remove_item(storage: Storage, key: String) -> Nil

Removes an item with the specified key.

pub fn session() -> Result(Storage, Nil)

Attempts to get the session storage object, fails if it’s not available.

pub fn set_item(
  storage: Storage,
  key: String,
  value: String,
) -> Result(Nil, Nil)

Adds or updates an item with the specified key. If the storage is full, an error is returned.

Search Document