value-format-table
v1.0.0
Published
Format an array of objects as text, Markdown, HTML, and more.
Downloads
71
Maintainers
Readme
value-format-table
Format an array of objects as text, Markdown, HTML, and more.
Installation
npm install value-format-table
Usage
import {
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);
API
Functions
Typedefs
valueFormatTable(array, [options]) ⇒ string
Format an array of objects
Kind: global function
| Param | Type | | --------- | ---------------------------------------------------------------- | | array | Array.<object> | | [options] | ValueFormatTableOptions |
valueFormatTableAsText(array, [options]) ⇒ string
Format an array of objects as text
Kind: global function
| Param | Type | | --------- | ---------------------------------------------------------------- | | array | Array.<object> | | [options] | ValueFormatTableOptions |
valueFormatTableAsMarkdown(array, [options]) ⇒ string
Format an array of objects as Markdown
Kind: global function
| Param | Type | | --------- | ---------------------------------------------------------------- | | array | Array.<object> | | [options] | ValueFormatTableOptions |
valueFormatTableAsHTML(array, [options]) ⇒ string
Format an array of objects as HTML
Kind: global function
| Param | Type | | --------- | ---------------------------------------------------------------- | | array | Array.<object> | | [options] | ValueFormatTableOptions |
ColumnOptions : object
Options for columns.
Kind: global typedef Properties
| Name | Type | Default | | -------------- | --------------------- | ------------------------------------------- | | [align] | string | ""left"" | | [formatCell] | function | | | [formatHeader] | function | |
ValueFormatTableOptions : object
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 | | |
License
MIT. See license file.