Creating a ASCII Table in Javascript

I want to share a small javascript module available in the NPM registry. It will help you to generate simple Tables using ASCII from a bi-dimensional array!

| ID | Price | Amount | Column D | Column E | |————|——————————|—————————|—————————————————————————————|———————————| | 1 | $ 100.00 | 0 | Very long text on this cell | 1 | | 2 | $ 100.00 | 10 | Left aligned | 123 | | 3 | $ 100.00 | 100 | Centered | 12345 | | 4 | $ 100.00 | 1000 | Right aligned | 123456789 |

var m = [
    ['ID', '^Price', '^Amount', '^Column D', '^Column E'], //header
    null, //horizontal line
    ['1', '$ 100.00', '0', 'Very long text on this cell', '^1'],
    ['2', '$ 100.00', '10', 'Right aligned', '123456789'],
];

var table = matrixToAsciiTable(m);

We used it at our company internaly to post messages to a Slack channel using a bot written in NodeJS. It can also be useful for logging data to a terminal. If you find any other use for it, I would be very happy to hear.

image

Get it from NPM using: npm install asciitable.js

Check it out on GitHub

May 13th, 2017 11:11pm Javascript NPM GitHub