diff --git a/src/WebStorageAPI/Storage.res b/src/WebStorageAPI/Storage.res index e0778a4..17765bb 100644 --- a/src/WebStorageAPI/Storage.res +++ b/src/WebStorageAPI/Storage.res @@ -5,14 +5,14 @@ Returns the name of the nth key, or null if n is greater than or equal to the nu [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Storage/key) */ @send -external key: (storage, int) => string = "key" +external key: (storage, int) => Null.t = "key" /** Returns the current value associated with the given key, or null if the given key does not exist. [Read more on MDN](https://developer.mozilla.org/docs/Web/API/Storage/getItem) */ @send -external getItem: (storage, string) => string = "getItem" +external getItem: (storage, string) => Null.t = "getItem" /** Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously. diff --git a/tests/WebStorageAPI/Storage__test.js b/tests/WebStorageAPI/Storage__test.js new file mode 100644 index 0000000..ca08ebb --- /dev/null +++ b/tests/WebStorageAPI/Storage__test.js @@ -0,0 +1,20 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Null from "rescript/lib/es6/Null.js"; + +for (let i = 0, i_finish = localStorage.length; i < i_finish; ++i) { + console.log(Null.getOr(localStorage.key(i), "nothing")); +} + +let item1 = Null.getOr(localStorage.getItem("foo"), "nothing"); + +localStorage.setItem("bar", "..."); + +localStorage.removeItem("bar"); + +localStorage.clear(); + +export { + item1, +} +/* Not a pure module */ diff --git a/tests/WebStorageAPI/Storage__test.res b/tests/WebStorageAPI/Storage__test.res new file mode 100644 index 0000000..4a7d2dc --- /dev/null +++ b/tests/WebStorageAPI/Storage__test.res @@ -0,0 +1,14 @@ +open WebAPI.Global +open WebAPI.Storage + +for i in 0 to localStorage.length - 1 { + localStorage->key(i)->Null.getOr("nothing")->Console.log +} + +let item1 = localStorage->getItem("foo")->Null.getOr("nothing") + +localStorage->setItem(~key="bar", ~value="...") + +localStorage->removeItem("bar") + +localStorage->clear