File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- | This module defines a data type and various functions for interacting
2
+ -- | with the `Storage` interface of the Web Storage API.
1
3
module Web.Storage.Storage
2
4
( Storage
3
5
, length
@@ -16,20 +18,26 @@ import Effect (Effect)
16
18
17
19
foreign import data Storage :: Type
18
20
21
+ -- | Returns the number of items in the storage.
19
22
foreign import length :: Storage -> Effect Int
20
23
21
24
foreign import _key :: Int -> Storage -> Effect (Nullable String )
22
25
26
+ -- | Retrieves the key at the given index in the storage, if one exists.
23
27
key :: Int -> Storage -> Effect (Maybe String )
24
28
key i = map toMaybe <<< _key i
25
29
26
30
foreign import _getItem :: String -> Storage -> Effect (Nullable String )
27
31
32
+ -- | Retrieves the value stored at the given key, if one exists.
28
33
getItem :: String -> Storage -> Effect (Maybe String )
29
34
getItem s = map toMaybe <<< _getItem s
30
35
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.
31
37
foreign import setItem :: String -> String -> Storage -> Effect Unit
32
38
39
+ -- | Removes the given key from the storage.
33
40
foreign import removeItem :: String -> Storage -> Effect Unit
34
41
42
+ -- | Clears all keys from the storage.
35
43
foreign import clear :: Storage -> Effect Unit
You can’t perform that action at this time.
0 commit comments