Module

Web.Storage.Storage

This module defines a data type and various functions for interacting with the Storage interface of the Web Storage API. For example:

import Prelude
import Effect (Effect)
import Effect.Console (log, logShow)
import Web.HTML (window)
import Web.HTML.Window (localStorage)
import Web.Storage.Storage (clear, getItem, removeItem, setItem)

main :: Effect Unit
main = do
  w <- window
  s <- localStorage w
  setItem "this-is-my-key" "Here is my value." s
  v <- getItem "this-is-my-key" s
  logShow v

  removeItem "this-is-my-key" s
  v' <- getItem "this-is-my-key" s
  log "It is gone!"
  logShow v'

  clear s

#Storage

data Storage :: Type

#length

length :: Storage -> Effect Int

Returns the number of items in the storage.

#key

key :: Int -> Storage -> Effect (Maybe String)

Retrieves the key at the given index in the storage, if one exists.

#getItem

getItem :: String -> Storage -> Effect (Maybe String)

Retrieves the value stored at the given key, if one exists.

#setItem

setItem :: String -> String -> Storage -> Effect Unit

Given a key name and a value (in that order), adds that key to the storage or updates its value if it already exists.

#removeItem

removeItem :: String -> Storage -> Effect Unit

Removes the given key from the storage.

#clear

clear :: Storage -> Effect Unit

Clears all keys from the storage.

Modules