Detalhes do pacote

cli-tableau

Keymetrics5.5m2.0.1

Pretty unicode tables for the CLI

cli, colors, table

readme (leia-me)

cli tableau

Build Status

Horizontal Tables

var Table = require('cli-tableau');

var table = new Table({
    head: ['TH 1 label', 'TH 2 label'],
    colWidths: [100, 200],
    borders: false
});

table.push(
    ['First value', 'Second value'],
    ['First value', 'Second value']
);

console.log(table.toString());

Vertical Tables

var Table = require('cli-tableau');
var 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"] }
var Table = require('cli-tableau');
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());

Custom styles

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

Credits

  • Guillermo Rauch <guillermo@learnboost.com> (Guille)

changelog (log de mudanças)

Changelog

2.0.0

  • add borders: false option
  • Adapt test to mocha
  • Replace manual padding with .padEnd
  • Allow only Node 8
  • Update travis test suite
  • Upgrade chalk to 3.0.0

0.3.1 / 2014-10-22

  • fix example for new paths
  • Readme badges
  • Lighter production installs
  • Safe colors
  • In addition to 256-xterm ansi colors, handle 24-bit colors
  • set up .travis.yml

0.3.0 / 2014-02-02

  • Switch version of colors to avoid npm broken-ness
  • Handle custom colored strings correctly
  • Removing var completely as return var width caused other problems.
  • Fixing global leak of width variable.
  • Omit horizontal decoration lines if empty
  • Add a test for the the compact mode
  • Make line() return the generated string instead of appending it to ret
  • Customize the vertical cell separator separately from the right one
  • Allow newer versions of colors to be used
  • Added test for bordercolor
  • Add bordercolor in style options and enable deepcopy of options

0.2.0 / 2012-10-21

  • test: avoid module dep in tests
  • fix type bug on integer vertical table value
  • handle newlines in vertical and cross tables
  • factor out common style setting function
  • handle newlines in body cells
  • fix render bug when no header provided
  • correctly calculate width of cells with newlines
  • handles newlines in header cells
  • ability to create cross tables
  • changing table chars to ones that windows supports
  • allow empty arguments to Table constructor
  • fix headless tables containing empty first row
  • add vertical tables
  • remove reference to require.paths
  • compact style for dense tables
  • fix toString without col widths by cloning array
  • [api]: Added abiltity to strip out ANSI color escape codes when calculating cell padding

0.0.1 / 2011-01-03

Initial release

Jun 28, 2017

Fork of Automattic/cli-table

  • Merges cli-table/#83 (test in 6d5d4b) to add array method names in the data set.
  • Releases a fix on null/undefined values, cli-table/#71.
  • Lint the code using standard.
  • Use chalk instead of colors.
  • Bump version to stable 1.0.0