Skip to content

Commit 0e44768

Browse files
elliotdaviesnatefaubion
authored andcommitted
Add docs to storage module (#7)
1 parent e9e9c82 commit 0e44768

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Web/Storage/Storage.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- | This module defines a data type and various functions for interacting
2+
-- | with the `Storage` interface of the Web Storage API.
13
module Web.Storage.Storage
24
( Storage
35
, length
@@ -16,20 +18,26 @@ import Effect (Effect)
1618

1719
foreign import data Storage :: Type
1820

21+
-- | Returns the number of items in the storage.
1922
foreign import length :: Storage -> Effect Int
2023

2124
foreign import _key :: Int -> Storage -> Effect (Nullable String)
2225

26+
-- | Retrieves the key at the given index in the storage, if one exists.
2327
key :: Int -> Storage -> Effect (Maybe String)
2428
key i = map toMaybe <<< _key i
2529

2630
foreign import _getItem :: String -> Storage -> Effect (Nullable String)
2731

32+
-- | Retrieves the value stored at the given key, if one exists.
2833
getItem :: String -> Storage -> Effect (Maybe String)
2934
getItem s = map toMaybe <<< _getItem s
3035

36+
-- | Given a key name and a value (in that order), adds that key to the storage or updates its value if it already exists.
3137
foreign import setItem :: String -> String -> Storage -> Effect Unit
3238

39+
-- | Removes the given key from the storage.
3340
foreign import removeItem :: String -> Storage -> Effect Unit
3441

42+
-- | Clears all keys from the storage.
3543
foreign import clear :: Storage -> Effect Unit

0 commit comments

Comments
 (0)