https://github.com/lukasbach/table-log
CLI logging utility that logs lines as vertically aligned tabular data
https://github.com/lukasbach/table-log
cli ink log logging table tabular typed typescript
Last synced: 8 months ago
JSON representation
CLI logging utility that logs lines as vertically aligned tabular data
- Host: GitHub
- URL: https://github.com/lukasbach/table-log
- Owner: lukasbach
- Created: 2021-04-30T20:47:40.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-30T20:53:36.000Z (about 5 years ago)
- Last Synced: 2025-03-17T09:50:15.045Z (over 1 year ago)
- Topics: cli, ink, log, logging, table, tabular, typed, typescript
- Language: TypeScript
- Homepage:
- Size: 589 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# `table-log`
> NPM utility tool to log lines as vertically aligned tabular data.

## Get Started
Install the tool via `yarn add table-log` or `npm i table-log --save`. Then import
the utility via
```typescript
import { CliTable } from 'table-log';
```
Then, initialize a new table with `table = CliTable.createNoBorderTable()`,
and invoke `table.log(...lines)` to log a new line. The table is automatically adjusted
whenever a new longest cell is logged.
Complete example:
```typescript
import { CliTable } from 'table-log';
const table = CliTable.createNoBorderTable({
// Optional column alignments
colAligns: ['left', 'right', 'left', 'right'],
// Optional maximum column widths
colWidths: [undefined, undefined, 35, undefined]
});
table.log('Received', 'GET', '/users/obi-wan-kenobi', '(352ms)');
table.log('Received', 'GET', '/users/vader', '(241ms)');
table.log('Received', 'POST', '/lightsabers/red/vader', '(890ms)');
table.log('Received', 'POST', '/lightsabers/blue/obi-wan-kenobi', '(937ms)');
table.log('Received', 'OPTIONS', '/lightsabers/new', '(125ms)');
table.log('Received', 'PUT', '/lightsabers/new', '(11,335ms)');
table.log('Received', 'GET', '/users/yoda', '(452ms)');
table.log('Received', 'POST', '/lightsabers/green/yoda', '(676ms)');
// There may also pass some time between renders
await new Promise(r => setTimeout(r, 2000));
table.log('Received', 'GET', '/lightsabers/green/yoda/handle/material', '(124ms)');
table.unmount();
console.log("Table unmounted!");
```
You can also create a table with a border, by invoking `CliTable.createSingleBorderTable()`
or `CliTable.createDoubleBorderTable()` instead of `CliTable.createNoBorderTable()`.

