1. text-table
borderless text tables with alignment
text-table
Package: text-table
Created by: substack
Last modified: Wed, 08 Mar 2023 01:53:50 GMT
Version: 0.2.0
License: MIT
Downloads: 135,147,355
Repository: https://github.com/substack/text-table

Install

npm install text-table
yarn add text-table

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code