Skip to main content

Command Palette

Search for a command to run...

Today's npm package: cli-table3

Updated
โ€ข1 min read
P

I am developer from India currently based in Berlin, Germany.

I am very interested in Design, though I don't design ๐Ÿ˜‰ I take care of it while making my apps.

Photography, videography and having random conversation over beer are my activities of spare time. Timelapses and hyperlapses make me wonder all the time ๐Ÿ˜Š

Today's npm package is cli-table3

For CLI tools, sometimes it is need to show some tabular information.

CLI Table is to the rescue.

Here's how you can use it to generate tables. In this example, we will generate table from file stats showing size, creation time and modify time of the file.

const fs = require('fs');
const path = require('path');
const table = require('cli-table3');
const file = process.argv.slice(2);

var table = new Table({
    head: ['Size', 'Created At', 'Modified At']
  , colWidths: [100, 200, 200]
});

// process the file
const stats = fs.statSync(path.resolve(process.cwd(), file));

// table is an Array, so you can `push`, `unshift`, `splice` and friends
table.push([stats.size, stats.birthtime, stats.mtime]);

console.log(table.toString());

Stay tuned for tomorrow's package of the Day.

C

Nice one!

1
P

Thanks Catalin

More from this blog

P

Pankaj Patel - @heypankaj_

63 posts

Sharing my learnings and thoughts on Blogging, Personal Branding and Programming