]> granicus.if.org Git - nethack/commitdiff
delinting
authorAdam Powers <apowers@ato.ms>
Sun, 8 Nov 2020 00:13:14 +0000 (16:13 -0800)
committerAdam Powers <apowers@ato.ms>
Sun, 8 Nov 2020 00:13:14 +0000 (16:13 -0800)
sys/libnh/npm-package/src/nethackShim.js

index e7a802c304cfe6a68cf6eb3454676487520ba88e..23c58e021afeacfef362ccd8d68fe897771afe0d 100644 (file)
@@ -6,41 +6,56 @@ let savedOnRuntimeInitialized;
 
 // starts nethack
 function nethackStart(cb, inputModule = {}) {
-    if(typeof cb !== "string" && typeof cb !== "function") throw new TypeError("expected first argument to be 'Function' or 'String' representing global callback function name");
-    if(typeof inputModule !== "object") throw new TypeError("expected second argument to be object");
+    if (typeof cb !== "string" && typeof cb !== "function") {
+        throw new TypeError("expected first argument to be 'Function' or 'String' representing global callback function name");
+    }
+
+    if (typeof inputModule !== "object") {
+        throw new TypeError("expected second argument to be object");
+    }
 
     let cbName;
-    if(typeof cb === "function") {
+    if (typeof cb === "function") {
         cbName = cb.name;
-        if (cbName === "") cbName = "__anonymousNetHackCallback";
-        if (globalThis[cbName] === undefined) globalThis[cbName] = cb;
-        else if (globalThis[cbName] !== cb) throw new Error (`'globalThis["${cbName}"]' is not the same as specified callback`);
+        if (cbName === "") {
+            cbName = "__anonymousNetHackCallback";
+        }
+
+        if (globalThis[cbName] === undefined) {
+            globalThis[cbName] = cb;
+        } else if (globalThis[cbName] !== cb) {
+            throw new Error(`'globalThis["${cbName}"]' is not the same as specified callback`);
+        }
     }
 
     /* global globalThis */
     userCallback = globalThis[cbName];
-    if(typeof userCallback !==  "function") throw new TypeError(`expected 'globalThis["${cbName}"]' to be a function`);
+    if (typeof userCallback !== "function") {
+        throw new TypeError(`expected 'globalThis["${cbName}"]' to be a function`);
+    }
     // if(userCallback.constructor.name !== "AsyncFunction") throw new TypeError(`expected 'globalThis["${cbName}"]' to be an async function`);
 
     // Emscripten Module config
     Module = inputModule;
     savedOnRuntimeInitialized = Module.onRuntimeInitialized;
-    Module.onRuntimeInitialized = function (... args) {
+    Module.onRuntimeInitialized = function(... args) {
         // after the WASM is loaded, add the shim graphics callback function
         Module.ccall(
             "shim_graphics_set_callback", // C function name
             null, // return type
             ["string"], // arg types
             [cbName], // arg values
-            {async: true} // options
+            {async: true}, // options
         );
 
         // if the user had their own onRuntimeInitialized(), call it now
-        if (savedOnRuntimeInitialized) savedOnRuntimeInitialized(... args);
+        if (savedOnRuntimeInitialized) {
+            savedOnRuntimeInitialized(... args);
+        }
     };
 
     // load and run the module
-    var factory = require(path.join(__dirname, "../build/nethack.js"));
+    let factory = require(path.join(__dirname, "../build/nethack.js"));
     factory(Module);
 }