Socket
Socket
Sign inDemoInstall

markdown-table

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-table

Markdown/ASCII tables


Version published
Weekly downloads
3.3M
decreased by-23.45%
Maintainers
1
Install size
12.7 kB
Created
Weekly downloads
 

Package description

What is markdown-table?

The markdown-table npm package is a utility for generating tables in Markdown format. It allows users to create well-formatted Markdown tables from arrays of data, providing options to customize alignment and padding.

What are markdown-table's main functionalities?

Basic Table Creation

This feature allows the creation of a basic Markdown table from an array of arrays. Each sub-array represents a row in the table.

const markdownTable = require('markdown-table');

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

console.log(table);

Custom Alignment

This feature enables the specification of alignment for each column in the table. 'l' stands for left, 'c' for center, and 'r' for right.

const markdownTable = require('markdown-table');

const table = markdownTable(
  [
    ['Feature', 'Support'],
    ['Tables', 'Yes'],
    ['Alignment', 'Yes']
  ],
  { align: ['l', 'c'] }
);

console.log(table);

Other packages similar to markdown-table

Readme

Source

markdown-table Build Status Coverage Status

Generate fancy Markdown/ASCII tables.

Installation

npm:

$ npm install markdown-table

Component.js:

$ component install wooorm/markdown-table

Bower:

$ bower install markdown-table

Duo:

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

Usage

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

/**
 * Normal usage (defaults to left-alignment):
 */

table([
    ['Branch', 'Commit'],
    ['master', '0123456789abcdef'],
    ['staging', 'fedcba9876543210']
]);
/*
 * | 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']
});
/*
 * | 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': '.'
});
/*
 * |    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.

The following options are available:

  • options.align — String or array of strings, the strings being either "l" (left), "r" (right), c (center), or . (dot). Other values are treated as "l". Only the lowercased first character is used, so Right is fine;
  • options.delimiter — Value to insert between cells. Carefull, non-pipe values will break GitHub Flavored Markdown;
  • options.start — Value to insert at the beginning of every row.
  • options.end — Value to insert at the end of every row.
  • options.rule — Whether to display a rule between the header and the body of the table. Carefull, will break GitHub Flavored Markdown when false;
  • options.stringLength — The method to detect the length of a cell (see below).

options.stringLength(cell)

ANSI-sequences mess up table creation. 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;
}

See the tests for an example.

Inspiration

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

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 22 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc