asciitable
Render tables in text for tabular terminal fun times!
Overview
asciitable is the result of me extracting some code from another project. It can
render simple tables with headings and pretty hyphen/pipe character-based
formatting.
Installation
Available via npm:
$ npm install asciitable
Or via git:
$ git clone git://github.com/deoxxa/asciitable.git node_modules/asciitable
API
asciitable
Generates a table! Easy as pie!
var table = asciitable(options, data);
var table = asciitable(data, options);
var table = asciitable(data);
var table = asciitable([
{a: "a", b: "b", c: "c"},
{a: "asddsfa", b: "sss", c: "zxc"},
{a: "dsgvdgsdvgssdf", b: "x", c: "eryty"},
{a: "m", b: "n", c: "o", d: "p"},
]);
console.log(table);
Arguments
- options - an object specifying some things about the table you want
generated. Options are optional.
- data - an array of objects.
Options
- fields - an array of field names you want to display. If omitted, asciitable
will try to figure out what all the fields are for all the objects in the data
array.
- plusIntersections - enables using a
+
character at line intersections.
Default is false. Or undefined. Whatever, default is "not enabled".
Example
Also see example.js.
var asciitable = require("asciitable");
var options = {
columns: [
{field: "ab", name: "First"},
{field: "b", name: "Second"},
{field: "c", name: "Third"},
{field: "de", name: "Fourth"},
],
};
var table = asciitable(options, [
{ab: "a", b: "b", c: "c" },
{ab: "asddsfa", b: "sss", c: "zxc" },
{ab: "dsgvdgsdvgssdf", b: "x", c: "eryty" },
{ab: "m", b: "n", c: "o", de: "p"},
{ab: 5, b: null, c: {}, de: [] },
{ab: function(){}},
]);
console.log(table);
Output:
--------------------------------------------------------
| First | Second | Third | Fourth |
--------------------------------------------------------
| a | b | c | |
| asddsfa | sss | zxc | |
| dsgvdgsdvgssdf | x | eryty | |
| m | n | o | p |
| 5 | null | [object Object] | |
| function (){} | | | |
--------------------------------------------------------
License
3-clause BSD. A copy is included with the source.
Contact