INNER CODE UNIT · JavaScript

Promise

linxidnju/OpenTag · src/cli.js:233

  return new Promise((resolve) => {
    const child = spawn(process.platform === "win32" ? "where" : "command", process.platform === "win32" ? [command] : ["-v", command], {
      shell: process.platform !== "win32",
      stdio: "ignore"
    });
    child.on("close", (code) => resolve(code === 0));
    child.on("error", () => resolve(false));
  });
}

function printTable(rows) {
  if (!rows.length) {
    console.log("(none)");
    return;
  }
  const headers = Object.keys(rows[0]);
  const widths = headers.map((header) => Math.max(header.length, ...rows.map((row) => String(row[header] ?? "").length)));
  console.log(headers.map((header, i) => header.padEnd(widths[i])).join("  "));

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…