From 51da150196ef6d0b6a1ac4669f2962b63c5e60c8 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 16 Jun 2018 12:46:19 +0200 Subject: [PATCH] Import type definition from `@types/cli-table2` --- index.d.ts | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 97 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..bdf17e2 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,95 @@ +declare namespace CliTable3 { + type CharName = + "top" | + "top-mid" | + "top-left" | + "top-right" | + "bottom" | + "bottom-mid" | + "bottom-left" | + "bottom-right" | + "left" | + "left-mid" | + "mid" | + "mid-mid" | + "right" | + "right-mid" | + "middle"; + + type HorizontalAlignment = "left" | "center" | "right"; + type VerticalAlignment = "top" | "center" | "bottom"; + + interface TableOptions { + truncate: string; + colWidths: Array; + rowHeights: Array; + colAligns: HorizontalAlignment[]; + rowAligns: VerticalAlignment[]; + head: string[]; + wordWrap: boolean; + } + + interface TableInstanceOptions extends TableOptions { + chars: Record; + style: { + "padding-left": number; + "padding-right": number; + head: string[]; + border: string[]; + compact: boolean; + }; + } + + interface TableConstructorOptions extends Partial { + chars?: Partial>; + style?: Partial; + } + + type CellValue = boolean | number | string | null | undefined; + + interface CellOptions { + content: CellValue; + chars?: Partial>; + truncate?: string; + colSpan?: number; + rowSpan?: number; + hAlign?: HorizontalAlignment; + vAlign?: VerticalAlignment; + style?: { + "padding-left"?: number; + "padding-right"?: number; + head?: string[]; + border?: string[]; + }; + } + + interface GenericTable extends Array { + options: TableInstanceOptions; + readonly width: number; + } + + type Table = HorizontalTable | VerticalTable | CrossTable; + type Cell = CellValue | CellOptions; + + type HorizontalTable = GenericTable; + type HorizontalTableRow = Cell[]; + + type VerticalTable = GenericTable; + interface VerticalTableRow { + [name: string]: Cell; + } + + type CrossTable = GenericTable; + interface CrossTableRow { + [name: string]: Cell[]; + } +} + +interface CliTable3 { + new (options?: CliTable3.TableConstructorOptions): CliTable3.Table; + readonly prototype: CliTable3.Table; +} + +declare const CliTable3: CliTable3; + +export = CliTable3; diff --git a/package.json b/package.json index 010a63d..2242f15 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,10 @@ "version": "0.5.0", "description": "Pretty unicode tables for the command line. Based on the original cli-table.", "main": "index.js", + "types": "index.d.ts", "files": [ "src/", + "index.d.ts", "index.js" ], "directories": {