npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@perkjs/text-table

v1.3.0

Published

borderless text tables with alignment

Downloads

4

Readme

text-table

This is an optimized version of text-table

generate borderless text table strings suitable for printing to stdout

Install

With npm do:

npm install @perkjs/text-table

Benchmark

Original text-table x 197,473 ops/sec ±2.14% (85 runs sampled)
@perkjs/text-table v1.3.0 x 367,456 ops/sec ±2.16% (86 runs sampled)
@perkjs/text-table v1.2.1 x 347,403 ops/sec ±1.69% (80 runs sampled)
@perkjs/text-table v1.2.0 x 330,972 ops/sec ±10.60% (81 runs sampled)
@perkjs/text-table v1.1.0 x 289,422 ops/sec ±1.97% (85 runs sampled)
@perkjs/text-table v1.0.0 x 209,862 ops/sec ±1.99% (81 runs sampled)

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

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