ascii-pretty-table
ascii-pretty-table, A simple and light weight library for creating ASCII tables.
docs
Uses
Install
npm install ascii-pretty-table
Example
const ascii = require("ascii-pretty-table");
import ascii from "ascii-pretty-table";
const table = new ascii("A Title");
table.setHeading("Column 1", "Column 2");
table.addRow("Row 1", "Row 2");
table.addRow("Row 3", "Row 4");
console.log(table.toString());
Result
+....................+
| A Title |
+''''''''''''''''''''+
| Column 1 | Column 2|
+''''''''''''''''''''+
| Row 1 | Row 2 |
+''''''''''''''''''''+
| Row 3 | Row 4 |
+''''''''''''''''''''+
You can create table without headings as well.
You can export or import table as JSON.
const ascii = require("ascii-pretty-table");
const table = new ascii("A Title");
table.addRow("Row 1", "Row 2");
table.addRow("Row 3", "Row 4");
const json = table.toJSON();
const newTable = new ascii();
newTable.fromJSON(json);
Change separators
table.setSeparators({
top: ".",
bottom: "'",
edge: "|",
fill: "-",
corner: "+",
});
Methods and Properties
read docs for ascii-pretty-table