Format an array of objects as text, Markdown, HTML, and more.
npm install value-format-tableimport {
valueFormatTableAsHTML,
valueFormatTableAsMarkdown,
} from "value-format-table";
const data = [
{
// ...
},
{
// ...
},
{
// ...
},
];
const formatHeader = (header) => header.toUpperCase();
const htmlTable = valueFormatTableAsHTML(data, {
formatHeader,
columns: [{ formatCell: toLink }, { formatCell: toLink }],
});
element.innerHTML = htmlTable;
const textTable = valueFormatTableAsMarkdown(data, {
formatHeader,
columns: [{ align: "right" }, { align: "right" }],
});
console.log(textTable);- valueFormatTable(array, [options]) ⇒
string Format an array of objects
- valueFormatTableAsText(array, [options]) ⇒
string Format an array of objects as text
- valueFormatTableAsMarkdown(array, [options]) ⇒
string Format an array of objects as Markdown
- valueFormatTableAsHTML(array, [options]) ⇒
string Format an array of objects as HTML
- ColumnOptions :
object Options for columns.
- ValueFormatTableOptions :
object Options for table creation. All optional.
Format an array of objects
Kind: global function
| Param | Type |
|---|---|
| array | Array.<object> |
| [options] | ValueFormatTableOptions |
Format an array of objects as text
Kind: global function
| Param | Type |
|---|---|
| array | Array.<object> |
| [options] | ValueFormatTableOptions |
Format an array of objects as Markdown
Kind: global function
| Param | Type |
|---|---|
| array | Array.<object> |
| [options] | ValueFormatTableOptions |
Format an array of objects as HTML
Kind: global function
| Param | Type |
|---|---|
| array | Array.<object> |
| [options] | ValueFormatTableOptions |
Options for columns.
Kind: global typedef Properties
| Name | Type | Default |
|---|---|---|
| [align] | string |
""left"" |
| [formatCell] | function |
|
| [formatHeader] | function |
Options for table creation. All optional.
Kind: global typedef Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [columns] | Array.<ColumnOptions> |
[] |
Options for each column. |
| [wrappings] | object |
{} |
Wrappings string for each cells in the form [start, end, lastEnd]. |
| [dividers] | object |
{} |
Dividers for top, middle and bottom of the table. |
| [minCellSize] | number |
1 |
Minimum cell size. |
| [dividerPadding] | string |
"" "" |
Which string to add around dividers cells. |
| [headers] | string |
"" "" |
Filter specific keys. |
| [formatHeader] | function |
||
| [formatDivider] | function |
MIT. See license file.
