Code Monkey home page Code Monkey logo

asciitable's Introduction

asciitable

Render tables in text for tabular terminal fun times!

Overview

asciitable is the result of me extracting some code from another project. It can render simple tables with headings and pretty hyphen/pipe character-based formatting.

Installation

Available via npm:

$ npm install asciitable

Or via git:

$ git clone git://github.com/deoxxa/asciitable.git node_modules/asciitable

API

asciitable

Generates a table! Easy as pie!

var table = asciitable(options, data);

// OR

var table = asciitable(data, options);

// OR

var table = asciitable(data);
// basic table
var table = asciitable([
  {a: "a", b: "b", c: "c"},
  {a: "asddsfa", b: "sss", c: "zxc"},
  {a: "dsgvdgsdvgssdf", b: "x", c: "eryty"},
  {a: "m", b: "n", c: "o", d: "p"},
]);

console.log(table);

// pretty table
var table = asciitable([
  {a: "a", b: "b", c: "c"},
  {a: "asddsfa", b: "sss", c: "zxc"},
  {a: "dsgvdgsdvgssdf", b: "x", c: "eryty"},
  {a: "m", b: "n", c: "o", d: "p"},
], {
  skinny: true,
  intersectionCharacter: "@",
});

Arguments

  • options - an object specifying some things about the table you want generated. Options are optional.
  • data - an array of objects.

Options

  • fields - an array of field names you want to display. If omitted, asciitable will try to figure out what all the fields are for all the objects in the data array.
  • intersectionCharacter - changes what character to use at points where lines intersect. The default is "-".
  • skinny - trims the "hanging" characters used in the layout. Saves you two horizontal characters!

Example

Also see example.js.

var asciitable = require("asciitable");

var options = {
  skinny: true,
  intersectionCharacter: "x",
  columns: [
    {field: "ab", name: "First"},
    {field: "b",  name: "Second"},
    {field: "c",  name: "Third"},
    {field: "de", name: "Fourth"},
  ],
};

var table = asciitable(options, [
  {ab: "a",              b: "b",   c: "c"            },
  {ab: "asddsfa",        b: "sss", c: "zxc"          },
  {ab: "dsgvdgsdvgssdf", b: "x",   c: "eryty"        },
  {ab: "m",              b: "n",   c: "o",    de: "p"},
  {ab: 5,                b: null,  c: {},     de: [] },
  {ab: function(){}},
]);

console.log(table);

Output:

x----------------x--------x-----------------x--------x
| First          | Second | Third           | Fourth |
x----------------x--------x-----------------x--------x
| a              | b      | c               |        |
| asddsfa        | sss    | zxc             |        |
| dsgvdgsdvgssdf | x      | eryty           |        |
| m              | n      | o               | p      |
| 5              | null   | [object Object] |        |
| function (){}  |        |                 |        |
x----------------x--------x-----------------x--------x

License

3-clause BSD. A copy is included with the source.

Contact

asciitable's People

Contributors

deoxxa avatar redchair123 avatar session-zz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

asciitable's Issues

Add option to remove hanging dashes

Some option that would remove the hanging dashes, like:

------------------------------------------------------
| First          | Second | Third           | Fourth |
------------------------------------------------------
| a              | b      | c               |        |
| asddsfa        | sss    | zxc             |        |
| dsgvdgsdvgssdf | x      | eryty           |        |
| m              | n      | o               | p      |
| 5              | null   | [object Object] |        |
| function (){}  |        |                 |        |
------------------------------------------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.