text-table
borderless text tables with alignment
Last updated 6 years ago by substack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install text-table 
SYNC missed versions from official npm registry.

text-table

generate borderless text table strings suitable for printing to stdout

build status

example

default align

var table = require('text-table');
var t = table([
    [ 'master', '0123456789abcdef' ],
    [ 'staging', 'fedcba9876543210' ]
]);
console.log(t);
master   0123456789abcdef
staging  fedcba9876543210

left-right align

var table = require('text-table');
var t = table([
    [ 'beep', '1024' ],
    [ 'boop', '33450' ],
    [ 'foo', '1006' ],
    [ 'bar', '45' ]
], { align: [ 'l', 'r' ] });
console.log(t);
beep   1024
boop  33450
foo    1006
bar      45

dotted align

var table = require('text-table');
var t = table([
    [ 'beep', '1024' ],
    [ 'boop', '334.212' ],
    [ 'foo', '1006' ],
    [ 'bar', '45.6' ],
    [ 'baz', '123.' ]
], { align: [ 'l', '.' ] });
console.log(t);
beep  1024
boop   334.212
foo   1006
bar     45.6
baz    123.

centered

var table = require('text-table');
var t = table([
    [ 'beep', '1024', 'xyz' ],
    [ 'boop', '3388450', 'tuv' ],
    [ 'foo', '10106', 'qrstuv' ],
    [ 'bar', '45', 'lmno' ]
], { align: [ 'l', 'c', 'l' ] });
console.log(t);
beep    1024   xyz
boop  3388450  tuv
foo    10106   qrstuv
bar      45    lmno

methods

var table = require('text-table')

var s = table(rows, opts={})

Return a formatted table string s from an array of rows and some options opts.

rows should be an array of arrays containing strings, numbers, or other printable values.

options can be:

  • opts.hsep - separator to use between columns, default ' '
  • opts.align - array of alignment types for each column, default ['l','l',...]

alignment types are:

  • 'l' - left
  • 'r' - right
  • 'c' - center
  • '.' - decimal

install

With npm do:

npm install text-table

license

MIT

Current Tags

  • 0.2.0                                ...           latest (6 years ago)

5 Versions

  • 0.2.0                                ...           6 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
  • 0.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 8,128
This Week 69,107
This Month 157,397
Last Day 15,202
Last Week 84,241
Last Month 354,164
Dependencies (0)
None
Dev Dependencies (3)
Dependents (775)

Copyright 2014 - 2016 © taobao.org |