2.0.0 • Published 5 years ago
kv-storage-polyfill v2.0.0
kv-storage polyfill
A polyfill for the kv-storage built-in module.
Usage
First, ensure you have an Import Map defined to enable the browser version where supported:
<script type="importmap">
{
"imports": {
"/node_modules/kv-storage/dist/kv-storage-polyfill.mjs": [
"std:kv-storage",
"/node_modules/kv-storage/dist/kv-storage-polyfill.mjs"
]
}
}
</script>
Then import the polyfill. If the browser supports std:kv-storage
natively, it will use that instead:
import { storage } from '/node_modules/kv-storage/dist/kv-storage-polyfill.mjs';
(async () => {
await storage.set("mycat", "Tom");
console.assert(await storage.get("mycat") === "Tom");
console.log(await storage.entries());
// Logs [["mycat", "Tom"]]
await storage.delete("mycat");
console.assert(await storage.get("mycat") === undefined);
})();
License
Apache 2