JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 488
  • Score
    100M100P100Q101246F
  • License MIT

Render data in a width adjustable ascii table.

Package Exports

  • ascii-data-table

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ascii-data-table) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Ascii Data Table

This module provides functionality to render tables with text borders / outlines so it can be pasted into the medium of choice.

The configuration is very limited by design, all that's configurable in the current version is the maximun width of the columns.

The API exposes only one method: run(rows, [options]) where rows is expected to be an array with an index for every row, and eaxh row is also expected to be an array with one index for every column.
All rows should have the same number of columns, and the first row is expected to be the header column with titles for each column.

[
  ['first column', 'second column'], // title row
  ['my data row 1 col 1', 'my data row 1 col 2'], // first data row
  ['my data row 2 col 1', 'my data row 2 col 2'], // second data row
]

With default max width, the above would produce:

+===================+===================+
|first column       |second column      |
+===================+===================+
|my data row 1 col 1|my data row 1 col 2|
+-------------------+-------------------+
|my data row 2 col 1|my data row 2 col 2|
+-------------------+-------------------+

Usage

Two packages are produced, one for Node.js environment and one for web browsers.

In Node.js

Usage in Node.js varies depending if the will be used within a ES2015 application or not.

In ES2015

import AsciiTable from '../src/ascii-data-table' // <- Notice we want the file from 'src' here
const items = [['x', 'y'], ['a', 'b'], ['c', 'd']]
const res = AsciiTable.run(items)

In ES 5.5

var AsciiTable = require('../lib/ascii-data-table') // <- Notice we want the file from 'lib' here
var items = [['x', 'y'], ['a', 'b'], ['c', 'd']]
var res = AsciiTable.run(items)

In web browsers

A bundle for web browsers is created and can be found in ./lib.

<script type="text/javascript" src="../lib/bundle.js"></script>
<script type="text/javascript">
  var items = [['x', 'y'], ['a', 'b'], ['c', 'd']]
  var output = AsciiTable.run(items)
  document.getElementById('my-table').innerHTML = output
  console.log(output)
</script>

Examples / Demo

In the ./examples folder there are examples for node and web browser environments.
One cool thing in the browser demo is that you can hook up a range slider to the maximun width of the columns, giving this effect:
slider-gif-demo

Testing

Run npm test to execute test in both Node.js and browser environments.
Run npm run test:watch to have tests run on file changes.