Skip to content

Commit

Permalink
breaking(table): rename min/maxCellWidth to min/maxColWidth (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Aug 22, 2020
1 parent 2496431 commit c75b94c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
8 changes: 4 additions & 4 deletions command/help/help-generator.ts
Expand Up @@ -49,7 +49,7 @@ export class HelpGenerator {
[ this.cmd.getDescription() ]
] )
.indent( this.indent * 2 )
.maxCellWidth( 140 )
.maxColWidth( 140 )
.padding( 1 )
.toString() + '\n';
}
Expand All @@ -74,7 +74,7 @@ export class HelpGenerator {
] )
.padding( [ 2, 2, 2 ] )
.indent( this.indent * 2 )
.maxCellWidth( [ 60, 60, 80, 60 ] )
.maxColWidth( [ 60, 60, 80, 60 ] )
.toString() + '\n';
}

Expand All @@ -88,7 +88,7 @@ export class HelpGenerator {
] )
.padding( [ 2, 2 ] )
.indent( this.indent * 2 )
.maxCellWidth( [ 60, 80, 60 ] )
.maxColWidth( [ 60, 80, 60 ] )
.toString() + '\n';
}

Expand Down Expand Up @@ -156,7 +156,7 @@ export class HelpGenerator {
] ) )
.padding( 1 )
.indent( this.indent * 2 )
.maxCellWidth( 150 )
.maxColWidth( 150 )
.toString() + '\n';
}

