tablegger
Version:
Table logger
108 lines (105 loc) • 2.14 kB
TypeScript
interface UserOptionType {
table?: TableType;
cell?: CellType;
}
interface TableType {
/**
* Is need a border
* @default true
*/
border?: boolean;
}
interface CellType {
/**
* @default center
*/
align?: 'left' | 'right' | 'center';
/**
* The left and right margins of the cell
* @default 0 (character)
*/
paddingX?: number;
/**
* The top and bome margins of the cell
* @default 0 (line)
*/
paddingY?: number;
/**
* Valid when table.border is `false`!
* @default 0
*/
gapX?: number;
}
type PrimaryType = string | number | boolean;
declare class Tablegger {
private option;
/**
* User's data source
*/
private data;
/**
* Current row index
*/
private i;
/**
* Current column index
*/
private j;
/**
* Maximum valid character width for each column
*/
private columnsWidth;
/**
* Output result
*/
private result;
/**
* Columns for table
* Must be set by `SetColumn` or `SetHeader`
* @default 3
*/
private column;
constructor(option?: Partial<UserOptionType>);
private push;
private calcColumnsWidth;
private addBorderHeader;
private addBorderRow;
private addPaddingYRow;
private addBorderFooter;
/**
* Add table elements
* @param words
*/
add(words?: PrimaryType | PrimaryType[]): this;
/**
* Set table header
* @param words
*/
setHeader(words: PrimaryType[]): this;
/**
* Set the number of table columns
* @param column
*/
setColumn(column: number): this;
/**
* Modify data at a location
* @param i Abscissa
* @param j Ordinate
* @param word your data
*/
set(i: number, j: number, word: string): this;
/**
* Override config
* @param option
*/
setConfig(option?: Partial<UserOptionType>): this;
/**
* Get raw data
*/
get rawData(): string[][];
/**
* Generate result
*/
toString(): string;
}
export { Tablegger };