Tablur pronounced "tay-bler" is a simple cli table util. It is similar to cliui with a few extra helpers. The main advantage to Tablur is that it's quick and it's written in Typescript. Typings for existing table utils isn't that great and in part the reason for this release.
$ npm install tablur
Tablur is similar in syntax to cliui if you've used it before. There's nothing complicated about it. The main difference is that Tablur is a little quicker than cliui and it's more versatile when it comes to adding sections.
const table = new Tablur({ width: 80 });
table.header('My App');
table.row('column 1', 'column 2', 'column3');
table.break(); // <-- adds an empty line break.
table.section('Sub Title'); // <-- adds a section header.
table.row('column 1', 'column 2'); // <-- 3rd col will be added as empty column.
table.footer('copyright 2018 my company');
// Render to string and return.
const result = table.toString();
// OR
// Output to specified writable stream.
table.write();
A quick note on "padding". The vertical padding is not 1 to 1. This is because it gets pretty huge when you do that. Hence verticle padding is divided by 2. This looks a little better when scaling padding. Just keep that in mind.
Name | Description | Default |
width | the width of your table. | auto |
scheme | the wrapping mode, wrap, truncate or none. | wrap |
padding | the value for padding/gutters. | 0 |
border | the border to use if any. | undefined |
borderColor | a color to style the border with. | undefined |
sizes | a number or array of numbers matching column count. | undefined |
aligns | an array of global alignment values. | undefined |
borders | a map object containing border values. | undefined |
rows | rows to initialize with just calls table.rows(rows). | [] |
The Tablur API is very simple. There are really four main methods, .row(), .header(), .footer() and .write(). In fact you'll primarily use two of those in most cases.
Adds a new row to the table.
Arguments | (...cols: (string | ITablerColumn)[]) |
Returns | Tablur |
Adds array of rows to the table.
Arguments | (...rows: (string | ITablerColumn)[][]) |
Returns | Tablur |
Adds a header to the table, optionally with overridable options or alignment. Options object should always be the last argument.
Arguments | (text: string, align?: TablerAlign) |
Arguments | (text: string, options?: ITablerOptionsBase) |
Arguments | (...cols: (string | TablerAlign | ITablerOptionsBase)[]) |
Returns | Tablur |
Adds a footer to the table, optionally with overridable options or alignment. Options object should always be the last argument.
Arguments | (text: string, align?: TablerAlign) |
Arguments | (text: string, options?: ITablerOptionsBase) |
Arguments | (...cols: (string | TablerAlign | ITablerOptionsBase)[]) |
Returns | Tablur |
Adds an empty break row to the table.
Arguments | none |
Returns | Tablur |
Creates a section header.
Arguments | (column: ITablerColumn) |
Arguments | (name: string, align: TablerAlign) |
Returns | Tablur |
Renders the table and returns string representation.
Arguments | none |
Returns | string |
Renders the table and writes to output stream.
Arguments | (wrap: string, stream?: NodeJS.WritableStream) |
Returns | void |
Clears the current rows but maintains options.
Arguments | none |
Returns | Tablur |
Clears rows and resets all options, optionally can provide new options.
Arguments | (options?: ITablerOptions) |
Returns | Tablur |
As a bonus Tablur is pretty quick also! (yes there's a typo in the name lol).
See https://origin1tech.github.io/tablur/
See CHANGE.md
See LICENSE.md
Generated using TypeDoc