async function dataToMarkdown(data) {
if (!Array.isArray(data) || data.length < 0)
throw "Please provide an array with elements";
let markup;
const columns = Object.keys(data[0]);
const lengths = columns.map((c) =>
d3.max(
data.map((d) => (d[c] ? d[c].toString().length : 4)).concat(c.length)
)
);
markup = `| ${columns
.map((c, i) => c.padEnd(lengths[i], " "))
.join(" | ")} | `;
markup = markup.concat(
`\n| ${columns.map((c, i) => "-".repeat(lengths[i])).join(" | ")} | `
);
data.forEach(
(d) =>
(markup = markup.concat(
`\n| ${columns
.map((c, i) => (d[c] ? d[c].toString() : "null").padEnd(lengths[i]))
.join(" | ")} | `
))
);
return markup;
}