climt
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Command Line Interface: Minimalist Tables

climt is a minimalist table renderer for CLI's with zero dependencies.

Example

import { ClimtTable } from 'climt';

// 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;
  }
});

// Formats header.
table.format((content, col, row) => {
  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    |      |

Readme

Keywords

Package Sidebar

Install

npm i climt

Weekly Downloads

5

Version

0.2.0

License

ISC

Unpacked Size

24.9 kB

Total Files

7

Last publish

Collaborators

  • hazdryx
  • helmare