• Stars
    star
    897
  • Rank 50,907 (Top 2 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Formats data into a string table.

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

More Repositories

1

react-css-modules

Seamless mapping of class names to CSS modules inside of React components.
JavaScript
5,232
star
2

slonik

A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
TypeScript
4,550
star
3

swing

A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder.
JavaScript
2,618
star
4

babel-plugin-react-css-modules

Transforms styleName to className using compile time CSS module resolution.
JavaScript
2,044
star
5

redux-immutable

redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.
TypeScript
1,880
star
6

eslint-plugin-flowtype

Flow type linting rules for ESLint.
JavaScript
1,078
star
7

roarr

JSON logger for Node.js and browser.
TypeScript
1,062
star
8

prepack-webpack-plugin

A webpack plugin for prepack.
JavaScript
1,039
star
9

eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
JavaScript
1,024
star
10

turbowatch

Extremely fast file change detector and task orchestrator for Node.js.
TypeScript
938
star
11

usus

Webpage pre-rendering service. ⚑️
JavaScript
805
star
12

flow-runtime

A runtime type system for JavaScript with full Flow compatibility.
JavaScript
802
star
13

surgeon

Declarative DOM extraction expression evaluator. πŸ‘¨β€βš•οΈ
JavaScript
693
star
14

liqe

Lightweight and performant Lucene-like parser, serializer and search engine.
TypeScript
636
star
15

eslint-config-canonical

The most comprehensive ES code style guide.
JavaScript
536
star
16

write-file-webpack-plugin

Forces webpack-dev-server to write bundle files to the file system.
JavaScript
528
star
17

lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.
TypeScript
518
star
18

gitdown

GitHub markdown preprocessor.
JavaScript
445
star
19

xhprof.io

GUI to analyze the profiling data collected using XHProf – A Hierarchical Profiler for PHP.
PHP
429
star
20

contents

Table of contents generator.
JavaScript
416
star
21

brim

View (minimal-ui) manager for iOS 8.
JavaScript
391
star
22

global-agent

Global HTTP/HTTPS proxy agent configurable using environment variables.
TypeScript
360
star
23

youtube-player

YouTube iframe API abstraction.
JavaScript
340
star
24

react-aux

A self-eradicating component for rendering multiple elements.
JavaScript
329
star
25

http-terminator

Gracefully terminates HTTP(S) server.
TypeScript
324
star
26

isomorphic-webpack

Abstracts universal consumption of application code base using webpack.
JavaScript
291
star
27

scream

Dynamic viewport management for mobile. Manage viewport in different states of device orientation. Scale document to fit viewport. Calculate the dimensions of the "minimal" iOS 8 view relative to your viewport width.
JavaScript
289
star
28

graphql-deduplicator

A GraphQL response deduplicator. Removes duplicate entities from the GraphQL response.
JavaScript
279
star
29

create-index

Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.
JavaScript
279
star
30

gajus.com-blog

The contents of the http://gajus.com/blog/.
JavaScript
226
star
31

wholly

jQuery plugin used to select the entire table row and column in response to mouseenter and mouseleave events. Wholly supports table layouts that utilize colspan and rowspan.
JavaScript
204
star
32

puppeteer-proxy

Proxies Puppeteer Page requests.
JavaScript
203
star
33

canonical-reducer-composition

Spec for Canonical Reducer Composition design pattern.
188
star
34

angular-swing

AngularJS directive for Swing: A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder, and many others.
JavaScript
183
star
35

dindent

HTML indentation library for development and testing.
PHP
177
star
36

babel-plugin-graphql-tag

Compiles GraphQL tagged template strings using graphql-tag.
JavaScript
172
star
37

eslint-plugin-canonical

ESLint rules for Canonical ruleset.
TypeScript
121
star
38

vlad

Input validation library promoting succinct syntax with extendable validators and multilingual support.
PHP
104
star
39

babel-plugin-log-deprecated

Adds a console.warn statement to the functions annotated with @deprecated tag.
JavaScript
103
star
40

redux-immutable-examples

A complete application showing use of redux-immutable.
JavaScript
103
star
41

babel-preset-es2015-webpack

Babel preset for all es2015 plugins except babel-plugin-transform-es2015-modules-commonjs.
JavaScript
97
star
42

scalpel

A CSS selector parser.
JavaScript
95
star
43

eslint-plugin-sql

SQL linting rules for ESLint.
TypeScript
93
star
44

graphql-lazyloader

GraphQL directive that adds Object-level data resolvers.
TypeScript
89
star
45

pg-formatter

A PostgreSQL SQL syntax beautifier.
TypeScript
80
star
46

orientationchangeend

The orientationchangeend event is fired when the orientation of the device has changed and the associated rotation animation has been complete.
JavaScript
78
star
47

bugger

Bugger is a collection of functions for debugging PHP code.
CSS
77
star
48

planton

Database-agnostic task scheduler.
TypeScript
77
star
49

dora

Input generation library for value resolution, data persistence, templates, CSRF and protection from XSS.
CSS
73
star
50

react-css-modules-examples

Usage examples for react-css-modules.
JavaScript
72
star
51

format-graphql

Formats GraphQL schema definition language (SDL) document.
JavaScript
71
star
52

to-string-loader

to-string loader for webpack
JavaScript
64
star
53

extract-email-address

Extracts email address from an arbitrary text input.
TypeScript
62
star
54

interdependent-interactive-histograms

This is a helper function that utilises d3.js and Crossfilter to create interdependent interactive histograms.
JavaScript
60
star
55

babel-plugin-transform-function-composition

Syntactic sugar 🍧🍨🍦 for easy to read function composition. πŸ¦„
JavaScript
58
star
56

preoom

Retrieves & observes Kubernetes Pod resource (CPU, memory) utilisation.
JavaScript
55
star
57

fuss

The Facebook SDK for PHP provides an interface to the Graph API.
PHP
53
star
58

postloader

A scaffolding tool for projects using DataLoader, Flow and PostgreSQL.
JavaScript
51
star
59

moa

MOA implements dynamically generated Active Record database abstraction.
PHP
50
star
60

extract-date

Extracts date from an arbitrary text input.
JavaScript
49
star
61

gitinfo

Gets information about a Git repository.
JavaScript
47
star
62

sister

Foundation for your emitter implementation. 202 reasons to not write your own implementation of event emitter.
JavaScript
45
star
63

react-outside-event

A higher order React component that attaches an event listener for events that occur outside of the component element.
JavaScript
44
star
64

babel-plugin-annotate-console-log

Annotates console.log call expression with information about the invocation context.
JavaScript
42
star
65

react-youtube-player

React component that encapsulates YouTube IFrame Player API and exposes player controls using the component properties.
JavaScript
40
star
66

bundle-dependencies

Generates bundledDependencies package.json value using values of the dependencies property. Updates package.json definition using the generated bundledDependencies value.
JavaScript
39
star
67

facebook-friend-rank

PHP class that can calculate who are the best user's friends. Data accuracy depends on the user activity and granted permissions.
PHP
39
star
68

waitehr

Waits for HTTP response and retries request until the expected response is received.
TypeScript
37
star
69

doll

Extended PDO with inline type hinting, deferred connection support, logging and benchmarking.
PHP
36
star
70

pie-chart

This is a helper function that utilises d3.js to create pie charts.
JavaScript
36
star
71

sguid

Signed Globally Unique Identifier (SGUID) generator.
JavaScript
34
star
72

slonik-utilities

Utilities for manipulating data in PostgreSQL database using Slonik.
TypeScript
32
star
73

prepack-loader

A webpack loader for prepack.
JavaScript
31
star
74

seeql

Real-time SQL profiler.
JavaScript
30
star
75

react-strict-prop-types

A higher order component that raises an error if component is used with an unknown property.
JavaScript
29
star
76

postgres-bridge

postgres/pg compatibility layer
TypeScript
29
star
77

crack-json

Extracts all JSON objects from an arbitrary text document.
JavaScript
29
star
78

roarr-cli

A CLI program for processing Roarr logs.
TypeScript
28
star
79

paggern

Pattern interpreter for generating random strings.
PHP
28
star
80

roarr-browser-log-writer

Roarr log writer for use in a web browser.
TypeScript
27
star
81

cluster-map

Abstracts execution of tasks in parallel using Node.js cluster.
JavaScript
27
star
82

database-types

A generic type generator for various databases.
JavaScript
26
star
83

iapetus

Prometheus metrics server.
TypeScript
25
star
84

require-new

Requires a new module object.
JavaScript
23
star
85

tmdb

The Movie Database (TMDb) SDK.
JavaScript
23
star
86

pan

Touch enabled implementation of WHATWG drag and drop mechanism.
JavaScript
23
star
87

eslint-plugin-zod

Zod linting rules for ESLint.
TypeScript
21
star
88

pragmatist

A collection of tasks to standardize builds.
JavaScript
21
star
89

pianola

A declarative function composition and evaluation engine.
JavaScript
20
star
90

approximate-now

Approximate (fast) current UNIX time.
TypeScript
20
star
91

babel-plugin-transform-export-default-name

Babel plugin that transforms default exports to named exports.
JavaScript
20
star
92

xfetch

A light-weight HTTP client for Node.js.
JavaScript
19
star
93

extract-time

Extracts time from an arbitrary text input.
JavaScript
19
star
94

override-require

Overrides Node.js module resolution logic.
JavaScript
18
star
95

fastify-webpack-hot

A Fastify plugin for serving files emitted by Webpack with Hot Module Replacement (HMR).
TypeScript
18
star
96

canonical

Canonical code style linter and formatter for JavaScript, SCSS, CSS and JSON.
JavaScript
18
star
97

babel-plugin-lodash-modularize

Babel plugin that replaces lodash library import statement to individual module imports.
JavaScript
18
star
98

semantic-url-parser

Extracts content information from known URL patterns.
TypeScript
17
star
99

extract-price

Extracts prices from an arbitrary text input.
JavaScript
17
star
100

express-tus

Express middleware for tus protocol.
JavaScript
16
star