You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

easy-table

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-table

Nice text table for the CLI

1.2.0
latest
Source
npm
Version published
Weekly downloads
2.5M
-16.45%
Maintainers
1
Weekly downloads
 
Created

What is easy-table?

The easy-table npm package is a simple and flexible library for creating and formatting text tables in Node.js. It allows you to easily create tables, format columns, and perform various operations on table data.

What are easy-table's main functionalities?

Creating a Simple Table

This feature allows you to create a simple table from an array of objects. Each object represents a row in the table, and the properties of the objects are the columns.

const Table = require('easy-table');

let data = [
  { name: 'John', age: 25, city: 'New York' },
  { name: 'Jane', age: 30, city: 'San Francisco' },
  { name: 'Mike', age: 27, city: 'Chicago' }
];

let t = new Table;
data.forEach(function(person) {
  t.cell('Name', person.name);
  t.cell('Age', person.age);
  t.cell('City', person.city);
  t.newRow();
});

console.log(t.toString());

Formatting Columns

This feature allows you to format columns in the table. In this example, the 'Age' column is formatted as a number with no decimal places.

const Table = require('easy-table');

let data = [
  { name: 'John', age: 25, city: 'New York' },
  { name: 'Jane', age: 30, city: 'San Francisco' },
  { name: 'Mike', age: 27, city: 'Chicago' }
];

let t = new Table;
data.forEach(function(person) {
  t.cell('Name', person.name);
  t.cell('Age', person.age, Table.number(0));
  t.cell('City', person.city);
  t.newRow();
});

console.log(t.toString());

Sorting Rows

This feature allows you to sort the rows in the table. In this example, the rows are sorted by the 'Age' column in descending order.

const Table = require('easy-table');

let data = [
  { name: 'John', age: 25, city: 'New York' },
  { name: 'Jane', age: 30, city: 'San Francisco' },
  { name: 'Mike', age: 27, city: 'Chicago' }
];

let t = new Table;
data.forEach(function(person) {
  t.cell('Name', person.name);
  t.cell('Age', person.age);
  t.cell('City', person.city);
  t.newRow();
});

t.sort(['Age|des']);

console.log(t.toString());

Other packages similar to easy-table

Keywords

table

FAQs

Package last updated on 06 Oct 2021

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