Convert CSV to GitHub-flavored Markdown table
⟐ DataConvert CSV to GitHub Markdown table
$ echo "name,role,city
Alice,admin,Paris
Bob,editor,London" | csv-to-md-table (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");
}