Coder Social home page Coder Social logo

table's Introduction

Table

Produces a string that represents array data in a text table.

Github action status Coveralls NPM version Canonical Code Style Twitter Follow

Demo of table displaying a list of missions to the Moon.

Features

  • Works with strings containing fullwidth characters.
  • Works with strings containing ANSI escape codes.
  • Configurable border characters.
  • Configurable content alignment per column.
  • Configurable content padding per column.
  • Configurable column width.
  • Text wrapping.

Install

npm install table

Buy Me A Coffee Become a Patron

Usage

import { table } from 'table';

// Using commonjs?
// const { table } = require('table');

const data = [
    ['0A', '0B', '0C'],
    ['1A', '1B', '1C'],
    ['2A', '2B', '2C']
];

console.log(table(data));
╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝

API

table

Returns the string in the table format

Parameters:

  • data: The data to display

    • Type: any[][]
    • Required: true
  • config: Table configuration

    • Type: object
    • Required: false

config.border

Type: { [type: string]: string }
Default: honeywell template

Custom borders. The keys are any of:

  • topLeft, topRight, topBody,topJoin
  • bottomLeft, bottomRight, bottomBody, bottomJoin
  • joinLeft, joinRight, joinBody, joinJoin
  • bodyLeft, bodyRight, bodyJoin
  • headerJoin
const data = [
  ['0A', '0B', '0C'],
  ['1A', '1B', '1C'],
  ['2A', '2B', '2C']
];

const config = {
  border: {
    topBody: `─`,
    topJoin: `┬`,
    topLeft: `┌`,
    topRight: `┐`,

    bottomBody: `─`,
    bottomJoin: `┴`,
    bottomLeft: `└`,
    bottomRight: `┘`,

    bodyLeft: `│`,
    bodyRight: `│`,
    bodyJoin: `│`,

    joinBody: `─`,
    joinLeft: `├`,
    joinRight: `┤`,
    joinJoin: `┼`
  }
};

console.log(table(data, config));
┌────┬────┬────┐
│ 0A │ 0B │ 0C │
├────┼────┼────┤
│ 1A │ 1B │ 1C │
├────┼────┼────┤
│ 2A │ 2B │ 2C │
└────┴────┴────┘

config.drawVerticalLine

Type: (lineIndex: number, columnCount: number) => boolean
Default: () => true

It is used to tell whether to draw a vertical line. This callback is called for each vertical border of the table. If the table has n columns, then the index parameter is alternatively received all numbers in range [0, n] inclusively.

const data = [
  ['0A', '0B', '0C'],
  ['1A', '1B', '1C'],
  ['2A', '2B', '2C'],
  ['3A', '3B', '3C'],
  ['4A', '4B', '4C']
];

const config = {
  drawVerticalLine: (lineIndex, columnCount) => {
    return lineIndex === 0 || lineIndex === columnCount;
  }
};

console.log(table(data, config));
╔════════════╗
║ 0A  0B  0C ║
╟────────────╢
║ 1A  1B  1C ║
╟────────────╢
║ 2A  2B  2C ║
╟────────────╢
║ 3A  3B  3C ║
╟────────────╢
║ 4A  4B  4C ║
╚════════════╝

config.drawHorizontalLine

Type: (lineIndex: number, rowCount: number) => boolean
Default: () => true

It is used to tell whether to draw a horizontal line. This callback is called for each horizontal border of the table. If the table has n rows, then the index parameter is alternatively received all numbers in range [0, n] inclusively. If the table has n rows and contains the header, then the range will be [0, n+1] inclusively.

const data = [
  ['0A', '0B', '0C'],
  ['1A', '1B', '1C'],
  ['2A', '2B', '2C'],
  ['3A', '3B', '3C'],
  ['4A', '4B', '4C']
];

const config = {
  drawHorizontalLine: (lineIndex, rowCount) => {
    return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount - 1 || lineIndex === rowCount;
  }
};

