Simple JavaScript CSV to Markdown Table Converter
You can see it in action and play with the Live Example.
Requires no external libraries. Works in Node as well as in the browser.
npm install csv-to-markdown-table
This package also includes a CLI tool. You can install it globally with:
npm install -g csv-to-markdown-table
Then you can use it like so:
$ csv-to-markdown-table --help
Usage: csv-to-markdown-table [options]
// … help output
$ csv-to-markdown-table --delimiter ',' --headers < example.csv
| cats | dogs | fish |
|------|------|------|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
$ csv-to-markdown-table
Reading from stdin... (press Ctrl+D at the start of a line to finish)
CSV Delimiter: \t (tab) Headers: false
[interactive input]
console.log(
csvToMarkdown( "header1,header2,header3\nValue1,Value2,Value3", ",", true)
);
const csvToMarkdown = require("csv-to-markdown-table");
console.log(
csvToMarkdown("header1,header2,header3\nValue1,Value2,Value3", ",", true)
);
import csvToMarkdown from "csv-to-markdown-table";
console.log(
csvToMarkdown("header1,header2,header3\nValue1,Value2,Value3", ",", true)
);
| header1 | header2 | header3 |
|---------|---------|---------|
| Value1 | Value2 | Value3 |
Which displays in markdown as:
header1 | header2 | header3 |
---|---|---|
Value1 | Value2 | Value3 |