blob: b8f6191153ba98982661e7b7fae103974bcc0417 [file] [log] [blame]
swissChiliab615d82024-03-08 17:15:13 -05001const units = require("./units.js");
2
3units().then((Module) => {
4 let _do_a_conversion = Module.cwrap("do_a_conversion", "number", [
5 "number",
6 "number",
7 ]);
8
9 async function convert(from, to = "") {
10 let from_c = Module.stringToNewUTF8(from);
11 let to_c = Module.stringToNewUTF8(to);
12 let lenBefore = globalThis.printBuffer.length;
13 _do_a_conversion(from_c, to === "" ? 0 : to_c);
14 return globalThis.printBuffer.slice(lenBefore).trim();
15 }
16
17 window.convert = convert;
18});