Skip to content
A polyfill for the kv-storage built-in module.
Branch: master
Clone or download
Latest commit 7de6cba Mar 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Initial release Mar 7, 2019
test Initial release Mar 7, 2019
.gitignore
CONTRIBUTING.md Initial release Mar 7, 2019
LICENSE
ORIGINAL-LICENSE
README.md Fix import paths Mar 19, 2019
package.json Initial release Mar 7, 2019

README.md

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

You can’t perform that action at this time.