Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The cli-table npm package is a utility for rendering unicode-aided tables on the command line from your node.js scripts. It allows for easy table creation with customizable column widths, alignments, colors, and more, making it highly useful for CLI tools that need to display data in a structured format.
Basic Table Creation
This feature allows for the creation of a simple table with rows of data. The example demonstrates how to instantiate a table, add rows, and then print it to the console.
const Table = require('cli-table');
let table = new Table();
table.push(
['First row', 'Some data'],
['Second row', 'More data']
);
console.log(table.toString());
Customized Table
This feature showcases the ability to customize the table with headers and column widths. The code sample creates a table with specified headers and column widths, adds rows of data, and prints the table.
const Table = require('cli-table');
let table = new Table({
head: ['ID', 'Name', 'Age'],
colWidths: [10, 20, 10]
});
table.push(
[1, 'John Doe', 30],
[2, 'Jane Doe', 25]
);
console.log(table.toString());
Table with Colored and Aligned Text
This feature demonstrates the ability to add colored and aligned text within table cells. The example shows how to align text horizontally and vertically within cells.
const Table = require('cli-table');
let table = new Table();
table.push(
[{content: 'Left align', hAlign: 'left', vAlign: 'top'}, 'Some data'],
[{content: 'Right align', hAlign: 'right'}, 'More data']
);
console.log(table.toString());
The 'table' package provides similar functionality for creating and rendering tables in the command line. It offers a more extensive API for customization compared to cli-table, including border styles, text wrapping, and cell padding.
Ascii-table is another package for creating ASCII tables in node.js applications. It is simpler and more lightweight than cli-table, focusing on basic table creation without the extensive customization options.
This utility allows you to render unicode-aided tables on the command line from your node.js scripts.
npm install cli-table
var Table = require('cli-table');
// 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());
Optionally you can initialize rows in the constructors directly - comes in handy for smaller tables:
new Table({
rows: [
['foo', '7 minutes ago']
, ['bar', '8 minutes ago']
]
})
var Table = require('cli-table');
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-table');
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
Clone the repository with all its submodules and run:
$ make test
(The MIT License)
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 CLI
The npm package cli-table receives a total of 3,130,428 weekly downloads. As such, cli-table popularity was classified as popular.
We found that cli-table demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.