swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 1 | const units = require("./units.js"); |
| 2 | |
| 3 | units().then((Module) => { |
| 4 | let _do_a_conversion = Module.cwrap("do_a_conversion", "number", [ |
| 5 | "number", |
| 6 | "number", |
swissChili | 4f0a0a8 | 2024-03-08 18:58:38 -0500 | [diff] [blame^] | 7 | "number", |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 8 | ]); |
| 9 | |
swissChili | 4f0a0a8 | 2024-03-08 18:58:38 -0500 | [diff] [blame^] | 10 | async function convert(from, to = "", system="si") { |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 11 | let from_c = Module.stringToNewUTF8(from); |
| 12 | let to_c = Module.stringToNewUTF8(to); |
swissChili | 4f0a0a8 | 2024-03-08 18:58:38 -0500 | [diff] [blame^] | 13 | let sys_c = Module.stringToNewUTF8(system); |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 14 | let lenBefore = globalThis.printBuffer.length; |
swissChili | 4f0a0a8 | 2024-03-08 18:58:38 -0500 | [diff] [blame^] | 15 | _do_a_conversion(from_c, to === "" ? 0 : to_c, system); |
swissChili | ab615d8 | 2024-03-08 17:15:13 -0500 | [diff] [blame] | 16 | return globalThis.printBuffer.slice(lenBefore).trim(); |
| 17 | } |
| 18 | |
| 19 | window.convert = convert; |
| 20 | }); |