array-table-kit
v0.2.3
Published
Convert arrays of objects into clean Markdown and HTML tables.
Maintainers
Readme
array-table-kit
Convert arrays of objects into clean Markdown and HTML tables.
array-table-kit is a small TypeScript utility for reports, README generation, admin exports, docs tooling and static sites. It has no runtime dependencies and works without a frontend framework.
Demo: packages.wasta-wocket.fr/array-table-kit/
Package quality
- TypeScript types are generated from the source.
- ESM-only package with no runtime dependencies.
- Marked as side-effect free for bundlers.
- Tested on Node.js 20 and 22 with GitHub Actions.
- Works in Node.js, docs tooling and static site pipelines.
Install
npm install array-table-kitMarkdown
import { arrayToMarkdownTable } from 'array-table-kit';
const rows = [
{ name: 'Ada', role: 'Engineer', stats: { score: 98 } },
{ name: 'Grace', role: 'Admiral', stats: { score: 94 } }
];
console.log(arrayToMarkdownTable(rows));| name | role | stats.score |
| ----- | -------- | ----------- |
| Ada | Engineer | 98 |
| Grace | Admiral | 94 |HTML
import { arrayToHtmlTable } from 'array-table-kit';
const html = arrayToHtmlTable(rows, {
tableClassName: 'data-table',
caption: 'Team'
});String values are escaped before rendering HTML.
Ecosystem recipes
array-table-kit is useful after parsing or extracting rows from other data sources.
Convert terminal output to Markdown:
import { arrayToMarkdownTable } from 'array-table-kit';
import { parseTerminalTable } from 'terminal-table-kit';
const rows = parseTerminalTable(kubectlOutput, {
keyStyle: 'camel'
});
const markdown = arrayToMarkdownTable(rows);Use object-path-kit when user-provided paths need bracket notation or validation:
import { getPath } from 'object-path-kit';
const cityPath = 'customer["billing.address"].city';
arrayToMarkdownTable(rows, {
columns: [
{
key: 'city',
header: 'City',
accessor: (row) => getPath(row, cityPath, '') as string
}
]
});Use object-key-paths to discover fields from an unknown object and then render a quick path inventory:
import { arrayToMarkdownTable } from 'array-table-kit';
import { getPathEntries } from 'object-key-paths';
const markdown = arrayToMarkdownTable(getPathEntries(payload), {
columns: [
{ key: 'path', header: 'Path' },
{ key: 'depth', header: 'Depth', align: 'right' },
{ key: 'isLeaf', header: 'Leaf' }
]
});Use json-csv-kit when the same rows need a downloadable CSV export:
import { arrayToMarkdownTable } from 'array-table-kit';
import { jsonToCsv } from 'json-csv-kit';
const markdown = arrayToMarkdownTable(rows);
const csv = jsonToCsv(rows);Columns
arrayToMarkdownTable(rows, {
columns: [
{ key: 'name', header: 'Name' },
{ key: 'stats.score', header: 'Score', align: 'right' }
]
});Use path when you want a stable column id that differs from the source field:
arrayToMarkdownTable(rows, {
columns: [
{ key: 'score', path: 'stats.score', header: 'Score', align: 'right' }
]
});Computed columns can use accessor:
arrayToMarkdownTable(rows, {
columns: [
{ key: 'name' },
{
key: 'summary',
header: 'Summary',
accessor: (row) => `${row.name} scored ${row.stats.score}`
}
]
});Primitive arrays are supported and render as a value column:
arrayToMarkdownTable(['one', 'two']);Readonly arrays and as const data are accepted by the TypeScript API, which keeps fixtures and generated data easy to pass directly.
Options
| Option | Default | Description |
| ------ | ------- | ----------- |
| columns | auto-discovered | Explicit column keys or column definitions. |
| emptyValue | '' | Text for null, undefined and invalid dates. |
| flatten | true | Flatten nested objects into dot-path columns. |
| formatHeader | none | Format auto-discovered column labels. |
| formatValue | none | Format every cell value before rendering. |
| maxDepth | 6 | Maximum depth for object flattening. |
| sortColumns | false | Sort auto-discovered columns alphabetically. |
CLI
array-table-kit data.json
array-table-kit data.json --html
array-table-kit data.json --format=htmlThe CLI expects a top-level JSON array. Primitive array items are wrapped in a value column.
Why
array-to-table is useful but old and focused on simple Markdown output. array-table-kit keeps the tiny utility spirit while adding TypeScript types, HTML output, safer escaping, nested object flattening, explicit columns and a small CLI.
License
MPL-2.0
