npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@oclif/table

v0.5.1

Published

Display table in terminal

Downloads

2,381,786

Readme

Version Downloads/week License

Description

Print beautiful, flexible tables to the terminal using Ink. This library powers many oclif/Salesforce CLIs and is built for real-world, production output: wide columns, multi-line cells, smart wrapping/truncation, theming, and great CI behavior.

Features

  • Rich rendering via Ink with graceful fallback to plain text in CI
  • Automatic column sizing with max/explicit width support (including percentages)
  • Per-column alignment, padding, and overflow control (wrap, truncate, middle/start/end)
  • Header formatting with change-case presets or custom function
  • Multiple border styles (outline, headers-only, vertical/horizontal, none, and more)
  • Sort and filter data, optionally per-column
  • Print multiple tables side-by-side or stacked with layout controls
  • Return a string (makeTable) or print directly (printTable/printTables)
  • TypeScript-first API with excellent types

Requirements

  • Node.js >= 18
  • ESM only (this package has "type": "module"). Use import, not require.

Installation

npm install @oclif/table
# or
yarn add @oclif/table
# or
pnpm add @oclif/table
# or
bun add @oclif/table

Quick start

import {printTable} from '@oclif/table'

const data = [
  {name: 'Alice', role: 'Engineer', notes: 'Loves distributed systems'},
  {name: 'Bob', role: 'Designer', notes: 'Enjoys typography and UI'},
]

printTable({
  title: 'Team',
  data,
  columns: [
    {key: 'name', width: 16},
    {key: 'role', width: 14, horizontalAlignment: 'center'},
    {key: 'notes', overflow: 'wrap'},
  ],
})

To generate a string instead of printing to stdout:

import {makeTable} from '@oclif/table'

const output = makeTable({data, columns: ['name', 'role', 'notes']})
// do something with `output`

To print multiple tables in one layout:

import {printTables} from '@oclif/table'

printTables(
  [
    {title: 'Developers', data, columns: ['name', 'role']},
    {title: 'Notes', data, columns: ['notes']},
  ],
  {direction: 'row', columnGap: 4, margin: 1},
)

API

  • printTable(options) — renders a single table to stdout.
  • makeTable(options): string — renders a single table and returns the output string.
  • printTables(tables, options?) — renders multiple tables with layout controls.

All three accept the same TableOptions<T> (documented below). printTables accepts an array of TableOptions plus optional container layout props.

TypeScript

import type {TableOptions} from '@oclif/table'

type Row = {name: string; age: number}
const opts: TableOptions<Row> = {
  data: [{name: 'Ada', age: 36}],
  columns: [
    {key: 'name', name: 'Full Name'},
    {key: 'age', horizontalAlignment: 'right'},
  ],
}

Options reference

Below are the most important options with defaults and behavior. See examples in ./examples for more patterns.

  • data (required): array of rows, each a plain object.

  • columns: list of keys or objects describing each column.

    • String form: 'name' (uses key as header)
    • Object form: { key, name?, width?, padding?, overflow?, horizontalAlignment?, verticalAlignment? }
      • name: header label (defaults to key or formatted with headerOptions.formatter)
      • width: number of characters or percentage string like '50%'
      • padding: spaces added on both sides (default: table padding)
      • overflow: 'wrap' | 'truncate' | 'truncate-start' | 'truncate-middle' | 'truncate-end'
      • horizontalAlignment: 'left' | 'center' | 'right'
      • verticalAlignment: 'top' | 'center' | 'bottom'
  • padding (number): cell padding for all columns. Default: 1.

  • maxWidth (number | percentage | 'none'): maximum table width. Defaults to terminal width.

    • When the natural table width exceeds maxWidth, columns shrink and content wraps/truncates based on overflow.
    • Use 'none' to allow unlimited width (useful for very wide outputs; users can resize their terminals).
  • width (number | percentage): exact table width. Overrides maxWidth. If wider than the natural width, columns expand evenly.

  • overflow: cell overflow behavior. Default: 'truncate'.

    • 'wrap' wraps long content
    • 'truncate' truncates the end
    • 'truncate-start' | 'truncate-middle' | 'truncate-end' choose truncation position
  • headerOptions: style options for headers.

    • formatter: either a function (header: string) => string or a change-case preset name: 'camelCase' | 'capitalCase' | 'constantCase' | 'kebabCase' | 'pascalCase' | 'sentenceCase' | 'snakeCase'
    • Styling keys (also supported by titleOptions):
      • color, backgroundColor (named color, hex #rrggbb, or rgb(r,g,b))
      • bold, dimColor, italic, underline, strikethrough, inverse
    • Default header style is bold blue (unless noStyle: true).
  • borderStyle: border preset. Default: 'all'.

    • Available: 'all' | 'headers-only' | 'headers-only-with-outline' | 'headers-only-with-underline' | 'horizontal' | 'horizontal-with-outline' | 'none' | 'outline' | 'vertical' | 'vertical-rows-with-outline' | 'vertical-with-outline'
  • borderColor: optional border color. When unset, the terminal's default color is used.

  • horizontalAlignment: default column alignment. Default: 'left'.

  • verticalAlignment: default vertical alignment within cells. Default: 'top'.

  • filter(row): predicate to include/exclude rows.

  • sort: object mapping keys to 'asc' | 'desc' | (a,b)=>number. Keys order defines multi-column priority.

  • title: optional string printed above the table.

  • titleOptions: style options for the title (same keys as headerOptions except formatter).

  • trimWhitespace: when wrapping text, trim whitespace at line boundaries. Default: true.

  • noStyle: disable all styling. Also strips ANSI color codes from your cell content for accurate width calculation.

Container options (for printTables)

printTables(tables, containerOptions) accepts:

  • direction: 'row' | 'column' (default 'row')
  • columnGap, rowGap: spacing between tables
  • alignItems: 'flex-start' | 'center' | 'flex-end'
  • margin, marginLeft, marginRight, marginTop, marginBottom

Behavior and environment variables

  • Terminal width detection: by default we use your terminal width. Override with OCLIF_TABLE_COLUMN_OVERRIDE.

    • Example: OCLIF_TABLE_COLUMN_OVERRIDE=120 node app.js
  • CI-safe output: in CI environments, we automatically fall back to a plain-text renderer (no Ink) for stability.

    • To force Ink rendering in CI, set OCLIF_TABLE_SKIP_CI_CHECK=1.
  • Very large data: by default, datasets with 10,000+ rows use the plain-text renderer to avoid memory issues.

    • Override with OCLIF_TABLE_LIMIT=<number> (Salesforce CLIs may also honor SF_TABLE_LIMIT).

Advanced examples

Header formatting with change-case:

import {printTable} from '@oclif/table'

printTable({
  data: [{first_name: 'Ada', last_name: 'Lovelace'}],
  columns: ['first_name', 'last_name'],
  headerOptions: {formatter: 'capitalCase'},
})

Per-column sizing and overflow:

printTable({
  data: [{name: 'A very very long name', notes: 'Multi-line\ncontent supported'}],
  maxWidth: '80%',
  columns: [
    {key: 'name', width: 20, overflow: 'truncate-middle'},
    {key: 'notes', overflow: 'wrap', horizontalAlignment: 'right'},
  ],
})

Switching borders and colors:

printTable({
  title: 'Inventory',
  titleOptions: {bold: true, color: 'cyan'},
  data: [{item: 'Widget', qty: 10}],
  columns: ['item', {key: 'qty', horizontalAlignment: 'right'}],
  borderStyle: 'vertical-with-outline',
  borderColor: 'green',
})

Examples directory

This repo contains many runnable examples in ./examples (including edge cases like very wide/very tall tables). Run any with:

tsx examples/basic.ts

Testing

This package includes snapshot tests for all examples to ensure consistent output across different environments.

Running tests

# Run all tests (including snapshot tests)
yarn test

# Run only snapshot tests
yarn test:examples

# Update snapshots after intentional changes
yarn test:examples:update

How snapshot testing works

Examples are executed in an isolated child process with:

  • Fixed terminal width (OCLIF_TABLE_COLUMN_OVERRIDE=120)
  • Disabled CI detection unless an example sets it
  • ESM loader for TypeScript (ts-node/esm)

Snapshots live in test/__snapshots__/examples/*.txt and mirror the examples directory structure.


Contributing

See the contributing guide.

License

MIT © Salesforce