Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
markdown-table
Advanced tools
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.
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);
The 'table' package also allows for the creation of text-based tables, which can be used in Markdown. It offers more extensive customization options such as border styles and cell content wrapping, making it more versatile than markdown-table for complex table layouts.
Similar to 'table', cli-table3 is designed for creating Unicode-aided tables in the command line interface but can also be used to generate Markdown-compatible tables. It provides additional features like custom header styles and column width control, offering more detailed customization compared to markdown-table.
Generate fancy Markdown/ASCII tables.
npm:
npm install markdown-table
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 |
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;
}
The original idea and basic implementation was inspired by James Halliday's text-table library.
FAQs
Generate a markdown (GFM) table
The npm package markdown-table receives a total of 4,620,018 weekly downloads. As such, markdown-table popularity was classified as popular.
We found that markdown-table demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.