Packages
plinth
0.5.6
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.0
0.1.13
0.1.12
0.1.11
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Bindings to Node.js and browser platform APIs
Current section
Files
Jump to
Current section
Files
src/plinth/javascript/storage.gleam
//// Bindings to local and session storage.
/// A Storage object (local or session).
///
/// See [https://developer.mozilla.org/en-US/docs/Web/API/Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage).
pub type Storage
/// Attempts to get the local storage object, fails if it's not available.
@external(javascript, "../../storage_ffi.mjs", "localStorage")
pub fn local() -> Result(Storage, Nil)
/// Attempts to get the session storage object, fails if it's not available.
@external(javascript, "../../storage_ffi.mjs", "sessionStorage")
pub fn session() -> Result(Storage, Nil)
/// Returns the amount of items in the storage.
@external(javascript, "../../storage_ffi.mjs", "length")
pub fn length(storage: Storage) -> Int
/// Returns the key of the item with the index `index`, if it exists.
@external(javascript, "../../storage_ffi.mjs", "key")
pub fn key(storage: Storage, index: Int) -> Result(String, Nil)
/// Returns the item with the specified key, if it exists.
@external(javascript, "../../storage_ffi.mjs", "getItem")
pub fn get_item(storage: Storage, key: String) -> Result(String, Nil)
/// Adds or updates an item with the specified key. If the storage is full, an error is returned.
@external(javascript, "../../storage_ffi.mjs", "setItem")
pub fn set_item(
storage: Storage,
key: String,
value: String,
) -> Result(Nil, Nil)
/// Removes an item with the specified key.
@external(javascript, "../../storage_ffi.mjs", "removeItem")
pub fn remove_item(storage: Storage, key: String) -> Nil
/// Clears the storage of all items.
@external(javascript, "../../storage_ffi.mjs", "clear")
pub fn clear(storage: Storage) -> Nil