array-to-html
v0.0.14
Published
Convert an array of objects to a simple markdown table.
Downloads
155
Maintainers
Readme
Array to Html
Convert an array of objects to a simple html table, list or DOMElement.
Install
$ npm i array-to-html
Use
Array to Table
Sample
const { arrayToTable } = require('array-to-html');
// array collection
const tableArray = [
{
Name: 'Jack',
Age: 40,
},
{
Name: 'Maria',
Age: 35,
},
];
// the magic
const tableHtml = arrayToTable(tableArray);
// output
console.log(tableHtml);
Output
Options
| Options | Type | Description | |--------------------|------|----------------------------------| | minify | Boolean | Compress HTML, remove spaces and breaks | | fake_style | Boolean | Insert styles | | columns_size | Numeric Array | Percent array [25, 25, 0, 50] | | header | Array | Header property, label, width |
// array collection
const tableArray = [ ... ];
// options
const options = {
minify: true,
fake_style: true,
columns_size: [70, 30], // 70%. 30% (two columns)
header: [
{
property: 'Name',
label: 'N-A-M-E',
width: 70, // 70%
}
]
}
// the magic
const tableHtml = arrayToTable(tableArray, options);
ToDo
- Table DOMElement
- Array to List
License
The MIT License.