gbr/js/storage

Bindings to local and session storage.

Types

pub type Estimate {
  Estimate(quota: Int, usage: Int)
}

Constructors

  • Estimate(quota: Int, usage: Int)
pub type Storage
pub type StorageManager

Values

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

Clears the storage of all items.

pub fn estimate(
  storage: StorageManager,
) -> promise.Promise(Result(Estimate, String))
pub fn get() -> Result(StorageManager, Nil)
pub fn get_directory(
  storage: StorageManager,
) -> promise.Promise(
  Result(file_system.Handle(file_system.D), String),
)
pub fn get_item(
  storage: Storage,
  key: String,
) -> Result(String, String)

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

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

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, String)

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

pub fn persist(
  storage: StorageManager,
) -> promise.Promise(Result(Bool, String))
pub fn persisted(
  storage: StorageManager,
) -> promise.Promise(Result(Bool, String))
pub fn remove_item(
  storage: Storage,
  key: String,
) -> Result(Nil, String)

Removes an item with the specified key.

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

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, String)

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

Search Document