🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

tty-table

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tty-table

Node cli table

4.2.3
latest
Version published
Weekly downloads
546K
-15%
Maintainers
1
Weekly downloads
 
Created

What is tty-table?

The tty-table npm package is used to create and display tables in the terminal. It provides a simple and flexible way to format and present tabular data in a visually appealing manner.

What are tty-table's main functionalities?

Basic Table Creation

This feature allows you to create a basic table with specified headers and rows. The table is then rendered and displayed in the terminal.

const ttyTable = require('tty-table');
const header = [
  { value: 'Name', width: 30, headerColor: 'cyan' },
  { value: 'Age', width: 10, headerColor: 'cyan' }
];
const rows = [
  ['Alice', 30],
  ['Bob', 25]
];
const table = ttyTable(header, rows);
console.log(table.render());

Customizing Table Appearance

This feature allows you to customize the appearance of the table, including border style, border color, padding, alignment, and text color.

const ttyTable = require('tty-table');
const header = [
  { value: 'Name', width: 30, headerColor: 'cyan', color: 'white', align: 'left' },
  { value: 'Age', width: 10, headerColor: 'cyan', color: 'white', align: 'right' }
];
const rows = [
  ['Alice', 30],
  ['Bob', 25]
];
const options = {
  borderStyle: 'solid',
  borderColor: 'blue',
  paddingBottom: 0,
  headerAlign: 'center',
  align: 'center',
  color: 'white'
};
const table = ttyTable(header, rows, options);
console.log(table.render());

Adding Footers

This feature allows you to add footers to the table, which can be used to display summary information or totals.

const ttyTable = require('tty-table');
const header = [
  { value: 'Name', width: 30, headerColor: 'cyan' },
  { value: 'Age', width: 10, headerColor: 'cyan' }
];
const rows = [
  ['Alice', 30],
  ['Bob', 25]
];
const footer = [
  { value: 'Total', colspan: 1, align: 'right' },
  { value: '2', align: 'right' }
];
const table = ttyTable(header, rows, { footer });
console.log(table.render());

Other packages similar to tty-table

FAQs

Package last updated on 29 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts