Convert CSV data to a markdown table format for documentation.
Code
Utilitiesconst lines = csv.trim().split('\n');
const headers = lines[0].split(',').map(h => h.trim());
const separator = headers.map(() => '---');
const rows = lines.slice(1).map(line => line.split(',').map(c => c.trim()));
const formatRow = cells => `| ${cells.join(' | ')} |`;
return [
formatRow(headers),
formatRow(separator),
...rows.map(formatRow)
].join('\n');Parameters
CSV string with headers in first row.
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Format Bytes (IEC)
Format bytes using IEC units (KiB, MiB, GiB) based on powers of 1024.
Format Credit Card
Format a credit card number with spaces every four digits.
Format File Size
Format bytes to a human readable file size with appropriate units.
Format List
Format an array as a human-readable list with 'and' or 'or' conjunctions.
Format Number Compact
Format a number in compact notation like 1K, 1M, or 1B.
Format Ordinal
Convert a number to its ordinal form (1st, 2nd, 3rd, etc.).