cli-table

WebJar for cli-table

License

License

MIT
Categories

Categories

CLI User Interface
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

cli-table
Last Version

Last Version

0.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

cli-table
WebJar for cli-table
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/Automattic/cli-table

Download cli-table

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/cli-table/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>cli-table</artifactId>
    <version>0.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/cli-table/
implementation 'org.webjars.npm:cli-table:0.3.1'
// https://jarcasting.com/artifacts/org.webjars.npm/cli-table/
implementation ("org.webjars.npm:cli-table:0.3.1")
'org.webjars.npm:cli-table:jar:0.3.1'
<dependency org="org.webjars.npm" name="cli-table" rev="0.3.1">
  <artifact name="cli-table" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='cli-table', version='0.3.1')
)
libraryDependencies += "org.webjars.npm" % "cli-table" % "0.3.1"
[org.webjars.npm/cli-table "0.3.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : colors jar 1.0.3

Project Modules

There are no modules declared in this project.

CLI Table NPM Version Build Status

This utility allows you to render unicode-aided tables on the command line from your node.js scripts.

Screenshot

Features

  • Customizable characters that constitute the table.
  • Color/background styling in the header through colors.js
  • Column width customization
  • Text truncation based on predefined widths
  • Text alignment (left, right, center)
  • Padding (left, right)
  • Easy-to-use API

Installation

npm install cli-table

How to use

Horizontal Tables

import Table from 'cli-table';

// instantiate
const 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());

Text Alignment

import Table from 'cli-table';

const table = new Table({
    colWidths: [100, 200],
    colAligns: ["left", "right"]
});

Vertical Tables

const Table = require('cli-table');
const table = new Table();

table.push(
    { 'Some key': 'Some value' }, 
    { 'Another key': 'Another value' }
);

console.log(table.toString());

Cross Tables

Cross tables are very similar to vertical tables, with two key differences:

  1. They require a head setting when instantiated that has an empty string as the first header
  2. The individual rows take the general form of { "Header": ["Row", "Values"] }
import Table from 'cli-table';
const 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());

Custom styles

The chars property controls how the table is drawn:

const 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:

const 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:

const 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

Running tests

Clone the repository with all its submodules and run:

$ make test

How to contribute

Contribution are welcome! If you spot a bug or want to request an improvement, you are encouraged to submit a PR.

  1. Keep PRs as atomic and limited in scope as possible. Will make reviewing easier and faster.
  2. Want to submit multiple fixes/improvements? Please submit one PR each.
  3. Always add tests for your PRs; this will ensure future changes won't break your code.

Credits

License

(The MIT License)

Copyright (c) 2010 LearnBoost <[email protected]>

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.

org.webjars.npm

Automattic

We are passionate about making the web a better place.

Versions

Version
0.3.1