mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
feat(table): update type definitions for v5.0 (#43425)
This commit is contained in:
Vendored
+25
-18
@@ -1,21 +1,13 @@
|
||||
// Type definitions for table 4.0
|
||||
// Type definitions for table 5.0
|
||||
// Project: https://github.com/gajus/table
|
||||
// Definitions by: Evan Shortiss <https://github.com/evanshortiss>
|
||||
// mrmlnc <https://github.com/mrmlnc>
|
||||
// Daniel Perez Alvarez <https://github.com/unindented>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export type BorderType = 'honeywell' | 'norc' | 'ramac' | 'void';
|
||||
export type TableBorderTemplate = 'honeywell' | 'norc' | 'ramac' | 'void';
|
||||
|
||||
export interface ColumnConfig {
|
||||
alignment?: 'left' | 'center' | 'right';
|
||||
paddingLeft?: number;
|
||||
paddingRight?: number;
|
||||
truncate?: number;
|
||||
width?: number;
|
||||
wrapWord?: boolean;
|
||||
}
|
||||
|
||||
export interface JoinStruct {
|
||||
export interface TableBorder {
|
||||
topBody?: string;
|
||||
topJoin?: string;
|
||||
topLeft?: string;
|
||||
@@ -36,19 +28,34 @@ export interface JoinStruct {
|
||||
joinJoin?: string;
|
||||
}
|
||||
|
||||
export interface TableColumns {
|
||||
alignment?: 'left' | 'center' | 'right';
|
||||
paddingLeft?: number;
|
||||
paddingRight?: number;
|
||||
truncate?: number;
|
||||
width?: number;
|
||||
wrapWord?: boolean;
|
||||
}
|
||||
|
||||
export type TableDrawHorizontalLine = (index: number, size: number) => boolean;
|
||||
|
||||
export interface TableUserConfig {
|
||||
border?: TableBorder;
|
||||
columns?: {
|
||||
[index: number]: ColumnConfig
|
||||
[index: number]: TableColumns;
|
||||
};
|
||||
drawHorizontalLine?: (index: number, size: number) => boolean;
|
||||
border?: JoinStruct;
|
||||
columnDefault?: ColumnConfig;
|
||||
columnDefault?: TableColumns;
|
||||
columnCount?: number;
|
||||
drawHorizontalLine?: TableDrawHorizontalLine;
|
||||
singleLine?: boolean;
|
||||
}
|
||||
|
||||
export interface TableStream {
|
||||
write(row: string[]): void;
|
||||
}
|
||||
|
||||
export function table(data: any[], userConfig?: TableUserConfig): string;
|
||||
|
||||
export function createStream(userConfig: TableUserConfig): { write: string[] };
|
||||
export function createStream(userConfig: TableUserConfig): TableStream;
|
||||
|
||||
export function getBorderCharacters(templateName: BorderType): JoinStruct;
|
||||
export function getBorderCharacters(templateName: TableBorderTemplate): TableBorder;
|
||||
|
||||
@@ -1,17 +1,35 @@
|
||||
import * as table from 'table';
|
||||
|
||||
const border: table.JoinStruct = table.getBorderCharacters('norc');
|
||||
const border: table.TableBorder = table.getBorderCharacters('norc');
|
||||
|
||||
const data = [
|
||||
['first name', 'last name'],
|
||||
['jane', 'doe'],
|
||||
['john', 'doe']
|
||||
['john', 'doe'],
|
||||
];
|
||||
|
||||
const config: table.TableUserConfig = {
|
||||
border,
|
||||
columnCount: 1,
|
||||
drawHorizontalLine: () => true
|
||||
columnDefault: {
|
||||
width: 50,
|
||||
},
|
||||
columnCount: 3,
|
||||
columns: {
|
||||
0: {
|
||||
width: 10,
|
||||
alignment: 'right',
|
||||
},
|
||||
1: {
|
||||
alignment: 'center',
|
||||
},
|
||||
2: {
|
||||
width: 10,
|
||||
},
|
||||
},
|
||||
drawHorizontalLine: (index, size) => index === 0 || index === 1 || index === size - 1 || index === size,
|
||||
};
|
||||
|
||||
table.table(data, config);
|
||||
|
||||
const stream = table.createStream(config);
|
||||
stream.write(['john', 'john']);
|
||||
|
||||
Reference in New Issue
Block a user