Giter VIP home page Giter VIP logo

markdown-table's Introduction

markdown-table Build Status Coverage Status

Generate fancy Markdown/ASCII tables.

Installation

npm:

npm install markdown-table

Usage

Normal usage (defaults to left-alignment):

var table = require('markdown-table');

table([
  ['Branch', 'Commit'],
  ['master', '0123456789abcdef'],
  ['staging', 'fedcba9876543210']
]);

Yields:

| Branch  | Commit           |
| ------- | ---------------- |
| master  | 0123456789abcdef |
| staging | fedcba9876543210 |

With alignment:

table([
  ['Beep', 'No.', 'Boop'],
  ['beep', '1024', 'xyz'],
  ['boop', '3388450', 'tuv'],
  ['foo', '10106', 'qrstuv'],
  ['bar', '45', 'lmno']
], {
  align: ['l', 'c', 'r']
});

Yields:

| Beep |   No.   |   Boop |
| :--- | :-----: | -----: |
| beep |   1024  |    xyz |
| boop | 3388450 |    tuv |
| foo  |  10106  | qrstuv |
| bar  |    45   |   lmno |

Alignment on dots:

table([
  ['No.'],
  ['0.1.2'],
  ['11.22.33'],
  ['5.6.'],
  ['1.22222'],
], {
  align: '.'
});

Yields:

|    No.      |
| :---------: |
|   0.1.2     |
| 11.22.33    |
|   5.6.      |
|     1.22222 |

API

markdownTable(table[, options])

Turns a given matrix of strings (an array of arrays of strings) into a table.

options
options.align

One style for all columns, or styles for their respective columns (string or Array.<string>). Each style is either 'l' (left), 'r' (right), 'c' (centre), or '.' (dot). Other values are treated as '', which doesn’t place the colon but does left align. Only the lowercased first character is used, so Right is fine.

options.delimiter

Value to insert between cells (string, default: ' | '). Careful, setting this to a non-pipe breaks GitHub Flavoured Markdown.

options.start

Value to insert at the beginning of every row (string, default: '| ').

options.end

Value to insert at the end of every row (string, default: ' |').

options.rule

Whether to display a rule between the header and the body of the table (boolean, default: true). Careful, will break GitHub Flavoured Markdown when false.

options.stringLength

Method to detect the length of a cell (Function, default: s => s.length).

ANSI-sequences mess up tables on terminals. To fix this, you have to pass in a stringLength option to detect the “visible” length of a cell.

var strip = require('strip-ansi');

function stringLength(cell) {
  return strip(cell).length;
}
options.pad

Whether to pad the markdown for table cells to make them the same width (boolean, default: true). Setting this to false will cause the table rows to remain staggered.

Inspiration

The original idea and basic implementation was inspired by James Halliday’s text-table library.

License

MIT © Titus Wormer

markdown-table's People

Contributors

wooorm avatar greenkeeperio-bot avatar alex-e-leon avatar

Watchers

 avatar

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.