Skip to content

Commit

Permalink
Merge pull request #21 from Turbo87/typing
Browse files Browse the repository at this point in the history
Import type definition from `@types/cli-table2`
  • Loading branch information
Turbo87 authored Jun 17, 2018
2 parents 174c23f + 51da150 commit 42fddf9
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
95 changes: 95 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<number | null>;
rowHeights: Array<number | null>;
colAligns: HorizontalAlignment[];
rowAligns: VerticalAlignment[];
head: string[];
wordWrap: boolean;
}

interface TableInstanceOptions extends TableOptions {
chars: Record<CharName, string>;
style: {
"padding-left": number;
"padding-right": number;
head: string[];
border: string[];
compact: boolean;
};
}

interface TableConstructorOptions extends Partial<TableOptions> {
chars?: Partial<Record<CharName, string>>;
style?: Partial<TableInstanceOptions["style"]>;
}

type CellValue = boolean | number | string | null | undefined;

interface CellOptions {
content: CellValue;
chars?: Partial<Record<CharName, string>>;
truncate?: string;
colSpan?: number;
rowSpan?: number;
hAlign?: HorizontalAlignment;
vAlign?: VerticalAlignment;
style?: {
"padding-left"?: number;
"padding-right"?: number;
head?: string[];
border?: string[];
};
}

interface GenericTable<T> extends Array<T> {
options: TableInstanceOptions;
readonly width: number;
}

type Table = HorizontalTable | VerticalTable | CrossTable;
type Cell = CellValue | CellOptions;

type HorizontalTable = GenericTable<HorizontalTableRow>;
type HorizontalTableRow = Cell[];

type VerticalTable = GenericTable<VerticalTableRow>;
interface VerticalTableRow {
[name: string]: Cell;
}

type CrossTable = GenericTable<CrossTableRow>;
interface CrossTableRow {
[name: string]: Cell[];
}
}

interface CliTable3 {
new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
readonly prototype: CliTable3.Table;
}

declare const CliTable3: CliTable3;

export = CliTable3;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 42fddf9

Please sign in to comment.