# text-table

> borderless text tables with alignment

Latest version **0.2.0** (published 2013-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install text-table
pnpm add text-table
yarn add text-table
bun add text-table
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2013-10-05 |
| First published | 2013-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/text-table) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James Halliday |
| Maintainers | substack |
| Keywords | text, table, align, ascii, rows, tabular |

## Links

- npm: https://www.npmjs.com/package/text-table
- Repository: https://github.com/substack/text-table
- Issues: https://github.com/substack/text-table/issues
- npm.io page: https://npm.io/package/text-table

## 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

- 0.2.0 (latest) — 2013-10-05
- 0.1.1 — 2013-05-16
- 0.1.0 — 2013-05-12
- 0.0.1 — 2013-05-11
- 0.0.0 — 2013-05-11

## README

# text-table

generate borderless text table strings suitable for printing to stdout

[![build status](https://secure.travis-ci.org/substack/text-table.png)](http://travis-ci.org/substack/text-table)

[![browser support](https://ci.testling.com/substack/text-table.png)](http://ci.testling.com/substack/text-table)

# example

## default align

``` js
var table = require('text-table');
var t = table([
    [ 'master', '0123456789abcdef' ],
    [ 'staging', 'fedcba9876543210' ]
]);
console.log(t);
```

```
master   0123456789abcdef
staging  fedcba9876543210
```

## left-right align

``` js
var table = require('text-table');
var t = table([
    [ 'beep', '1024' ],
    [ 'boop', '33450' ],
    [ 'foo', '1006' ],
    [ 'bar', '45' ]
], { align: [ 'l', 'r' ] });
console.log(t);
```

```
beep   1024
boop  33450
foo    1006
bar      45
```

## dotted align

``` js
var table = require('text-table');
var t = table([
    [ 'beep', '1024' ],
    [ 'boop', '334.212' ],
    [ 'foo', '1006' ],
    [ 'bar', '45.6' ],
    [ 'baz', '123.' ]
], { align: [ 'l', '.' ] });
console.log(t);
```

```
beep  1024
boop   334.212
foo   1006
bar     45.6
baz    123.
```

## centered

``` js
var table = require('text-table');
var t = table([
    [ 'beep', '1024', 'xyz' ],
    [ 'boop', '3388450', 'tuv' ],
    [ 'foo', '10106', 'qrstuv' ],
    [ 'bar', '45', 'lmno' ]
], { align: [ 'l', 'c', 'l' ] });
console.log(t);
```

```
beep    1024   xyz
boop  3388450  tuv
foo    10106   qrstuv
bar      45    lmno
```

# methods

``` js
var table = require('text-table')
```

## var s = table(rows, opts={})

Return a formatted table string `s` from an array of `rows` and some options
`opts`.

`rows` should be an array of arrays containing strings, numbers, or other
printable values.

options can be:

* `opts.hsep` - separator to use between columns, default `'  '`
* `opts.align` - array of alignment types for each column, default `['l','l',...]`
* `opts.stringLength` - callback function to use when calculating the string length

alignment types are:

* `'l'` - left
* `'r'` - right
* `'c'` - center
* `'.'` - decimal

# install

With [npm](https://npmjs.org) do:

```
npm install text-table
```

# Use with ANSI-colors

Since the string length of ANSI color schemes does not equal the length
JavaScript sees internally it is necessary to pass the a custom string length
calculator during the main function call.

See the `test/ansi-colors.js` file for an example.

# license

MIT

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