console.log(table(data, config));
╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
║ 2A │ 2B │ 2C ║
║ 3A │ 3B │ 3C ║
╟────┼────┼────╢
║ 4A │ 4B │ 4C ║
╚════╧════╧════╝

config.singleLine

Type: boolean
Default: false

If true, horizontal lines inside the table are not drawn. This option also overrides the config.drawHorizontalLine if specified.

const data = [
  ['-rw-r--r--', '1', 'pandorym', 'staff', '1529', 'May 23 11:25', 'LICENSE'],
  ['-rw-r--r--', '1', 'pandorym', 'staff', '16327', 'May 23 11:58', 'README.md'],
  ['drwxr-xr-x', '76', 'pandorym', 'staff', '2432', 'May 23 12:02', 'dist'],
  ['drwxr-xr-x', '634', 'pandorym', 'staff', '20288', 'May 23 11:54', 'node_modules'],
  ['-rw-r--r--', '1,', 'pandorym', 'staff', '525688', 'May 23 11:52', 'package-lock.json'],
  ['-rw-r--r--@', '1', 'pandorym', 'staff', '2440', 'May 23 11:25', 'package.json'],
  ['drwxr-xr-x', '27', 'pandorym', 'staff', '864', 'May 23 11:25', 'src'],
  ['drwxr-xr-x', '20', 'pandorym', 'staff', '640', 'May 23 11:25', 'test'],
];

const config = {
  singleLine: true
};

console.log(table(data, config));
╔═════════════╤═════╤══════════╤═══════╤════════╤══════════════╤═══════════════════╗
║ -rw-r--r--  │ 1   │ pandorym │ staff │ 1529   │ May 23 11:25 │ LICENSE           ║
║ -rw-r--r--  │ 1   │ pandorym │ staff │ 16327  │ May 23 11:58 │ README.md         ║
║ drwxr-xr-x  │ 76  │ pandorym │ staff │ 2432   │ May 23 12:02 │ dist              ║
║ drwxr-xr-x  │ 634 │ pandorym │ staff │ 20288  │ May 23 11:54 │ node_modules      ║
║ -rw-r--r--  │ 1,  │ pandorym │ staff │ 525688 │ May 23 11:52 │ package-lock.json ║
║ -rw-r--r--@ │ 1   │ pandorym │ staff │ 2440   │ May 23 11:25 │ package.json      ║
║ drwxr-xr-x  │ 27  │ pandorym │ staff │ 864    │ May 23 11:25 │ src               ║
║ drwxr-xr-x  │ 20  │ pandorym │ staff │ 640    │ May 23 11:25 │ test              ║
╚═════════════╧═════╧══════════╧═══════╧════════╧══════════════╧═══════════════════╝

config.columns

Type: Column[] | { [columnIndex: number]: Column }

Column specific configurations.

config.columns[*].width

Type: number
Default: the maximum cell widths of the column

Column width (excluding the paddings).

const data = [
  ['0A', '0B', '0C'],
  ['1A', '1B', '1C'],
  ['2A', '2B', '2C']
];

const config = {
  columns: {
    1: { width: 10 }
  }
};

console.log(table(data, config));
╔════╤════════════╤════╗
║ 0A │ 0B         │ 0C ║
╟────┼────────────┼────╢
║ 1A │ 1B         │ 1C ║
╟────┼────────────┼────╢
║ 2A │ 2B         │ 2C ║
╚════╧════════════╧════╝

config.columns[*].alignment

Type: 'center' | 'justify' | 'left' | 'right'
Default: 'left'

Cell content horizontal alignment

const data = [
  ['0A', '0B', '0C', '0D 0E 0F'],
  ['1A', '1B', '1C', '1D 1E 1F'],
  ['2A', '2B', '2C', '2D 2E 2F'],
];

const config = {
  columnDefault: {
    width: 10,
  },
  columns: [
    { alignment: 'left' },
    { alignment: 'center' },
    { alignment: 'right' },
    { alignment: 'justify' }
  ],
};

