https://github.com/helmare/climt
A NodeJs minimalist table renderer for CLI's with zero dependencies.
https://github.com/helmare/climt
Last synced: 8 months ago
JSON representation
A NodeJs minimalist table renderer for CLI's with zero dependencies.
- Host: GitHub
- URL: https://github.com/helmare/climt
- Owner: Helmare
- License: isc
- Created: 2021-10-16T14:32:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-04T19:07:11.000Z (over 2 years ago)
- Last Synced: 2024-08-11T11:58:02.545Z (almost 2 years ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/climt
- Size: 120 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `C`ommand `L`ine `I`nterface: `M`inimalist `T`ables
climt is a minimalist table renderer for CLI's with zero dependencies.
## Example
```ts
import { ClimtTable } from 'climt';
type Data = {
a?: number|null;
sub?: {
b: number
}
};
// Create table.
const table = new ClimtTable();
// Column bound to the a property
table.column('Alpha', 'a')
// Column bound to the sub.b property, with styling
table.column('Beta', 'sub.b', { align: 'right' })
// Column using a function for it's data.
table.column('Charlie', row => {
if (row.a && row.sub && row.sub.b) {
return (row.a + row.sub.b).toString();
}
});
// Formats header.
table.format((col, row, content) => {
if (row == -1) {
return content.toUpperCase();
}
else {
return content;
}
});
// Renders table with the data.
table.render([
{ a: 5, sub: { b: 5 } },
{ a: -1, sub: { b: 10 } },
{ a: 10, sub: { b: 2 } },
{ a: 15, sub: { b: -6 } },
{ a: null, sub: { b: 10 } },
{ a: 20 }
]);
```
### Outputs
```
ALPHA | BETA | CHARLIE
-------+------+---------
5 | 5 | 10
-1 | 10 | 9
10 | 2 | 12
15 | -6 | 9
| 10 |
20 | |
```