Skip to content

dmnsgn/value-format-table

Repository files navigation

value-format-table

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Format an array of objects as text, Markdown, HTML, and more.

paypal coinbase twitter

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

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

Typedefs

ColumnOptions : object

Options for columns.

ValueFormatTableOptions : object

Options for table creation. All optional.

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 "&quot;left&quot;"
[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 "&quot; &quot;" Which string to add around dividers cells.
[headers] string "&quot; &quot;" Filter specific keys.
[formatHeader] function
[formatDivider] function

License

MIT. See license file.