Add stuff for blog post
diff --git a/units-impl-wasm.js b/units-impl-wasm.js
index 105f51e..6b10f29 100644
--- a/units-impl-wasm.js
+++ b/units-impl-wasm.js
@@ -1,26 +1,30 @@
const units = require("./units.lib.js");
-globalThis.printBuffer = "";
+export function setupUnits() {
+ globalThis.printBuffer = "";
-units({
- "print": function(out) {
- globalThis.printBuffer += out + "\n";
- }
-}).then((Module) => {
- let _do_a_conversion = Module.cwrap("do_a_conversion", "number", [
- "number",
- "number",
- "number",
- ]);
+ window.convertPromise = units({
+ "print": function(out) {
+ globalThis.printBuffer += out + "\n";
+ }
+ }).then((Module) => {
+ let _do_a_conversion = Module.cwrap("do_a_conversion", "number", [
+ "number",
+ "number",
+ "number",
+ ]);
- async function convert(from, to = "", system="si") {
- let from_c = Module.stringToNewUTF8(from);
- let to_c = Module.stringToNewUTF8(to);
- let sys_c = Module.stringToNewUTF8(system);
- let lenBefore = globalThis.printBuffer.length;
- _do_a_conversion(from_c, to === "" ? 0 : to_c, system);
- return globalThis.printBuffer.slice(lenBefore).trim();
- }
+ async function convert(from, to = "", system="si") {
+ let from_c = Module.stringToNewUTF8(from);
+ let to_c = Module.stringToNewUTF8(to);
+ let sys_c = Module.stringToNewUTF8(system);
+ let lenBefore = globalThis.printBuffer.length;
+ _do_a_conversion(from_c, to === "" ? 0 : to_c, system);
+ return globalThis.printBuffer.slice(lenBefore).trim();
+ }
- window.convert = convert;
+ window.convert = convert;
+
+ return convert;
});
+}