console.log(table(data, config));
╔════════════╤════════════╤════════════╤════════════╗
║ 0A         │     0B     │         0C │ 0D  0E  0F ║
╟────────────┼────────────┼────────────┼────────────╢
║ 1A         │     1B     │         1C │ 1D  1E  1F ║
╟────────────┼────────────┼────────────┼────────────╢
║ 2A         │     2B     │         2C │ 2D  2E  2F ║
╚════════════╧════════════╧════════════╧════════════╝

config.columns[*].verticalAlignment

Type: 'top' | 'middle' | 'bottom'
Default: 'top'

Cell content vertical alignment

const data = [
  ['A', 'B', 'C', 'DEF'],
];

const config = {
  columnDefault: {
    width: 1,
  },
  columns: [
    { verticalAlignment: 'top' },
    { verticalAlignment: 'middle' },
    { verticalAlignment: 'bottom' },
  ],
};

console.log(table(data, config));
╔═══╤═══╤═══╤═══╗
║ A │   │   │ D ║
║   │ B │   │ E ║
║   │   │ C │ F ║
╚═══╧═══╧═══╧═══╝

config.columns[*].paddingLeft

Type: number
Default: 1

The number of whitespaces used to pad the content on the left.

config.columns[*].paddingRight

Type: number
Default: 1

The number of whitespaces used to pad the content on the right.

The paddingLeft and paddingRight options do not count on the column width. So the column has width = 5, paddingLeft = 2 and paddingRight = 2 will have the total width is 9.

const data = [
  ['0A', 'AABBCC', '0C'],
  ['1A', '1B', '1C'],
  ['2A', '2B', '2C']
];

const config = {
  columns: [
    {
      paddingLeft: 3
    },
    {
      width: 2,
      paddingRight: 3
    }
  ]
};

console.log(table(data, config));
╔══════╤══════╤════╗
║   0A │ AA   │ 0C ║
║      │ BB   │    ║
║      │ CC   │    ║
╟──────┼──────┼────╢
║   1A │ 1B   │ 1C ║
╟──────┼──────┼────╢
║   2A │ 2B   │ 2C ║
╚══════╧══════╧════╝

config.columns[*].truncate

Type: number
Default: Infinity

The number of characters is which the content will be truncated. To handle a content that overflows the container width, table package implements text wrapping. However, sometimes you may want to truncate content that is too long to be displayed in the table.

const data = [
  ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
];

const config = {
  columns: [
    {
      width: 20,
      truncate: 100
    }
  ]
};

console.log(table(data, config));
╔══════════════════════╗
║ Lorem ipsum dolor si ║
║ t amet, consectetur  ║
║ adipiscing elit. Pha ║
║ sellus pulvinar nibh ║
║ sed mauris convall…  ║
╚══════════════════════╝

config.columns[*].wrapWord

Type: boolean
Default: false

The table package implements auto text wrapping, i.e., text that has the width greater than the container width will be separated into multiple lines at the nearest space or one of the special characters: \|/_.,;-.

When wrapWord is false:

