Advertisement
lignite0

ROBO24 - Markdown table generator

Oct 22nd, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import fs from "fs";
  2. import util from "util";
  3.  
  4. const readFile = util.promisify(fs.readFile);
  5.  
  6. const writer = process.stdout;
  7.  
  8. (async function generateMarkdownBinaryTable() {
  9.     const buffer = await readFile("chunk.txt");
  10.     const data = buffer.toString();
  11.     const blocks = data.trim().split("---");
  12.     for (let block of blocks) {
  13.         const lines = block.trim().split("\n");
  14.         let offset = 0;
  15.         writer.write(`| Offset | Size | Type | Field | Description |\n`);
  16.         writer.write(`|--------|------|------|-------|-------------|\n`);
  17.         for (let line of lines) {
  18.             const segments = line.split(";");
  19.             let [enableOffset, expression, type, description] = segments;
  20.             const rowOffset = enableOffset === "0" ? "dynamic" : "0x" + offset.toString(16).padStart(5, "0");
  21.             const byteSize = eval(expression);
  22.             type = type ? type.trim() : "";
  23.             description = description ? description.trim() : "";
  24.             writer.write(`|${rowOffset}|${byteSize}|${type}|${description}|\n`);
  25.             offset += parseInt(byteSize);
  26.         }
  27.         writer.write(`\n`);
  28.     }
  29. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement