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

tabula

v1.10.0

Published

a light function for printing a text table to stdout

Downloads

447

Readme

A light tabula(items, options) function for printing a text table to stdout.

Why another one? I had one that worked for me and wanted to re-use it. Trawling through dozens of available ones on npm was a chore I haven't done. I'd welcome a table-printing node.js bake off.

Install

npm install tabula

Usage

var tabula = require('tabula');

var items = [
    {name: 'trent', age: 38, game: 'hockey'},
    {name: 'ewan', age: 4, game: 'chess'}
];

tabula(items);
/* prints:
NAME   AGE  GAME
trent  38   hockey
ewan   4    chess
*/

tabula(items, {columns: ['name', 'age']});
/* prints:
NAME   AGE
trent  38
ewan   4
*/

tabula(items, {
    columns: ['name', 'age'],
    skipHeader: true
});
/* prints:
trent  38
ewan   4
*/

// Sort by age. Attempts numeric sort on given fields.
// Note: This actually sorts the given `items` array in-place.
tabula(items, {
    columns: ['name', 'age'],
    sort: ['age']
});
/* prints:
NAME   AGE
ewan   4
trent  38
*/

TODO

  • document dottedLookup
  • document column align=right
  • document opts.noAnsi
  • document column width, maxWidth
  • document sort.*.keyFunc

tabula CLI

There is also a tabula CLI that can be used for emitting a table from a stream of JSON objects (or a single JSON array). E.g.:

$ echo '[{"name":"trent","age":38}, {"name":"ewan","age":4}]' | tabula
NAME   AGE
trent  38
ewan   4

# column selection
$ echo '[{"name":"trent","age":38}, {"name":"ewan","age":4}]' | tabula name
NAME
trent
ewan

# sorting
$ echo '[{"name":"trent","age":38}, {"name":"ewan","age":4}]' | tabula -s age
NAME   AGE
ewan   4
trent  38

Features

This section is an (incomplete) list and demo of some of tabula's features.

ANSI escape codes

tabula (as of version 1.7.0) properly calculates widths for cells using ANSI escape codes for coloring. E.g. try this sample:

var tabula = require('tabula');
function red(s) {
    return '\033[31m' + s + '\033[39m';
}
tabula([
    { name: 'Trent', age: 42, job: 'Engineer' },
    { name: 'Ewan', age: red(8), job: 'Student' },
]);

TODO

  • Describe the "opinions", features and limitations of this module.

  • tabula CLI for piping in a JSON array of objects, or stream of objects.

    • streaming
    • option for skipping non-JSON lines (e.g. for bunyan logs)
    • option for non-JSON input? e.g. space separated ('json -ga foo bar' output, output from other table-emitting things, perhaps then 2-space or more separated), naive-csv
    • separate tabula-cli module?
    • test cases
  • Merge this with node-tab if reasonable. I have some PR work for it (that I haven't completed) to add some conveniences that tabulate provides. It is silly to have two table-printing libs in play.

License

MIT. See LICENSE.txt.