UNPKG

@juparog/print-table

Version:

print-table is a simple library that allows you to print beautiful and customizable tables in the console using ANSI escape codes. It is ideal for displaying tabular data in a clear and visually appealing way.

77 lines (76 loc) 3.38 kB
import { AlignmentText } from './constants'; import { BackgroundColor, BackgroundColorFunc, Color, ColorFunc, ColumnStyle, SelectModeFunc } from './types'; /** * Generate the ANSI sequence code for a given mode. * @param args - The mode to be applied. * @returns - The ANSI sequence code. */ export declare function SequenceBuilder(...args: string[]): string; /** * Generate the ANSI sequence code for a given mode. * @param select - The mode to be applied. * @param value - The value to be formatted. * @param mode - The mode to be applied. * @returns - The ANSI sequence code. */ export declare function SequenceModeCode(select: boolean | SelectModeFunc | undefined, value: string, mode: string): string; /** * Generate the ANSI sequence code for a given color. * @param select - The color to be applied. * @param value - The value to be formatted. * @returns - The ANSI sequence code. */ export declare function SequenceColorCode(select: Color | ColorFunc | BackgroundColor | BackgroundColorFunc | undefined, value: string): string; /** * Generate the ANSI sequence code for a given value and options. * @param value - The value to be formatted. * @param options - The options to be applied to the value. * @returns - The ANSI sequence code. */ export declare function SequenceCodeBuilder(value: string, options: ColumnStyle): string; /** * Truncates a text to a specified maximum length and appends an ellipsis if truncated. * @param text - The input text to be truncated. * @param maxLength - The maximum length of the truncated text. * @returns The truncated text. */ export declare function truncateText(text: string, maxLength: number): string; /** * Remove ANSI codes from a string. * @param input - The input string. * @returns The string without ANSI codes. */ export declare function removeANSICodes(input: string): string; /** * Combine the matrices in `data` exchanging rows for columns and * joining the elements of each row with separator. * * @param {string[][]} data - The array of data to combine. * @param {string} separator - The separator to join the elements of each row. * @returns {string[]} - The array resulting from the combination. */ export declare function combineArrays(data: string[][], separator: string): string[]; /** * Get the padding for a string. * @param value - The string to be padded. * @param width - The width of the padding. * @param char - The character to use for padding. * @returns The padding string. */ export declare function getPadding(value: string, width: number, char: string): string; /** * Aligns a text to the left, right, or center. * @param value - The string to be aligned. * @param padding - The padding to be added. * @param align - The alignment of the text. Default: `AlignmentText.LEFT`. * @returns The aligned text. */ export declare function alignHorizontalText(value: string, padding: string, align?: AlignmentText): string; /** * Pads an array of cell fragments to a specified length with alignment. * @param cellFragments - An array of cell fragments. * @param length - The desired length of the resulting array. * @param align - The alignment for padding. Default: `AlignmentText.TOP`. * @returns A new array with padded cell fragments. */ export declare function padArrayWithAling(cellFragments: string[], length: number, align?: AlignmentText): string[];