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
|
14 | npm i cli-simple-table
|
15 | ```
|
16 |
|
17 | ### Basic usage
|
18 | ```js
|
19 | const SimpleTable = require('cli-simple-table');
|
20 | const chalk = require('chalk');
|
21 |
|
22 | const table = new SimpleTable();
|
23 |
|
24 | table.header('Name', 'Emoji');
|
25 |
|
26 | table.row(chalk.red('Squid'), '🦑');
|
27 | table.row(chalk.green('Frog'), '🐸');
|
28 | table.row(chalk.yellow('Tiger'), '🐯');
|
29 | table.row(chalk.blue('Whale'), '🐳');
|
30 | table.row(chalk.magenta('Unicorn'), '🦄');
|
31 | table.row(chalk.cyan('Dolphin'), '🐬');
|
32 | table.row(chalk.white('Panda'), '🐼');
|
33 |
|
34 | console.log(table.toString());
|
35 | ```
|
36 |
|
37 |
|
38 | ### Alignment
|
39 | ```js
|
40 | const table = new SimpleTable();
|
41 |
|
42 | table.header(
|
43 | 'Name',
|
44 | {
|
45 | text: 'Age',
|
46 | align: 'right'
|
47 | }
|
48 | );
|
49 |
|
50 | table.row('Steve', 26);
|
51 |
|
52 | console.log(table.toString());
|
53 | ```
|
54 |
|
55 |
|
56 | ### Max column width
|
57 | ```js
|
58 | const table = new SimpleTable();
|
59 |
|
60 | table.header(
|
61 | {
|
62 | text: 'Long text',
|
63 | maxWidth: 25,
|
64 | },
|
65 | {
|
66 | text: 'Long long text',
|
67 | maxWidth: 25,
|
68 | }
|
69 | );
|
70 |
|
71 | table.row('Truncates really really long text', chalk.magenta('Colored long long text too'));
|
72 |
|
73 | console.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
|