kv-storage-polyfill

2.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i kv-storage-polyfill

Weekly Downloads

70

Version

2.0.0

License

Apache-2.0

Unpacked Size

185 kB

Total Files

14

Last publish

Collaborators

  • developit