@juparog/print-table
Version:
print-table is a simple library that allows you to print beautiful and customizable tables in the console using ANSI escape codes. It is ideal for displaying tabular data in a clear and visually appealing way.
161 lines (137 loc) ⢠8.48 kB
Markdown
# print-table
<!-- BADGES:START - Do not remove or modify this section -->
[](#contributors-) [](https://coveralls.io/github/juparog/nodejs-libs?branch=main)
<!-- BADGES:END -->
`print-table` is a simple library that allows you to print beautiful and customizable tables in the console using ANSI escape codes. It is ideal for displaying tabular data in a clear and visually appealing way.
## Installation
```bash
npm install @juparog/print-table
```
## Usage
Here is an example of how to use `print-table`:
```typescript
import { AlignmentText, BgColor, ConsoleTable, ROUNDED_BOX_THEME, TableOptions } from '@juparog/print-table';
// Define your table options
const tableOptions: TableOptions = {
columns: [
{
header: { name: 'Rule š' },
key: 'Rule',
width: 20,
bold: true,
},
{ header: 'Group š', key: 'Group', width: 25 },
{
header: 'Status š„',
key: 'Status',
width: 20,
bgColor: (value) => {
if (value === 'Succeeded') {
return BgColor.GREEN;
}
return BgColor.RED;
},
align: AlignmentText.CENTER_MIDDLE,
styleFullCell: true,
},
{
header: 'Messages š¬',
key: 'Messages',
width: 50,
truncate: false,
},
],
data: [ // Your data goes here
{
Rule: 'NAMING_STANDARD',
Group: 'Configuration management',
Status: 'Succeeded',
Messages: '',
},
{
Rule: 'DEPLOY_DEV',
Group: 'Continuous deployment',
Status: 'Succeeded',
Messages: '',
},
{
Rule: 'DEPLOY_PDN',
Group: 'Continuous deployment',
Status: 'Failed',
Messages:
'Failed configurations in stage Deploy PDN: [You need configure some task like: ROLLBACK_TASK, REST_CALL_TASK. At least one must be configured.]',
},
{
Rule: 'BUILD_TASKS',
Group: 'Continuous integration',
Status: 'Failed',
Messages:
'Failed configurations in stage Build: [Prohibited enabled value on Unit Test, it must match the expression "true".]',
},
{
Rule: 'ACCEPTANCE_TEST',
Group: 'Continuous integration',
Status: 'Failed',
Messages: 'No stages to validate',
},
],
theme: ROUNDED_BOX_THEME, // You can choose different themes for your table
};
// Create an instance of ConsoleTable
const consoleTable = new ConsoleTable(tableOptions);
// Print the table to the console
consoleTable.printTable();
```
Output of example:
```bash
$ ts-node ./index.ts
āāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā®
ā Rule š ā Group š ā Status š„ ā Messages š¬ ā
āāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā NAMING_STANDARD ā Configuration management ā Succeeded ā ā
āāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā DEPLOY_DEV ā Continuous deployment ā Succeeded ā ā
āāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā ā ā ā Failed configurations in stage Deploy PDN: [You ne ā
ā DEPLOY_PDN ā Continuous deployment ā Failed ā ed configure some task like: ROLLBACK_TASK, REST_C ā
ā ā ā ā ALL_TASK. At least one must be configured.] ā
āāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā BUILD_TASKS ā Continuous integration ā Succeeded ā ā
āāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā ACCEPTANCE_TEST ā Continuous integration ā Failed ā No stages to validate ā
ā°āāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ
```
In this example, we define a table with specific columns, data, and a theme. Customize your table's appearance by adjusting options such as column width, text alignment, background color, and more.
## Features
- Simple and intuitive API
- Customizable themes for different table styles
- Support for text alignment, background colors, and other styling options
- Easy integration with existing Node.js projects
Explore the full range of features and customization options by referring to the documentation or exploring the source code.
## License
This library is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. Feel free to use and modify it according to your needs.
We hope you find `print-table` helpful for presenting your tabular data in a visually appealing way!
## Contributors āØ
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://medium.com/@juangasca95"><img src="https://avatars.githubusercontent.com/u/58745412?v=4?s=100" width="100px;" alt="Juan Rodriguez"/><br /><sub><b>Juan Rodriguez</b></sub></a><br /><a href="https://github.com/juparog/nodejs-libs/commits?author=juparog" title="Code">š»</a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td align="center" size="13px" colspan="7">
<img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg">
<a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
</img>
</td>
</tr>
</tfoot>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->