Merge pull request #25791 from Arylo/cli-table

Add type definition for cli-table
This commit is contained in:
Ron Buckton
2018-05-18 14:49:45 -07:00
committed by GitHub
4 changed files with 119 additions and 0 deletions
+50
View File
@@ -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"] }
);
+45
View File
@@ -0,0 +1,45 @@
// Type definitions for cli-table 0.3
// Project: https://github.com/Automattic/cli-table
// Definitions by: AryloYeung <https://github.com/arylo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
interface TableOptions {
chars: Partial<Record<(
'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: Partial<{
'padding-left': number;
'padding-right': number;
head: string[];
border: string[];
compact: boolean;
}>;
head: string[];
}
declare class Table extends Array {
constructor(options?: Partial<TableOptions>);
toString(): string;
static version: string;
}
export = Table;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }