Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | type Table<Columns extends string> = {
rows: Array<Record<Columns, string>>;
};
/**
* Creates a markdown table block.
* @param rows - An array of objects representing the rows of the table.
* @returns A markdown table string.
* @example
* ```typescript
* table<'email' | 'description'>({
* rows: [
* {
* email: 'test@example.com',
* description: 'test email used in service',
* },
* ],
* });
* ```
*/
export const table = <Columns extends string>({ rows }: Table<Columns>) => {
const columns = Object.keys(rows[0]) as Columns[];
return [
`| ${columns.map((header) => header.toUpperCase()).join(' | ')} |`,
`| ${columns.map(() => '---').join(' | ')} |`,
...rows.map(
(row) => `| ${columns.map((header) => row[header]).join(' | ')} |`,
),
].join('\n');
};
|