const data = [
    ['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
];

const config = {
  columns: [ { width: 20 } ]
};

console.log(table(data, config));
╔══════════════════════╗
║ Lorem ipsum dolor si ║
║ t amet, consectetur  ║
║ adipiscing elit. Pha ║
║ sellus pulvinar nibh ║
║ sed mauris convallis ║
║ dapibus. Nunc venena ║
║ tis tempus nulla sit ║
║ amet viverra.        ║
╚══════════════════════╝

When wrapWord is true:

╔══════════════════════╗
║ Lorem ipsum dolor    ║
║ sit amet,            ║
║ consectetur          ║
║ adipiscing elit.     ║
║ Phasellus pulvinar   ║
║ nibh sed mauris      ║
║ convallis dapibus.   ║
║ Nunc venenatis       ║
║ tempus nulla sit     ║
║ amet viverra.        ║
╚══════════════════════╝

config.columnDefault

Type: Column
Default: {}

The default configuration for all columns. Column-specific settings will overwrite the default values.

config.header

Type: object

Header configuration.

Deprecated in favor of the new spanning cells API.

The header configuration inherits the most of the column's, except:

  • content {string}: the header content.
  • width: calculate based on the content width automatically.
  • alignment: center be default.
  • verticalAlignment: is not supported.
  • config.border.topJoin will be config.border.topBody for prettier.
const data = [
      ['0A', '0B', '0C'],
      ['1A', '1B', '1C'],
      ['2A', '2B', '2C'],
    ];

const config = {
  columnDefault: {
    width: 10,
  },
  header: {
    alignment: 'center',
    content: 'THE HEADER\nThis is the table about something',
  },
}

console.log(table(data, config));
╔══════════════════════════════════════╗
║              THE HEADER              ║
║  This is the table about something   ║
╟────────────┬────────────┬────────────╢
║ 0A         │ 0B         │ 0C         ║
╟────────────┼────────────┼────────────╢
║ 1A         │ 1B         │ 1C         ║
╟────────────┼────────────┼────────────╢
║ 2A         │ 2B         │ 2C         ║
╚════════════╧════════════╧════════════╝

config.spanningCells

Type: SpanningCellConfig[]

Spanning cells configuration.

The configuration should be straightforward: just specify an array of minimal cell configurations including the position of top-left cell and the number of columns and/or rows will be expanded from it.

The content of overlap cells will be ignored to make the data shape be consistent.

By default, the configuration of column that the top-left cell belongs to will be applied to the whole spanning cell, except:

  • The width will be summed up of all spanning columns.
  • The paddingRight will be received from the right-most column intentionally.

Advances customized column-like styles can be configurable to each spanning cell to overwrite the default behavior.

const data = [
  ['Test Coverage Report', '', '', '', '', ''],
  ['Module', 'Component', 'Test Cases', 'Failures', 'Durations', 'Success Rate'],
  ['Services', 'User', '50', '30', '3m 7s', '60.0%'],
  ['', 'Payment', '100', '80', '7m 15s', '80.0%'],
  ['Subtotal', '', '150', '110', '10m 22s', '73.3%'],
  ['Controllers', 'User', '24', '18', '1m 30s', '75.0%'],
  ['', 'Payment', '30', '24', '50s', '80.0%'],
  ['Subtotal', '', '54', '42', '2m 20s', '77.8%'],
  ['Total', '', '204', '152', '12m 42s', '74.5%'],
];

const config = {
  columns: [
    { alignment: 'center', width: 12 },
    { alignment: 'center', width: 10 },
    { alignment: 'right' },
    { alignment: 'right' },
    { alignment: 'right' },
    { alignment: 'right' }
  ],
  spanningCells: [
    { col: 0, row: 0, colSpan: 6 },
    { col: 0, row: 2, rowSpan: 2, verticalAlignment: 'middle'},
    { col: 0, row: 4, colSpan: 2, alignment: 'right'},
    { col: 0, row: 5, rowSpan: 2, verticalAlignment: 'middle'},
    { col: 0, row: 7, colSpan: 2, alignment: 'right' },
    { col: 0, row: 8, colSpan: 2, alignment: 'right' }
  ],
};

console.log(table(data, config));
╔══════════════════════════════════════════════════════════════════════════════╗
║                             Test Coverage Report                             ║
╟──────────────┬────────────┬────────────┬──────────┬───────────┬──────────────╢
║    Module    │ Component  │ Test Cases │ Failures │ Durations │ Success Rate ║
╟──────────────┼────────────┼────────────┼──────────┼───────────┼──────────────╢
║              │    User    │         50 │       30 │     3m 7s │        60.0% ║
║   Services   ├────────────┼────────────┼──────────┼───────────┼──────────────╢
║              │  Payment   │        100 │       80 │    7m 15s │        80.0% ║
╟──────────────┴────────────┼────────────┼──────────┼───────────┼──────────────╢
║                  Subtotal │        150 │      110 │   10m 22s │        73.3% ║
╟──────────────┬────────────┼────────────┼──────────┼───────────┼──────────────╢
║              │    User    │         24 │       18 │    1m 30s │        75.0% ║
║ Controllers  ├────────────┼────────────┼──────────┼───────────┼──────────────╢
║              │  Payment   │         30 │       24 │       50s │        80.0% ║
╟──────────────┴────────────┼────────────┼──────────┼───────────┼──────────────╢
║                  Subtotal │         54 │       42 │    2m 20s │        77.8% ║
╟───────────────────────────┼────────────┼──────────┼───────────┼──────────────╢
║                     Total │        204 │      152 │   12m 42s │        74.5% ║
╚═══════════════════════════╧════════════╧══════════╧═══════════╧══════════════╝

createStream

table package exports createStream function used to draw a table and append rows.

Parameter:

  • config: the same as table's, except config.columnDefault.width and config.columnCount must be provided.
import { createStream } from 'table';

const config = {
  columnDefault: {
    width: 50
  },
  columnCount: 1
};

const stream = createStream(config);

setInterval(() => {
  stream.write([new Date()]);
}, 500);

Streaming current date.

table package uses ANSI escape codes to overwrite the output of the last line when a new row is printed.

The underlying implementation is explained in this Stack Overflow answer.

Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.

import { createStream } from 'table';

import _ from 'lodash';

const config = {
  columnDefault: {
    width: 50
  },
  columnCount: 3,
  columns: [
    {
      width: 10,
      alignment: 'right'
    },
    { alignment: 'center' },
    { width: 10 }

  ]
};

const stream = createStream(config);

let i = 0;

setInterval(() => {
  let random;

  random = _.sample('abcdefghijklmnopqrstuvwxyz', _.random(1, 30)).join('');

  stream.write([i++, new Date(), random]);
}, 500);

Streaming random data.

getBorderCharacters

Parameter:

  • template
    • Type: 'honeywell' | 'norc' | 'ramac' | 'void'
    • Required: true

You can load one of the predefined border templates using getBorderCharacters function.

import { table, getBorderCharacters } from 'table';

const data = [
  ['0A', '0B', '0C'],
  ['1A', '1B', '1C'],
  ['2A', '2B', '2C']
];

const config = {
  border: getBorderCharacters(`name of the template`)
};

console.log(table(data, config));
# honeywell

╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝

# norc

┌────┬────┬────┐
│ 0A │ 0B │ 0C │
├────┼────┼────┤
│ 1A │ 1B │ 1C │
├────┼────┼────┤
│ 2A │ 2B │ 2C │
└────┴────┴────┘

# ramac (ASCII; for use in terminals that do not support Unicode characters)

+----+----+----+
| 0A | 0B | 0C |
|----|----|----|
| 1A | 1B | 1C |
|----|----|----|
| 2A | 2B | 2C |
+----+----+----+

# void (no borders; see "borderless table" section of the documentation)

 0A  0B  0C

 1A  1B  1C

 2A  2B  2C

Raise an issue if you'd like to contribute a new border template.

Borderless Table

Simply using void border character template creates a table with a lot of unnecessary spacing.

To create a more pleasant to the eye table, reset the padding and remove the joining rows, e.g.

const output = table(data, {
    border: getBorderCharacters('void'),
    columnDefault: {
        paddingLeft: 0,
        paddingRight: 1
    },
    drawHorizontalLine: () => false
    }
);

console.log(output);
0A 0B 0C
1A 1B 1C
2A 2B 2C

table's People

Contributors

crow-eh avatar danilvalov avatar davidhq avatar dependabot[bot] avatar epoberezkin avatar esrefdurna avatar fracmak avatar gajus avatar ianedington avatar jeremyvignelles avatar jimmywarting avatar leask avatar ljharb avatar m-allanson avatar markherhold avatar michaelgwelch avatar miosame avatar mrcheater avatar nam-hle avatar pandorym avatar raffis avatar realityking avatar rix0rrr avatar shuunen avatar tahmidsadik avatar viddo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

table's Issues

Cannot find module './border/'

I'm running Node v0.12.0 (my company requires this whole security process in order to upgrade anything, it's a big hassle). When I try to import this library via the require function, like so:

var table = require("table");

I get this result:

>> Error: Cannot find module './border/'

I would recommend either adding support for pre-ES6 versions of Node, or (more simply) add an engines entry to your package.json file that sets the required version of Node higher than v0.12.0.

Newline not allowed in column data

Considering the following row array:

let rows = [
  [chalk.blue('foobar'), 'The quick brown fox'],
  [chalk.blue('barbaz'), 'Jumps over\nthe lazy dog'],
  [chalk.blue('lorem'), 'ipsum']
];

Calling table results in the following error: Error: Table data must not contain control characters.

Checked the readme and there's nothing about this error. Does this module restrict newlines (and other control characters) in column values, or am I missing something and am a big dummy?

Cannot set property '0' of undefined

image

[ 'City' ] 0 0 'City'
[ '' ] 0 0 ''

node_modules/table/dist/mapDataUsingRowHeightIndex.js:53
        rowHeight[index2][index1] = part;
                                  ^

TypeError: Cannot set property '0' of undefined

New release

When is it planned to release a new version?

In 4.0.1, there is still the dependency to ajv ^4.7.0, which leads to a critical dependency warning. The warning would be solved with ajv updated to version 5, which is already on master.

Wrap words

The auto-wrapping functionality should be able to wrap lines respecting word barriers.

In the current output, string is chunked into rows simply using length delimiter, e.g.

║ Message                                                ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/check-returns-types' wa     ║
║ s not found                                            ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/check-types' was not fo     ║
║ und                                                    ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/require-param' was not      ║
║ found                                                  ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/require-returns-descrip     ║
║ tion' was not found                                    ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/require-returns-types'      ║
║ was not found                                          ║
╟────────────────────────────────────────────────────────╢
║ Variables within the same declaration block should     ║
║ be sorted alphabetically                               ║
╟────────────────────────────────────────────────────────╢
║ "lintFiles" is defined but never used                  ║
╟────────────────────────────────────────────────────────╢
║ Missing JSDoc @returns for function                    ║

It should use word (space) or special character barrier when possible, e.g.

║ Message                                                ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/check-returns-types'        ║
║ was not found                                          ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/check-types' was not        ║
║ found                                                  ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/require-param' was not      ║
║ found                                                  ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule                                    ║
║ 'jsdoc/require-returns-description' was not found      ║
╟────────────────────────────────────────────────────────╢
║ Definition for rule 'jsdoc/require-returns-types'      ║
║ was not found                                          ║
╟────────────────────────────────────────────────────────╢
║ Variables within the same declaration block should     ║
║ be sorted alphabetically                               ║
╟────────────────────────────────────────────────────────╢
║ "lintFiles" is defined but never used                  ║
╟────────────────────────────────────────────────────────╢
║ Missing JSDoc @returns for function                    ║

How can I wrap text by \n ?

How can I wrap text As shown below ###?

There is not much content in each line.

image

The following code will get a wrong result

stream.write([
  '🌹',
  ['Apple', 'Facebook', 'Homelink'].join('\n')
])

Here is my config for table
image

Error in mapDataUsingRowHeightIndex.js when cell contains too many newline symbols

This code

const table = require('table');

const config = {
    columnDefault: {
        width: 5
    },
    columnCount: 3
};
const stream = table.createStream(config);

const lastCell = '\na\n2\n3';

stream.write([1, 2, 3]);
stream.write([1, 2, lastCell]);

fails with following error:

