Easy Table

1.2.0 · abandoned · verified Wed Apr 22

easy-table is a JavaScript utility for rendering plain text tables primarily for command-line interfaces. It allows for highly customizable table structures, including dynamic cell content formatting via 'printer' functions, column sorting with specific syntax, and aggregation features like totaling and averaging. The package is currently at version 1.2.0. Its last known activity on npm was 5 years ago, and the GitHub repository shows an 8-year inactivity period, suggesting it is in an abandoned state rather than actively maintained. It ships with TypeScript type definitions, enabling type-safe usage in modern TypeScript projects. Key differentiators include its flexible cell rendering pipeline and built-in aggregation capabilities for simple CLI reporting.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic table creation, custom cell formatting, static `Table.print` usage with options, and sorting and totaling features.

import Table from 'easy-table';

const data = [
  { id: 123123, desc: 'Something awesome', price: 1000.00 },
  { id: 245452, desc: 'Very interesting book', price: 11.45},
  { id: 232323, desc: 'Yet another product', price: 555.55 }
];

// Using instance methods for fine-grained control
let t = new Table();

data.forEach(product => {
  t.cell('Product Id', product.id);
  t.cell('Description', product.desc);
  t.cell('Price, USD', product.price, Table.number(2)); // Format price to 2 decimal places
  t.newRow();
});

console.log('Formatted Table:\n' + t.toString());

// Using the static print method for quick rendering with options
console.log('\nAuto-generated Table with options:\n' + Table.print(data, {
  desc: { name: 'Product Description' }, // Rename column
  price: { printer: Table.number(2) }     // Apply printer
}));

// Example of sorting and totaling
let sortableTable = new Table();
data.forEach(product => {
  sortableTable.cell('Product Id', product.id);
  sortableTable.cell('Description', product.desc);
  sortableTable.cell('Price, USD', product.price);
  sortableTable.newRow();
});
sortableTable.sort(['Price, USD|des']); // Sort by Price descending
sortableTable.total('Price, USD', { printer: Table.aggr.printer('Total: ', Table.number(2)) });

console.log('\nSorted and Totaled Table:\n' + sortableTable.toString());

view raw JSON →