blob: bf562e1ef0ae14825b54f65c1428e8562cc9b901 [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",
swissChili4f0a0a82024-03-08 18:58:38 -05007 "number",
swissChiliab615d82024-03-08 17:15:13 -05008 ]);
9
swissChili4f0a0a82024-03-08 18:58:38 -050010 async function convert(from, to = "", system="si") {
swissChiliab615d82024-03-08 17:15:13 -050011 let from_c = Module.stringToNewUTF8(from);
12 let to_c = Module.stringToNewUTF8(to);
swissChili4f0a0a82024-03-08 18:58:38 -050013 let sys_c = Module.stringToNewUTF8(system);
swissChiliab615d82024-03-08 17:15:13 -050014 let lenBefore = globalThis.printBuffer.length;
swissChili4f0a0a82024-03-08 18:58:38 -050015 _do_a_conversion(from_c, to === "" ? 0 : to_c, system);
swissChiliab615d82024-03-08 17:15:13 -050016 return globalThis.printBuffer.slice(lenBefore).trim();
17 }
18
19 window.convert = convert;
20});