╔═══════╤═══════╤═══════╗
║ 1     │ 2     │ 3     ║
╚═══════╧═══════╧═══════╝/path_to_prj/node_modules/table/dist/mapDataUsingRowHeightIndex.js:49
        rowHeight[index2][index1] = part;
                                  ^

TypeError: Cannot set property '2' of undefined
at _lodash2.default.forEach (/path_to_prj/node_modules/table/dist/mapDataUsingRowHeightIndex.js:49:35)
...

Node v6.5.0.

Borderless Demo in Readme Possibly Erroneous

I copied and pasted the borderless demo from the README verbatim and it's printing empty lines between rows, which seems to run contrary to the expected output according to that section in the README. Here's my output:

→ node table-test.js

0A 0B 0C 

1A 1B 1C 

2A 2B 2C 

Does the README and the section on borderless tables need updating?

error str.normalize() on android

Hi!
i'm run debug my app is ok but when build release then show red error:
TypeError: underfined is not a function (evaluating 'str.normalize()')
please help me.
thanks

`@types/table` is on older version - write in TS maybe?

Right now I have these installed:

"table": "^5.0.2"
"@types/table": "^4.0.5"

and I see this:

screenshot from 2018-09-05 15-09-58

It really helps if libraries are written in TS...have external typings means the typings are never in sync, ultimately. Maybe I installed the wrong @types package?

cell span (colspan, table title) support

Just looking for this simple feature in gajus/table

screenshot 2016-04-09 18 03 19

Looking for somewhere in this library's output to put "Suman Test Results"

Does this lib support a table title?

Error raised when on cell is empty

Hi

The following error is raised by the method calculateCellHeight.js when one cell is empty:
Unhandled rejection Error: Column width must be greater than 0.

I think it should raise such error only when a whole column is empty
The minWidth configuration option should also be used to compute this width

Thanks

Pierre-André

How could I use newline characters?

I want to start a new line in a single cell, so I tried to add '\r\n' or '\n' at the end of the line. But it seems like it will be forbidden because of the regex test in validateData.js line 58: /[\x01-\x1A]/.test(cell). So is there any way to have a new line?

wrapWord does not exists in ColumnConfig interface

Using this :

const data = [
    ['0A', '0B', '0C'],
    ['1A', '1B', '1C'],
    ['2A', '2B', '2C']
];
const config = {
    columns: {
      0: {
       wrapWord: true,
      }
    }
  };
console.log(table(data, config));

Will results with this error :

TSError: ⨯ Unable to compile TypeScript:
src/index.ts(594,27): error TS2345: Argument of type '{ columns: { 0: { wrapWord: boolean; }; }; }' is not assignable to parameter of type 'TableUserConfig'

Streaming - columnSizeIndex.map is not a function

Hello, I have a problem with streaming. I used example code only difference is I changed import with require as const {createStream} = require("table");

  const columns = columnSizeIndex.map(size => {
                                  ^

TypeError: columnSizeIndex.map is not a function
    at drawBorder (C:\nodejs\node_modules\table\dist\drawBorder.js:20:35)
    at drawBorderTop (C:\nodejs\node_modules\table\dist\drawBorder.js:41:10)
    at create (C:\nodejs\node_modules\table\dist\createStream.js:85:43)
    at Object.write (C:\nodejs\node_modules\table\dist\createStream.js:151:16)
    at Timeout.setInterval [as _onTimeout] (C:\nodejs\index.js:70:12)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)

Tag older releases

It would be helpful for seeing the state of the code at specific versions if each of them were tagged here in the repo instead of just released on NPM.

To tag older versions with the proper timestamp you can use a script like the following on Windows:

tag-release.ps1:

param([string]$version = "")
$message=(git log -1 --pretty=%B | head -1)
$env:GIT_COMMITTER_DATE=(git show --format=%aD | head -1)
git tag -a "$version" -m "$message"

This is a slightly modified version of this answer which has a version for *NIX shells.

header, where the header does not have columns

Right now, basic output might look like:

╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝

I am looking for something like this instead:

╔══════════════╗
║no columns here
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝

where the header does not have columns, is this possible?

New Table Template - Markdown

Great existing table templates, but one key item that's missing is the Markdown table.

| 0A | 0B | 0C |
|----|----|----|
| 1A | 1B | 1C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |
| 2A | 2B | 2C |

Results in cool stuff on github, like so:

0A 0B 0C
1A 1B 1C
2A 2B 2C
2A 2B 2C
2A 2B 2C
2A 2B 2C
2A 2B 2C

Would be nice if we could give users a copy/paste friendly table for github!

https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables

Ability to progressively update a table

Hi :-)

