tinysearch 0.3.0

A tiny search engine for static websites
<html>

<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
</head>

<body>
  <!-- Note the usage of `type=module` here as this is an ES6 module -->
  <script type="module">
    // Use ES module import syntax to import functionality from the module
    // that we have compiled.
    //
    // Note that the `default` import is an initialization function which
    // will "boot" the module and make it ready to use. Currently browsers
    // don't support natively imported WebAssembly as an ES module, but
    // eventually the manual initialization won't be required!
    // import { search, default as init } from './tinysearch_engine.js';
    import { search, default as init } from './tinysearch_engine.js';
    window.search = search;

    async function run() {
      // First up we need to actually load the wasm file, so we use the
      // default export to inform it where the wasm file is located on the
      // server, and then we wait on the returned promise to wait for the
      // wasm to be loaded.
      //
      // Note that instead of a string here you can also pass in an instance
      // of `WebAssembly.Module` which allows you to compile your own module.
      // Also note that the promise, when resolved, yields the wasm module's
      // exports which is the same as importing the `*_bg` module in other
      // modes
      await init('./tinysearch_engine_bg.wasm');
    }

    run();
  </script>

  <script>
    // And afterwards we can use all the functionality defined in wasm.
    function doSearch() {
      let value = document.getElementById("demo").value;
      const arr = search(value, 10);
      let ul = document.getElementById("results");
      ul.innerHTML = "";

      for (i = 0; i < arr.length; i++) {
        var li = document.createElement("li");

        let elem = arr[i];
        let elemlink = document.createElement('a');
        elemlink.innerHTML = elem[0];
        elemlink.setAttribute('href', elem[1]);
        li.appendChild(elemlink);

        ul.appendChild(li);
      }
    }
  </script>

  <h2>Search:</h2>
  <input type="text" id="demo" onkeyup="doSearch()">
  <h2>Results:</h2>
  <ul id="results">
  </ul>
</body>

</html>