csv-to-md-table Convert CSV to GitHub-flavored Markdown table
Examples
Convert CSV to a GitHub-flavored Markdown table
Usage
"name,role,city
Alice,admin,Paris
Bob,editor,London" | csv-to-md-table Create a Markdown table for a GitHub README or PR
Usage
"Feature,Status,Owner
Auth,Done,Alice
Dashboard,In Progress,B..." | csv-to-md-table Format comparison data as a Markdown table for a blog post
Usage
"Tool,Category,Use Case
slugify,Text,URL generation
json-form..." | csv-to-md-table View source
(input)=>{
const lines = input.trim().split("\n");
if (!lines.length) return "";
const delim = lines[0].includes("\t") ? "\t" : ",";
const rows = lines.map((l)=>l.split(delim).map((c)=>c.trim()));
const fmt = (row)=>`| ${row.join(" | ")} |`;
const sep = `| ${rows[0].map(()=>"---").join(" | ")} |`;
return [
fmt(rows[0]),
sep,
...rows.slice(1).map(fmt)
].join("\n");
}