I have a case in which it takes time to retrieve all the data I need to display in a tabular way.
I was thinking of rendering the table progressively, as the data fetching progresses.

Do you think this is possible?

Add ability to make cells span columns and/or rows.

This feature already exists in https://github.com/jamestalmage/cli-table2 package.

Visually, it looks pretty cool:

┌───────┬─────┬────┐
│ hello │ sup │ hi │
├───────┤     │    │
│ howdy │     │    │
├───┬───┼──┬──┤    │
│ o │ k │  │  │    │
└───┴───┴──┴──┴────┘

In cli-table2 the syntax for that is:

var table;

table = new Table({
    style: {
        head: [],
        border: []
    }
});

table.push(
    [
        {
            content: 'hello',
            colSpan: 2
        },
        {
            rowSpan: 2,
            colSpan: 2,
            content: 'sup'
        },
        {
            rowSpan: 3,
            content: 'hi'
        }
    ],
    [
        {
            content: 'howdy',
            colSpan:2
        }
    ],
    [
        'o',
        'k',
        '',
        ''
    ]
);

Terminal Links dont work

I am trying to use https://github.com/sindresorhus/terminal-link

First I got the error

(node:6881) UnhandledPromiseRejectionWarning: Error: Table data must not contain control characters.
    at validateTableData (/Users/alisowski/Documents/perf-table/node_modules/table/dist/validateTableData.js:62:19)
    at table (/Users/alisowski/Documents/perf-table/node_modules/table/dist/table.js:95:34)
    at Object.<anonymous> (/Users/alisowski/Documents/perf-table/dist/index.js:221:36)
    at step (/Users/alisowski/Documents/perf-table/dist/index.js:43:23)
    at Object.next (/Users/alisowski/Documents/perf-table/dist/index.js:24:53)
    at fulfilled (/Users/alisowski/Documents/perf-table/dist/index.js:15:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

After commenting out the code that threw the error It output

screen shot 2018-10-02 at 11 37 33 am

Do you think it will be possible to terminal links inside of the table?

TypeError: table is not a function

Hi,

I tried to use table with Gulp in our starter kit. I had to use require() to import it because I can't install babel

But when I try to use table with your exemple, it return me this error.

data = [
    ['0A', '0B', '0C'],
    ['1A', '1B', '1C'],
    ['2A', '2B', '2C']
];

options = {
    column: {
        0: {
            alignment: 'left',
            minWidth: 10
        },
        1: {
            alignment: 'center',
            minWidth: 10
        },
        2: {
            alignment: 'right',
            minWidth: 10
        }
    }
};

output = table(data, options);

Is there a way to use table without ES6?

Thanks for your help!

emoji cause table column width corruption

Emojis in cell text cause column width corruption:

corrupted table

stringWidth for ie. 24.2⚠️ returns 6. I am not Unicode expert, but this is most likely related to ZWJ code points and issue in string-width dependency: sindresorhus/string-width#2. Since that issue is almost 2 years old, maybe a different module should be used or own approach implemented?

TypeScript Definition

Would you be willing to write a TypeScript definition file for this package and submit it to the Typings registry? I'm writing a package in TypeScript and it'd be great to use your stuff.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.