JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18372240
  • Score
    100M100P100Q203308F
  • License MIT

Markdown/ASCII tables

Package Exports

  • markdown-table

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (markdown-table) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

markdown-table Build Status Coverage Status

Generate fancy Markdown/ASCII tables.

Installation

npm:

npm install markdown-table

Usage

Dependencies:

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

Normal usage (defaults to left-alignment):

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

The following options are available:

  • options.align (string or Array.<string>) — One style for all columns, or styles for their respective columns. 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 (string, default: ' | ') — Value to insert between cells. Careful, setting this to a non-pipe breaks GitHub Flavoured Markdown;
  • options.start (string, default: '| ') — Value to insert at the beginning of every row.
  • options.end (string, default: ' |') — Value to insert at the end of every row.
  • options.rule (boolean, default: true) — Whether to display a rule between the header and the body of the table. Careful, will break GitHub Flavoured Markdown when false;
  • options.stringLength (Function, default: s => s.length) — Method to detect the length of a cell (see below).

stringLength(cell)

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 chalk = require('chalk');

function stringLength(cell) {
  return chalk.stripColor(cell).length;
}

Inspiration

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

License

MIT © Titus Wormer