1.0.1 • Published 3 months ago

inquirer-table v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

inquirer-table

NPM npm.io npm.io npm.io

A table prompt for Inquirer.js.

Interactive table component for command line interfaces.

Installation

yarnnpmpnpm
yarn add inquirer-tablenpm install inquirer-tablepnpm add inquirer-table

Usage

import { table, type TableColumn } from 'inquirer-table';

interface Post {
  userId: number;
  id: number;
  title: string;
  body: string;
}

const posts: Post[] = [
  {
    userId: 1,
    id: 1,
    title:
      'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
    body: 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto'
  }
];

const columns: TableColumn<Post>[] = [
  {
    header: 'ID',
    accessorKey: 'id'
  },
  {
    header: 'User ID',
    accessorKey: 'userId'
  },
  {
    header: 'Title',
    accessorKey: 'title'
  },
  {
    header: 'Body',
    accessorKey: 'body'
  }
];

const answer = await table({
  data: posts,
  columns
});

See other usage examples

Options

PropertyTypeRequiredDescription
dataTableItem[]YesData to be shown in the table.
columnsTableColumn<TableItem>[]YesTable columns.
pageSizenumberNoPage size for pagination. Defaults to 5.
multiplebooleanNoIf true, multiple selection is allowed. Defaults to false.
selectablebooleanNoIf true, table rows become selectable. Defaults to false.
abortControllerAbortControllerNoIf an AbortController is provided, the prompt can be cancelled by pressing backspace. Canceling Prompt
tableOptionsOmit<CliTable.TableConstructorOptions, 'head' \| 'colWidths' \| 'colAligns'>Nocli-table3 options.
renderHeader(params: UseTablePaginationReturn & UseCliTableBaseOptions<TableItem>) => string \| null \| undefinedNoRender the table header.
renderFooter(params: UseTablePaginationReturn & UseCliTableBaseOptions<TableItem>) => string \| null \| undefinedNoRender the table footer.
renderFigureCell(params: RenderFigureCellParams) => CliTable.CellNoRender figure cell.
renderActiveCell(value: CliTable.CellValue) => CliTable.CellValueNoRender the cell where the pointer is active.
renderSelectedCell(value: CliTable.CellValue) => CliTable.CellValueNoRender the selected cell.
renderUnSelectedCell(value: CliTable.CellValue) => CliTable.CellValueNoRender the unselected cell.