# tabula

> a light function for printing a text table to stdout

Latest version **1.10.0** (published 2017-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install tabula
pnpm add tabula
yarn add tabula
bun add tabula
```

Provides the command `tabula`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.10.0 |
| Published | 2017-12-22 |
| First published | 2014-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Trent Mick |
| Maintainers | trentm |
| Keywords | table, stdout, tabulate |

## Links

- npm: https://www.npmjs.com/package/tabula
- Repository: https://github.com/trentm/node-tabula
- Issues: https://github.com/trentm/node-tabula/issues
- npm.io page: https://npm.io/package/tabula

## Dependencies (3)

- [lstream](https://npm.io/package/lstream.md) 0.0.4
- [dashdash](https://npm.io/package/dashdash.md) 1.x >=1.8
- [assert-plus](https://npm.io/package/assert-plus.md) ^1.0.0

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.10.0 (latest) — 2017-12-22
- 1.9.0 — 2016-12-15
- 1.8.0 — 2016-06-06
- 1.7.0 — 2015-11-04
- 1.6.1 — 2015-09-22
- 1.6.0 — 2015-09-04
- 1.5.0 — 2015-09-04
- 1.4.2 — 2015-03-26
- 1.4.1 — 2014-11-19
- 1.4.0 — 2014-11-04
- 1.3.0 — 2014-09-03
- 1.2.2 — 2014-08-13
- 1.2.1 — 2014-06-27
- 1.2.0 — 2014-06-01
- 1.1.1 — 2014-05-30
- … 2 more at https://npm.io/package/tabula/versions

## README

A light `tabula(items, options)` function for printing a text table
to stdout.

Why another one? I had one that worked for me and wanted to re-use it. Trawling
through dozens of available ones on npm was a chore I haven't done. I'd welcome
a table-printing node.js bake off.


# Install

    npm install tabula


# Usage

```javascript
var tabula = require('tabula');

var items = [
    {name: 'trent', age: 38, game: 'hockey'},
    {name: 'ewan', age: 4, game: 'chess'}
];

tabula(items);
/* prints:
NAME   AGE  GAME
trent  38   hockey
ewan   4    chess
*/

tabula(items, {columns: ['name', 'age']});
/* prints:
NAME   AGE
trent  38
ewan   4
*/

tabula(items, {
    columns: ['name', 'age'],
    skipHeader: true
});
/* prints:
trent  38
ewan   4
*/

// Sort by age. Attempts numeric sort on given fields.
// Note: This actually sorts the given `items` array in-place.
tabula(items, {
    columns: ['name', 'age'],
    sort: ['age']
});
/* prints:
NAME   AGE
ewan   4
trent  38
*/
```

# TODO

- document dottedLookup
- document column align=right
- document opts.noAnsi
- document column width, maxWidth 
- document sort.*.keyFunc


# `tabula` CLI

There is also a `tabula` CLI that can be used for emitting a table
from a stream of JSON objects (or a single JSON array). E.g.:

    $ echo '[{"name":"trent","age":38}, {"name":"ewan","age":4}]' | tabula
    NAME   AGE
    trent  38
    ewan   4

    # column selection
    $ echo '[{"name":"trent","age":38}, {"name":"ewan","age":4}]' | tabula name
    NAME
    trent
    ewan

    # sorting
    $ echo '[{"name":"trent","age":38}, {"name":"ewan","age":4}]' | tabula -s age
    NAME   AGE
    ewan   4
    trent  38


# Features

This section is an (incomplete) list and demo of some of tabula's features.


## ANSI escape codes

`tabula` (as of version 1.7.0) properly calculates widths for cells using
ANSI escape codes for coloring. E.g. try this sample:

```
var tabula = require('tabula');
function red(s) {
    return '\033[31m' + s + '\033[39m';
}
tabula([
    { name: 'Trent', age: 42, job: 'Engineer' },
    { name: 'Ewan', age: red(8), job: 'Student' },
]);
```


# TODO

- Describe the "opinions", features and limitations of this module.

- `tabula` CLI for piping in a JSON array of objects, or stream of objects.
    - streaming
    - option for skipping non-JSON lines (e.g. for bunyan logs)
    - option for non-JSON input? e.g. space separated ('json -ga foo bar'
      output, output from other table-emitting things, perhaps then 2-space
      or more separated), naive-csv
    - separate tabula-cli module?
    - test cases

- Merge this with [node-tab](https://github.com/davepacheco/node-tab) if
  reasonable. I have some PR work for it (that I haven't completed) to add some
  conveniences that `tabulate` provides. It is silly to have two table-printing
  libs in play.


# License

MIT. See LICENSE.txt.

---
_Source: https://npm.io/package/tabula · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
