UNPKG

1.73 kBMarkdownView Raw
1<p align="center">
2 <img src="/.github/screenshot-1.png" width="70%">
3 <br>
4 <a href="https://npm.im/cli-simple-table"><img src="https://badgen.net/npm/v/cli-simple-table"></a>
5 <a href="https://npm.im/cli-simple-table"><img src="https://badgen.net/npm/dm/cli-simple-table"></a>
6 <a href="https://packagephobia.now.sh/result?p=cli-simple-table"><img src="https://packagephobia.now.sh/badge?p=cli-simple-table"></a>
7 <br>
8 <br>
9 <i>Simple CLI table for simple people</i>
10</p>
11
12### Install
13```sh
14npm i cli-simple-table
15```
16
17### Basic usage
18```js
19const SimpleTable = require('cli-simple-table');
20const chalk = require('chalk');
21
22const table = new SimpleTable();
23
24table.header('Name', 'Emoji');
25
26table.row(chalk.red('Squid'), '🦑');
27table.row(chalk.green('Frog'), '🐸');
28table.row(chalk.yellow('Tiger'), '🐯');
29table.row(chalk.blue('Whale'), '🐳');
30table.row(chalk.magenta('Unicorn'), '🦄');
31table.row(chalk.cyan('Dolphin'), '🐬');
32table.row(chalk.white('Panda'), '🐼');
33
34console.log(table.toString());
35```
36
37
38### Alignment
39```js
40const table = new SimpleTable();
41
42table.header(
43 'Name',
44 {
45 text: 'Age',
46 align: 'right'
47 }
48);
49
50table.row('Steve', 26);
51
52console.log(table.toString());
53```
54
55
56### Max column width
57```js
58const table = new SimpleTable();
59
60table.header(
61 {
62 text: 'Long text',
63 maxWidth: 25,
64 },
65 {
66 text: 'Long long text',
67 maxWidth: 25,
68 }
69);
70
71table.row('Truncates really really long text', chalk.magenta('Colored long long text too'));
72
73console.log(table.toString());
74```
75
76
77## Options
78
79- `columnPadding` `<Number>` (`10`) - Number of characters to pad the column content with
80
81- `headerSeparator` `<Number>` (`1`) - Number of lines that separate the header from the table body