22 lines
657 B
TypeScript
22 lines
657 B
TypeScript
/**
|
|
* Markdown building blocks of the generated French reports. Cells are
|
|
* escaped so a pipe or a newline in data never breaks a table.
|
|
*/
|
|
|
|
export function cell(value: string | number | null): string {
|
|
if (value === null) return '-'
|
|
return String(value).replace(/\|/g, '\\|').replace(/\n/g, ' ')
|
|
}
|
|
|
|
export function table(
|
|
head: string[],
|
|
rows: Array<Array<string | number | null>>,
|
|
): string {
|
|
const lines = [head, head.map(() => '---'), ...rows.map((r) => r.map(cell))]
|
|
return lines.map((line) => `| ${line.join(' | ')} |`).join('\n')
|
|
}
|
|
|
|
export function code(value: string | null): string {
|
|
return value === null ? '-' : `\`${value}\``
|
|
}
|