ascii-table
ascii-table copied to clipboard
Example d.ts code for Typescript
I love this project, but for Typescript I have to write it myself every time. Here is a sample code for those looking for d.ts for Typescript.
declare module 'ascii-table' {
export default class AsciiTable {
constructor(title?: string);
setTitle(title: string): void;
setHeading(...headings: string[]): void;
addRow(...values: string[]): void;
addRow(row: string[]): void;
addRow(row: Record<string, string>): void;
addRow(row: string[], truncate: boolean): void;
addRow(row: Record<string, string>, truncate: boolean): void;
setAlign(column: number, alignment: 'left' | 'center' | 'right'): void;
setAlign(alignments: ('left' | 'center' | 'right')[]): void;
setJustify(column: number, justify: boolean): void;
setJustify(justify: boolean[]): void;
setChars(chars: Record<string, string>): void;
setStyle(style: 'default' | 'fat' | 'thin' | 'double' | 'round' | 'single'): void;
setBorder(border: boolean): void;
setTruncate(truncate: boolean): void;
setMaxColWidth(maxWidth: number): void;
setMinColWidth(minWidth: number): void;
setColWidth(column: number, width: number): void;
setColWidths(widths: number[]): void;
setDefaultColWidth(width: number): void;
setDefaultAlignment(alignment: 'left' | 'center' | 'right'): void;
setDefaultJustify(justify: boolean): void;
setDefaultTruncate(truncate: boolean): void;
setDefaultMaxColWidth(maxWidth: number): void;
setDefaultMinColWidth(minWidth: number): void;
setDefaultStyle(style: 'default' | 'fat' | 'thin' | 'double' | 'round' | 'single'): void;
setDefaultBorder(border: boolean): void;
setDefaultChars(chars: Record<string, string>): void;
toString(): string;
}
}
You saved me time, thanks!
I would like to suggest you add removeBorder(): void to the code
You saved me time, thanks! I would like to suggest you add
removeBorder(): voidto the code
You're welcome. Thanks for noticing the a missing part.
Thanks for sharing these!
One method that I noticed is missing from the list is addRowMatrix:
addRowMatrix(row: Array<unknown>): void;
Thanks for sharing these!
One method that I noticed is missing from the list is
addRowMatrix:
addRowMatrix(row: Array<unknown>): void;
Thank you for your contribution. I hope one day we can see this issue inside the library