diff --git a/types/cli-table/cli-table-tests.ts b/types/cli-table/cli-table-tests.ts new file mode 100644 index 0000000000..30d160f699 --- /dev/null +++ b/types/cli-table/cli-table-tests.ts @@ -0,0 +1,50 @@ +import Table = require('cli-table'); + +/** + * Example. + */ + +/* col widths */ +const table = new Table({ + head: ['Rel', 'Change', 'By', 'When'], + colWidths: [6, 21, 25, 17] +}); + +table.push( + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'], + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] +); + +table.toString(); + +/* compact */ +const table1 = new Table({ + head: ['Rel', 'Change', 'By', 'When'], + colWidths: [6, 21, 25, 17], + style : {compact : true, 'padding-left' : 1} +}); + +table1.push( + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'], + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'], + [], + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] +); + +/* headless */ +const headless_table = new Table(); +headless_table.push( + ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'] +); +/* vertical */ +const vertical_table = new Table(); +vertical_table.push( + { "Some Key": "Some Value"}, + { "Another much longer key": "And its corresponding longer value"} +); +/* cross */ +const cross_table = new Table({ head: ["", "Header #1", "Header #2"] }); +cross_table.push( + { "Header #3": ["Value 1", "Value 2"] }, + { "Header #4": ["Value 3", "Value 4"] } +); diff --git a/types/cli-table/index.d.ts b/types/cli-table/index.d.ts new file mode 100644 index 0000000000..a39ac2d914 --- /dev/null +++ b/types/cli-table/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for cli-table 0.3 +// Project: https://github.com/Automattic/cli-table +// Definitions by: AryloYeung +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +interface TableOptions { + chars: Partial>; + truncate: string; + colors: boolean; + colWidths: number[]; + colAligns: Array<"left" | "middle" | "right">; + style: Partial<{ + 'padding-left': number; + 'padding-right': number; + head: string[]; + border: string[]; + compact: boolean; + }>; + head: string[]; +} + +declare class Table extends Array { + constructor(options?: Partial); + toString(): string; + static version: string; +} + +export = Table; diff --git a/types/cli-table/tsconfig.json b/types/cli-table/tsconfig.json new file mode 100644 index 0000000000..50afa32769 --- /dev/null +++ b/types/cli-table/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cli-table-tests.ts" + ] +} diff --git a/types/cli-table/tslint.json b/types/cli-table/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cli-table/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }