table

  • Version 6.8.0
  • Published
  • 335 kB
  • 5 dependencies
  • BSD-3-Clause license

Install

npm i table
yarn add table
pnpm add table

Overview

Formats data into a string table.

Index

Functions

function createStream

createStream: (userConfig: StreamUserConfig) => WritableStream;

    function getBorderCharacters

    getBorderCharacters: (name: string) => BorderConfig;

      function table

      table: (data: unknown[][], userConfig?: TableUserConfig) => string;

        Type Aliases

        type Alignment

        type Alignment = 'center' | 'justify' | 'left' | 'right';

          type BaseUserConfig

          type BaseUserConfig = {
          /**
          * Custom border
          */
          readonly border?: BorderUserConfig;
          /**
          * Default values for all columns. Column specific settings overwrite the default values.
          */
          readonly columnDefault?: ColumnUserConfig;
          /**
          * Column specific configuration.
          */
          readonly columns?: Indexable<ColumnUserConfig>;
          /**
          * Used to tell whether to draw a vertical line.
          * This callback is called for each non-content line of the table.
          * The default behavior is to always return true.
          */
          readonly drawVerticalLine?: DrawVerticalLine;
          };

            type BorderConfig

            type BorderConfig = Required<BorderUserConfig>;

              type BorderUserConfig

              type BorderUserConfig = {
              readonly topLeft?: string;
              readonly topRight?: string;
              readonly topBody?: string;
              readonly topJoin?: string;
              readonly bottomLeft?: string;
              readonly bottomRight?: string;
              readonly bottomBody?: string;
              readonly bottomJoin?: string;
              readonly joinLeft?: string;
              readonly joinRight?: string;
              readonly joinBody?: string;
              readonly joinJoin?: string;
              readonly joinMiddleUp?: string;
              readonly joinMiddleDown?: string;
              readonly joinMiddleLeft?: string;
              readonly joinMiddleRight?: string;
              readonly headerJoin?: string;
              readonly bodyRight?: string;
              readonly bodyLeft?: string;
              readonly bodyJoin?: string;
              };

                type CellUserConfig

                type CellUserConfig = {
                /**
                * Cell content horizontal alignment (default: left)
                */
                readonly alignment?: Alignment;
                /**
                * Cell content vertical alignment (default: top)
                */
                readonly verticalAlignment?: VerticalAlignment;
                /**
                * Number of characters are which the content will be truncated (default: Infinity)
                */
                readonly truncate?: number;
                /**
                * Cell content padding width left (default: 1)
                */
                readonly paddingLeft?: number;
                /**
                * Cell content padding width right (default: 1)
                */
                readonly paddingRight?: number;
                /**
                * If true, the text is broken at the nearest space or one of the special characters: "\|/_.,;-"
                */
                readonly wrapWord?: boolean;
                };

                  type ColumnUserConfig

                  type ColumnUserConfig = CellUserConfig & {
                  /**
                  * Column width (default: auto calculation based on the cell content)
                  */
                  readonly width?: number;
                  };

                    type DrawHorizontalLine

                    type DrawHorizontalLine = DrawLinePredicate;

                      type DrawLinePredicate

                      type DrawLinePredicate = (index: number, size: number) => boolean;

                        type DrawVerticalLine

                        type DrawVerticalLine = DrawLinePredicate;

                          type HeaderUserConfig

                          type HeaderUserConfig = Omit<ColumnUserConfig, 'verticalAlignment' | 'width'> & {
                          readonly content: string;
                          };
                          • Deprecated

                            Use spanning cell API instead

                          type Indexable

                          type Indexable<T> = {
                          readonly [index: number]: T;
                          };

                            type SpanningCellConfig

                            type SpanningCellConfig = CellUserConfig & {
                            readonly row: number;
                            readonly col: number;
                            readonly rowSpan?: number;
                            readonly colSpan?: number;
                            };

                              type StreamUserConfig

                              type StreamUserConfig = BaseUserConfig & {
                              /**
                              * The number of columns
                              */
                              readonly columnCount: number;
                              /**
                              * Default values for all columns. Column specific settings overwrite the default values.
                              */
                              readonly columnDefault: ColumnUserConfig & {
                              /**
                              * The default width for each column
                              */
                              readonly width: number;
                              };
                              };

                                type TableUserConfig

                                type TableUserConfig = BaseUserConfig & {
                                /**
                                * The header configuration
                                */
                                readonly header?: HeaderUserConfig;
                                /**
                                * Used to tell whether to draw a horizontal line.
                                * This callback is called for each non-content line of the table.
                                * The default behavior is to always return true.
                                */
                                readonly drawHorizontalLine?: DrawHorizontalLine;
                                /**
                                * Horizontal lines inside the table are not drawn.
                                */
                                readonly singleLine?: boolean;
                                readonly spanningCells?: SpanningCellConfig[];
                                };

                                  type VerticalAlignment

                                  type VerticalAlignment = 'bottom' | 'middle' | 'top';

                                    type WritableStream

                                    type WritableStream = {
                                    readonly write: (rows: string[]) => void;
                                    };

                                      Package Files (5)

                                      Dependencies (5)

                                      Dev Dependencies (25)

                                      Peer Dependencies (0)

                                      No peer dependencies.

                                      Badge

                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/table.

                                      • Markdown
                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/table)
                                      • HTML
                                        <a href="https://www.jsdocs.io/package/table"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>