Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Pretty unicode tables for the command line. Based on the original cli-table.
The cli-table3 npm package is a utility for rendering Unicode-aided tables on the command line from your node.js scripts. It is a fork of the original cli-table package and provides additional features and bug fixes. It allows for easy table creation with customizable characters for the border and columns, as well as alignment and color options for the text within the cells.
Basic Table Creation
This feature allows you to create a simple table with rows and columns. The code sample demonstrates how to instantiate a new table, add rows to it, and then print it to the console.
const Table = require('cli-table3');
const table = new Table();
table.push(
['First column', 'Second column'],
['First row', 'Second row']
);
console.log(table.toString());
Custom Table Styling
This feature allows for customization of the table's appearance. The code sample shows how to create a table with custom border characters and styles.
const Table = require('cli-table3');
const table = new Table({
style: { head: [], border: [] },
chars: {
'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right': '╝',
'left': '║', 'left-mid': '╟', 'mid': '─', 'mid-mid': '┼',
'right': '║', 'right-mid': '╢', 'middle': '│'
}
});
table.push(
['First column', 'Second column'],
['First row', 'Second row']
);
console.log(table.toString());
Column Width and Alignment
This feature allows you to specify the width and alignment of columns. The code sample demonstrates setting the width of each column and aligning the text within them.
const Table = require('cli-table3');
const table = new Table({
colWidths: [20, 30],
colAligns: ['left', 'right'],
});
table.push(
['Left aligned', 'Right aligned'],
['Longer text in the first column', 'Text in the second column']
);
console.log(table.toString());
The 'table' package is another popular choice for creating text-based tables in Node.js. It provides automatic text wrapping, spanning cells, and alignment, and is highly customizable. Compared to cli-table3, it might offer a more modern API and additional features for complex table creation.
Ascii-table is a small and simple package for creating ASCII tables. It is less feature-rich than cli-table3 but is straightforward to use for basic table needs. It lacks some of the advanced styling and customization options available in cli-table3.
Easy-table is a minimalistic package that allows for quick table generation with a focus on simplicity and performance. It doesn't have as many styling options as cli-table3 but can be a good choice for simple tabular data representation.
This utility allows you to render unicode-aided tables on the command line from your node.js scripts.
cli-table3
is based on (and api compatible with) the original cli-table,
and cli-table2, which are both
unmaintained. cli-table3
includes all the additional features from
cli-table2
.
npm install cli-table3
A portion of the unit test suite is used to generate examples:
This package is api compatible with the original cli-table. So all the original documentation still applies (copied below).
var Table = require('cli-table3');
// instantiate
var table = new Table({
head: ['TH 1 label', 'TH 2 label']
, colWidths: [100, 200]
});
// table is an Array, so you can `push`, `unshift`, `splice` and friends
table.push(
['First value', 'Second value']
, ['First value', 'Second value']
);
console.log(table.toString());
var Table = require('cli-table3');
var table = new Table();
table.push(
{ 'Some key': 'Some value' }
, { 'Another key': 'Another value' }
);
console.log(table.toString());
Cross tables are very similar to vertical tables, with two key differences:
head
setting when instantiated that has an empty string as the first headervar Table = require('cli-table3');
var table = new Table({ head: ["", "Top Header 1", "Top Header 2"] });
table.push(
{ 'Left Header 1': ['Value Row 1 Col 1', 'Value Row 1 Col 2'] }
, { 'Left Header 2': ['Value Row 2 Col 1', 'Value Row 2 Col 2'] }
);
console.log(table.toString());
The chars
property controls how the table is drawn:
var table = new Table({
chars: { 'top': '═' , 'top-mid': '╤' , 'top-left': '╔' , 'top-right': '╗'
, 'bottom': '═' , 'bottom-mid': '╧' , 'bottom-left': '╚' , 'bottom-right': '╝'
, 'left': '║' , 'left-mid': '╟' , 'mid': '─' , 'mid-mid': '┼'
, 'right': '║' , 'right-mid': '╢' , 'middle': '│' }
});
table.push(
['foo', 'bar', 'baz']
, ['frob', 'bar', 'quuz']
);
console.log(table.toString());
// Outputs:
//
//╔══════╤═════╤══════╗
//║ foo │ bar │ baz ║
//╟──────┼─────┼──────╢
//║ frob │ bar │ quuz ║
//╚══════╧═════╧══════╝
Empty decoration lines will be skipped, to avoid vertical separator rows just set the 'mid', 'left-mid', 'mid-mid', 'right-mid' to the empty string:
var table = new Table({ chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''} });
table.push(
['foo', 'bar', 'baz']
, ['frobnicate', 'bar', 'quuz']
);
console.log(table.toString());
// Outputs: (note the lack of the horizontal line between rows)
//┌────────────┬─────┬──────┐
//│ foo │ bar │ baz │
//│ frobnicate │ bar │ quuz │
//└────────────┴─────┴──────┘
By setting all chars to empty with the exception of 'middle' being set to a single space and by setting padding to zero, it's possible to get the most compact layout with no decorations:
var table = new Table({
chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': ''
, 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': ''
, 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': ''
, 'right': '' , 'right-mid': '' , 'middle': ' ' },
style: { 'padding-left': 0, 'padding-right': 0 }
});
table.push(
['foo', 'bar', 'baz']
, ['frobnicate', 'bar', 'quuz']
);
console.log(table.toString());
// Outputs:
//foo bar baz
//frobnicate bar quuz
Later versions of cli-table3 supporting debugging your table data.
Enable and use debugging:
var table = new Table({ debug: 1 });
table.push([{}, {},}); // etc.
console.log(table.toString());
table.messages.forEach((message) => console.log(message));
If you are rendering multiple tables with debugging on run Table.reset()
after
rendering each table.
Clone the repository and run yarn install
to install all its submodules, then run one of the following commands:
$ yarn test:coverage
$ yarn test:watch
$ yarn docs
(The MIT License)
Copyright (c) 2014 James Talmage <james.talmage@jrtechnical.com>
Original cli-table code/documentation: Copyright (c) 2010 LearnBoost <dev@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Pretty unicode tables for the command line. Based on the original cli-table.
The npm package cli-table3 receives a total of 14,566,139 weekly downloads. As such, cli-table3 popularity was classified as popular.
We found that cli-table3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.