Expand Down
2 changes: 1 addition & 1 deletion examples/table/table-options.ts
Expand Up @@ -9,7 +9,7 @@ new Table()
[ 'Row 2 Column 1', 'Row 2 Column 2', 'Row 2 Column 3' ],
[ 'Row 3 Column 1', 'Row 3 Column 2', 'Row 3 Column 3' ]
] )
.maxCellWidth( 10 )
.maxColWidth( 10 )
.padding( 1 )
.indent( 2 )
.border( true )
Expand Down
22 changes: 11 additions & 11 deletions table/README.md
Expand Up @@ -46,16 +46,16 @@
* [.clone()](#clone)
* [.toString()](#tostring)
* [.render()](#render)
* [.minCellWidth(width,override)](#mincellwidthwidthoverride)
* [.maxCellWidth(width,override)](#maxcellwidthwidthoverride)
* [.minColWidth(width,override)](#mincolwidthwidthoverride)
* [.maxColWidth(width,override)](#maxcolwidthwidthoverride)
* [.indent(width,override)](#indentwidthoverride)
* [.padding(padding,override)](#paddingpaddingoverride)
* [.border(enable,override)](#borderenableoverride)
* [.chars(chars)](#charschars)
* [.getHeader()](#getheader)
* [.getBody()](#getbody)
* [.getMinCellWidth()](#getmincellwidth)
* [.getMaxCellWidth()](#getmaxcellwidth)
* [.getMinColWidth()](#getmincolwidth)
* [.getMaxColWidth()](#getmaxcolwidth)
* [.getIndent()](#getindent)
* [.getPadding()](#getpadding)
* [.getBorder()](#getborder)
Expand Down Expand Up @@ -174,7 +174,7 @@ new Table()
[ 'Row 2 Column 1', 'Row 2 Column 2', 'Row 2 Column 3' ],
[ 'Row 3 Column 1', 'Row 3 Column 2', 'Row 3 Column 3' ]
] )
.maxCellWidth( 10 )
.maxColWidth( 10 )
.padding( 1 )
.indent( 2 )
.border( true )
Expand Down Expand Up @@ -275,24 +275,24 @@ Outputs the result of the `.toString()` method with `Deno.stdout.writeSnyc()`.

*Return type*: `this`

#### .minCellWidth(width,override)
#### .minColWidth(width,override)

Set min column with.

| Argument | Type | Required | Description |
| ----- | :--: | :--: | ----------- |
| width | `number | Array<number>` | Yes | Min column with. To give all columns the same min width pass a number to `.minCellWidth()`, to give each column an indiviuel min width you can pass an `Array<number>` to `.minCellWidth()`. |
| width | `number | Array<number>` | Yes | Min column with. To give all columns the same min width pass a number to `.minColWidth()`, to give each column an indiviuel min width you can pass an `Array<number>` to `.minColWidth()`. |
| override | `boolean` | No | Set override to `false` to prevent overriding existing values. |

*Return type*: `this`

#### .maxCellWidth(width,override)
#### .maxColWidth(width,override)

Set max column with.

| Argument | Type | Required | Description |
| ----- | :--: | :--: | ----------- |
| width | `number | Array<number>` | Yes | Max column with. To give all columns the same max width pass a number to `. maxCellWidth()`, to give each column an indiviuel max width you can pass an `Array<number>` to `. maxCellWidth()`. |
| width | `number | Array<number>` | Yes | Max column with. To give all columns the same max width pass a number to `. maxColWidth()`, to give each column an indiviuel max width you can pass an `Array<number>` to `. maxColWidth()`. |
| override | `boolean` | No | Set override to `false` to prevent overriding existing values. |

*Return type*: `this`
Expand Down Expand Up @@ -375,13 +375,13 @@ Returns all body rows.

*Return type*: `IRow[]`

#### .getMinCellWidth()
#### .getMinColWidth()

Get min columns width.

*Return type*: `number | number[]`

#### .getMaxCellWidth()
#### .getMaxColWidth()

Get max columns width.

Expand Down
8 changes: 4 additions & 4 deletions table/layout.ts
Expand Up @@ -53,10 +53,10 @@ export class TableLayout {
const padding: number[] = [];
const width: number[] = [];
for ( let colIndex: number = 0; colIndex < columns; colIndex++ ) {
const minCellWidth: number = Array.isArray( this.options.minCellWidth ) ? this.options.minCellWidth[ colIndex ] : this.options.minCellWidth;
const maxCellWidth: number = Array.isArray( this.options.maxCellWidth ) ? this.options.maxCellWidth[ colIndex ] : this.options.maxCellWidth;
const cellWidth: number = longest( colIndex, rows, maxCellWidth );
width[ colIndex ] = Math.min( maxCellWidth, Math.max( minCellWidth, cellWidth ) );
const minColWidth: number = Array.isArray( this.options.minColWidth ) ? this.options.minColWidth[ colIndex ] : this.options.minColWidth;
const maxColWidth: number = Array.isArray( this.options.maxColWidth ) ? this.options.maxColWidth[ colIndex ] : this.options.maxColWidth;
const colWidth: number = longest( colIndex, rows, maxColWidth );
width[ colIndex ] = Math.min( maxColWidth, Math.max( minColWidth, colWidth ) );
padding[ colIndex ] = Array.isArray( this.options.padding ) ? this.options.padding[ colIndex ] : this.options.padding;
}

Expand Down
28 changes: 14 additions & 14 deletions table/table.ts
Expand Up @@ -8,8 +8,8 @@ export interface IBorderOptions extends Partial<IBorder> {}
export interface ITableOptions {
indent?: number;
border?: boolean;
maxCellWidth?: number | number[];
minCellWidth?: number | number[];
maxColWidth?: number | number[];
minColWidth?: number | number[];
padding?: number | number[];
chars?: IBorderOptions;
}
Expand All @@ -25,8 +25,8 @@ export class Table<T extends IRow = IRow> extends Array<T> {
protected options: ITableSettings = {
indent: 0,
border: false,
maxCellWidth: Infinity,
minCellWidth: 0,
maxColWidth: Infinity,
minColWidth: 0,
padding: 1,
chars: border
};
Expand Down Expand Up @@ -83,16 +83,16 @@ export class Table<T extends IRow = IRow> extends Array<T> {
return this;
}

public maxCellWidth( width: number | number[], override: boolean = true ): this {
if ( override || typeof this.options.maxCellWidth === 'undefined' ) {
this.options.maxCellWidth = width;
public maxColWidth( width: number | number[], override: boolean = true ): this {
if ( override || typeof this.options.maxColWidth === 'undefined' ) {
this.options.maxColWidth = width;
}
return this;
}

public minCellWidth( width: number | number[], override: boolean = true ): this {
if ( override || typeof this.options.minCellWidth === 'undefined' ) {
this.options.minCellWidth = width;
public minColWidth( width: number | number[], override: boolean = true ): this {
if ( override || typeof this.options.minColWidth === 'undefined' ) {
this.options.minColWidth = width;
}
return this;
}
Expand Down Expand Up @@ -131,12 +131,12 @@ export class Table<T extends IRow = IRow> extends Array<T> {
return this.slice();
}

public getMaxCellWidth(): number | number[] {
return this.options.maxCellWidth;
public getMaxColWidth(): number | number[] {
return this.options.maxColWidth;
}

public getMinCellWidth(): number | number[] {
return this.options.minCellWidth;
public getMinColWidth(): number | number[] {
return this.options.minColWidth;
}

public getIndent(): number {
Expand Down
44 changes: 22 additions & 22 deletions table/test/table_test.ts
Expand Up @@ -23,7 +23,7 @@ Deno.test( 'simple table with word break', () => {
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'cell3 cell3' ]
] )
.maxCellWidth( 4 )
.maxColWidth( 4 )
.padding( 1 )
.toString(),
`
Expand Down Expand Up @@ -253,7 +253,7 @@ Deno.test( 'multiline table', () => {
[ 'cell1', 'cell2', 'At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
`
Stet clita kasd cell2 cell3
Expand Down Expand Up @@ -295,7 +295,7 @@ Deno.test( 'multiline border table', () => {
[ 'cell1', 'cell2', 'At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
`
Expand Down Expand Up @@ -343,23 +343,23 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
Table.from( [
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.', 'cell3' ],
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
Table.from( [
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString()
], [
Table.from( [
Expand All @@ -368,23 +368,23 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
Table.from( [
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'cell3' ],
[ 'Stet clita kasd gubergren, no sea takimata.', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
Table.from( [
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'sanctus est Lorem ipsum dolor sit.' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString()
], [
Table.from( [
Expand All @@ -393,23 +393,23 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
Table.from( [
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'accusam et justo duo.' ],
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
Table.from( [
[ 'cell1', 'cell2', 'cell3' ],
[ 'cell1', 'cell2', 'cell3' ],
[ 'Stet clita kasd gubergren, no sea takimata.', 'cell2', 'cell3' ]
] )
.padding( 1 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString()
] ] )
.padding( 1 )
Expand Down Expand Up @@ -443,7 +443,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
Table.from( [
Expand All @@ -452,7 +452,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
Table.from( [
Expand All @@ -461,7 +461,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString()
], [
Expand All @@ -471,7 +471,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
Table.from( [
Expand All @@ -480,7 +480,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'Stet clita kasd gubergren, no sea takimata.', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
Table.from( [
Expand All @@ -489,7 +489,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'sanctus est Lorem ipsum dolor sit.' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString()
], [
Expand All @@ -499,7 +499,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
Table.from( [
Expand All @@ -508,7 +508,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'cell1', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString(),
Table.from( [
Expand All @@ -517,7 +517,7 @@ Deno.test( 'nested multiline border table', () => {
[ 'Stet clita kasd gubergren, no sea takimata.', 'cell2', 'cell3' ]
] )
.padding( 0 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.border( true )
.toString()
] ] )
Expand Down Expand Up @@ -563,7 +563,7 @@ Deno.test( 'table with padding', () => {
[ 'cell1', 'cell2', 'At vero eos et accusam et justo duo dolores et ea rebum.' ]
] )
.padding( 5 )
.maxCellWidth( 20 )
.maxColWidth( 20 )
.toString(),
`
Stet clita kasd cell2 cell3
Expand Down

0 comments on commit c75b94c

Please sign in to comment.