Socket
Socket
Sign inDemoInstall

text-table

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

text-table

borderless text tables with alignment


Version published
Maintainers
1
Weekly downloads
29,956,568
decreased by-7.92%

Weekly downloads

Package description

What is text-table?

The text-table npm package is a utility for formatting data into a table-like structure using plain text. It is useful for creating simple, readable tables in console applications or for formatting data in a tabular form without the need for HTML or graphical interfaces.

What are text-table's main functionalities?

Simple table creation

This feature allows you to create a simple text-based table with rows of data. Each sub-array represents a row in the table.

var table = require('text-table');
var t = table([
    ['master', '0123456789abcdef', 'Initial commit'],
    ['test', 'fedcba9876543210', 'Work in progress']
]);
console.log(t);

Alignment and padding

This feature allows you to specify alignment and padding for the columns in the table. The 'align' option takes an array of characters representing the alignment for each column ('.' for right, '-' for left). The 'hsep' option specifies a horizontal separator.

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

Other packages similar to text-table

Readme

Source

text-table

generate borderless text table strings suitable for printing to stdout

build status

browser support

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',...]
  • opts.stringLength - callback function to use when calculating the string length

alignment types are:

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

install

With npm do:

npm install text-table

Use with ANSI-colors

Since the string length of ANSI color schemes does not equal the length JavaScript sees internally it is necessary to pass the a custom string length calculator during the main function call.

See the test/ansi-colors.js file for an example.

license

MIT

Keywords

FAQs

Last updated on 05 Oct 2013

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc