diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..38e348a --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,77 @@ +type HorizontalTableRow = string[]; +type VerticalTableRow = Record; +type CrossTableRow = Record; +type TableRow = HorizontalTableRow | VerticalTableRow | CrossTableRow; + +interface TableOptions { + rows?: T[]; + chars?: { + [k in + | 'top' + | 'top-mid' + | 'top-left' + | 'top-right' + | 'bottom' + | 'bottom-mid' + | 'bottom-left' + | 'bottom-right' + | 'left' + | 'left-mid' + | 'mid' + | 'mid-mid' + | 'right' + | 'right-mid' + | 'middle']?: string; + }; + truncate?: string; + colors?: boolean; + colWidths?: number[]; + colAligns?: Array<'left' | 'middle' | 'right'>; + style?: { + 'padding-left'?: number; + 'padding-right'?: number; + head?: string[]; + border?: string[]; + compact?: boolean; + }; + head?: string[]; +} + +declare class Table extends Array { + /** + * Table constructor + * + * @param options + * @api public + */ + constructor(options?: T extends CrossTableRow ? never : TableOptions); + constructor(options: T extends CrossTableRow ? TableOptions & { head: ['', ...string[]] } : never); + + /** + * Width getter + * + * @return width + * @api public + */ + get width(): number; + + /** + * Render to a string. + * + * @return table representation + * @api public + */ + render(): string; + + /** + * Render to a string. + * + * @return table representation + * @api public + */ + toString(): string; + + static readonly version: string; +} + +export = Table; diff --git a/package.json b/package.json index 58595c5..6bd2edf 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "expresso": "~0.9", "should": "~0.6" }, - "main": "lib", + "main": "./lib/index.js", + "types": "./lib/main.d.ts", "files": ["lib"], "scripts": { "test": "make test"