-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
843 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
##### config.header | ||
|
||
Type: `object` | ||
|
||
Header configuration. | ||
|
||
The header configuration inherits the most of the column's, except: | ||
- `content` **{string}**: the header content. | ||
- `width:` calculate based on the content width automatically. | ||
- `alignment:` `center` be default. | ||
- `config.border.topJoin` will be `config.border.topBody` for more prettier. | ||
|
||
```js | ||
const data = [ | ||
['0A', '0B', '0C'], | ||
['1A', '1B', '1C'], | ||
['2A', '2B', '2C'], | ||
]; | ||
|
||
const config = { | ||
columnDefault: { | ||
width: 10, | ||
}, | ||
header: { | ||
alignment: 'center', | ||
content: 'THE HEADER\nThis is the table about something', | ||
}, | ||
} | ||
|
||
console.log(table(data, config)); | ||
``` | ||
|
||
``` | ||
╔══════════════════════════════════════╗ | ||
║ THE HEADER ║ | ||
║ This is the table about something ║ | ||
╟────────────┬────────────┬────────────╢ | ||
║ 0A │ 0B │ 0C ║ | ||
╟────────────┼────────────┼────────────╢ | ||
║ 1A │ 1B │ 1C ║ | ||
╟────────────┼────────────┼────────────╢ | ||
║ 2A │ 2B │ 2C ║ | ||
╚════════════╧════════════╧════════════╝ | ||
``` |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
## Install | ||
|
||
```bash | ||
npm install table | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
## Usage | ||
|
||
```js | ||
import { table } from 'table'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ | |
"test/**/*.ts" | ||
], | ||
"reporter": [ | ||
"text-lcov" | ||
"text-lcov", "text" | ||
] | ||
}, | ||
"repository": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
alignString, | ||
} from './alignString'; | ||
import { | ||
drawRow, | ||
} from './drawRow'; | ||
import { | ||
padString, | ||
} from './padTableData'; | ||
import { | ||
truncateString, | ||
} from './truncateTableData'; | ||
import type { | ||
TableConfig, | ||
} from './types/internal'; | ||
import { | ||
wrapCell, | ||
} from './wrapCell'; | ||
|
||
export const drawHeader = (width: number, config: TableConfig): string => { | ||
if (!config.header) { | ||
throw new Error('Can not draw header without header configuration'); | ||
} | ||
|
||
const {alignment, paddingRight, paddingLeft, wrapWord} = config.header; | ||
|
||
let content = config.header.content; | ||
|
||
content = truncateString(content, config.header.truncate); | ||
|
||
const headerLines = wrapCell(content, width, wrapWord); | ||
|
||
return headerLines.map((headerLine) => { | ||
let line = alignString(headerLine, width, alignment); | ||
line = padString(line, paddingLeft, paddingRight); | ||
|
||
return drawRow([line], { | ||
...config, | ||
drawVerticalLine: (index) => { | ||
const columnCount = config.columns.length; | ||
|
||
return config.drawVerticalLine(index === 0 ? 0 : columnCount, columnCount); | ||
}, | ||
}); | ||
}).join(''); | ||
}; |
Oops, something went wrong.