@markusylisiurunen/md-table

Minimal package for creating themable tables as strings.

Stats

StarsIssuesVersionUpdatedCreatedSize
@markusylisiurunen/md-table
000.2.1-alpha4 years ago4 years agoMinified + gzip package size for @markusylisiurunen/md-table in KB

Readme

npm version npm dependencies github issues license

hero image

Features

  • 🖍 Themable using chalk.
  • 📎 Copy-pasteable to markdown files and websites.
  • 😍 Minimal and beautiful af.

Install

$ npm add @markusylisiurunen/md-table

Usage

const getTable = require('md-table');

console.log(
  getTable(
    ['Superhero', 'Real name'],
    [
      ['Batman', 'Bruce Wayne'],
      ['Spider-Man', 'Peter Parker'],
      ['Iron Man', 'Elon Musk'],
    ]
  )
);

/*
=>
| Superhero  | Real name    |
| ---------- | ------------ |
| Batman     | Bruce Wayne  |
| Spider-Man | Peter Parker |
| Iron Man   | Elon Musk    |
*/

API

getTable(header, rows, [options])

  • {Array<String>} header: An array of the table's head columns.
  • {Array<Array<String>>} rows: An array of each row of data.
  • {Object} [options]: An optional options object.
    • {Number} options.x (default: 0): Horizontal padding applied to the table.
    • {Number} options.y (default: 0): Vertical padding applied to the table.
    • {Array} options.alignRight (default: []): Column indexes to align right.
    • {Object} options.colors: An object of hex color values for theming.
      • {String} colors.head (default: ''): Header text color.
      • {String} colors.data (default: ''): Data text color.
      • {String} colors.border (default: ''): Border color.

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.