tty-table is a versatile JavaScript library designed to render tabular data in various environments, including Node.js command-line interfaces, web browsers, and browser developer consoles. Currently at stable version 5.0.0, the library sees moderate release activity, with recent updates focusing on bug fixes and dependency management. Its key differentiators include extensive configuration options for headers, columns, and data rows, supporting custom formatters for cell values, and the ability to handle both static datasets and streaming data in terminal applications. Unlike some CLI table libraries, tty-table provides a unified API for both terminal and browser rendering, offering flexibility for developers building multi-platform tools or debugging in the browser console.
npm install tty-tableVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a basic table with custom headers, data (both array of arrays and array of objects), and rendering it to the console with styling and a custom formatter.
Ensure all `width` properties in your header configuration are explicitly defined as integers. Review layouts that might have implicitly relied on floating-point width calculations.
Use a traditional `function` declaration (`function(cellValue, ...){...}`) for `formatter` callbacks if you need to access `this` context for methods like `this.configure()` or `this.resetStyle()`.Use `const Table = require('tty-table');` for CommonJS environments or `import { Table } from 'tty-table';` for ES Modules.Rewrite the `formatter` function using a traditional `function` keyword to ensure `this` context is correctly bound by `tty-table`:
```javascript
{
value: "Column",
formatter: function(cellValue, columnIndex, rowIndex, rowData, inputData) {
this.configure({ truncate: false }); // 'this' will now work
return cellValue;
}
}
```No dependency data recorded yet.