Options
All
  • Public
  • Public/Protected
  • All
Menu

Tablur

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.

Install

$ npm install tablur

Usage

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();

Options

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.

NameDescriptionDefault
widththe width of your table.auto
schemethe wrapping mode, wrap, truncate or none.wrap
paddingthe value for padding/gutters.0
borderthe border to use if any.undefined
borderColora color to style the border with.undefined
sizesa number or array of numbers matching column count.undefined
alignsan array of global alignment values.undefined
bordersa map object containing border values.undefined
rowsrows to initialize with just calls table.rows(rows).[]

API

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.

row

Adds a new row to the table.

Arguments(...cols: (string | ITablerColumn)[])
ReturnsTablur

rows

Adds array of rows to the table.

Arguments(...rows: (string | ITablerColumn)[][])
ReturnsTablur

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)[])
ReturnsTablur

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)[])
ReturnsTablur

break

Adds an empty break row to the table.

Argumentsnone
ReturnsTablur

section

Creates a section header.

Arguments(column: ITablerColumn)
Arguments(name: string, align: TablerAlign)
ReturnsTablur

toString

Renders the table and returns string representation.

Argumentsnone
Returnsstring

write

Renders the table and writes to output stream.

Arguments(wrap: string, stream?: NodeJS.WritableStream)
Returnsvoid

clear

Clears the current rows but maintains options.

Argumentsnone
ReturnsTablur

reset

Clears rows and resets all options, optionally can provide new options.

Arguments(options?: ITablerOptions)
ReturnsTablur

Benchmark

As a bonus Tablur is pretty quick also! (yes there's a typo in the name lol).

Docs

See https://origin1tech.github.io/tablur/

Change

See CHANGE.md

License

See LICENSE.md

Generated using TypeDoc