Comparing version 3.3.0 to 3.4.0
@@ -31,1 +31,3 @@ # Table | ||
{"gitdown": "include", "file": "./usage/predefined_border_templates.md"} | ||
{"gitdown": "include", "file": "./usage/text_truncation.md"} | ||
{"gitdown": "include", "file": "./usage/text_wrapping.md"} |
@@ -29,2 +29,3 @@ ## Usage | ||
* @property {number} width Column width (default: auto). | ||
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity). | ||
* @property {number} paddingLeft Cell content padding width left (default: 1). | ||
@@ -31,0 +32,0 @@ * @property {number} paddingRight Cell content padding width right (default: 1). |
@@ -65,2 +65,3 @@ 'use strict'; | ||
width: maximumColumnWidthIndex[index], | ||
truncate: Infinity, | ||
paddingLeft: 1, | ||
@@ -67,0 +68,0 @@ paddingRight: 1 |
@@ -42,2 +42,5 @@ { | ||
}, | ||
"truncate": { | ||
"type": "number" | ||
}, | ||
"paddingLeft": { | ||
@@ -44,0 +47,0 @@ "type": "number" |
@@ -53,2 +53,6 @@ 'use strict'; | ||
var _truncateTableData = require('./truncateTableData'); | ||
var _truncateTableData2 = _interopRequireDefault(_truncateTableData); | ||
/** | ||
@@ -66,2 +70,3 @@ * @typedef {string} table~cell | ||
* @property {number} width Column width (default: auto). | ||
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity). | ||
* @property {number} paddingLeft Cell content padding width left (default: 1). | ||
@@ -130,2 +135,4 @@ * @property {number} paddingRight Cell content padding width right (default: 1). | ||
rows = (0, _truncateTableData2['default'])(data, config); | ||
rowHeightIndex = (0, _calculateRowHeightIndex2['default'])(rows, config); | ||
@@ -132,0 +139,0 @@ |
{ | ||
"name": "table", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Formats data into a string table.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
120
README.md
@@ -16,2 +16,4 @@ <h1 id="table">Table</h1> | ||
* [Predefined Border Templates](#table-usage-predefined-border-templates) | ||
* [Text Truncation](#table-usage-text-truncation) | ||
* [Text Wrapping](#table-usage-text-wrapping) | ||
@@ -61,2 +63,3 @@ | ||
* @property {number} width Column width (default: auto). | ||
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity). | ||
* @property {number} paddingLeft Cell content padding width left (default: 1). | ||
@@ -99,2 +102,3 @@ * @property {number} paddingRight Cell content padding width right (default: 1). | ||
* @property {table~columns[]} columns Column specific configuration. | ||
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values. | ||
* @property {table~drawJoin} drawJoin | ||
@@ -418,2 +422,11 @@ */ | ||
+----+----+----+ | ||
# void (no borders; see "bordless table" section of the documentation) | ||
0A 0B 0C | ||
1A 1B 1C | ||
2A 2B 2C | ||
``` | ||
@@ -423,1 +436,108 @@ | ||
<h4 id="table-usage-predefined-border-templates-borderless-table">Borderless Table</h4> | ||
Simply using "void" border character template creates a table with a lot of unnecessary spacing. | ||
To create a more plesant to the eye table, reset the padding and remove the joining rows, e.g. | ||
```js | ||
let output; | ||
output = table(data, { | ||
border: getBorderCharacters(`void`), | ||
columnDefault: { | ||
paddingLeft: 0, | ||
paddingRight: 1 | ||
}, | ||
drawJoin: () => { | ||
return false | ||
} | ||
}); | ||
console.log(output); | ||
``` | ||
``` | ||
0A 0B 0C | ||
1A 1B 1C | ||
2A 2B 2C | ||
``` | ||
<h3 id="table-usage-text-truncation">Text Truncation</h3> | ||
To handle a content that overflows the container width, `table` package implements [text wrapping](#table-usage-text-wrapping). However, sometimes you may want to truncate content that is too long to be displayed in the table. | ||
`{number} config.columns[{number}].truncate` property (default: `Infinity`) truncates the text at the specified length. | ||
```js | ||
let config, | ||
data, | ||
output; | ||
data = [ | ||
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.'] | ||
]; | ||
config = { | ||
columns: { | ||
0: { | ||
width: 20, | ||
truncate: 100 | ||
} | ||
} | ||
}; | ||
output = table(data, config); | ||
console.log(output); | ||
``` | ||
``` | ||
╔══════════════════════╗ | ||
║ Lorem ipsum dolor si ║ | ||
║ t amet, consectetur ║ | ||
║ adipiscing elit. Pha ║ | ||
║ sellus pulvinar nibh ║ | ||
║ sed mauris conva... ║ | ||
╚══════════════════════╝ | ||
``` | ||
<h3 id="table-usage-text-wrapping">Text Wrapping</h3> | ||
`table` package implements auto text wrapping, i.e. text that has width greater than the container width will be separated into multiple lines, e.g. | ||
```js | ||
let config, | ||
data, | ||
output; | ||
data = [ | ||
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.'] | ||
]; | ||
config = { | ||
columns: { | ||
0: { | ||
width: 20 | ||
} | ||
} | ||
}; | ||
output = table(data, config); | ||
console.log(output); | ||
``` | ||
``` | ||
╔══════════════════════╗ | ||
║ Lorem ipsum dolor si ║ | ||
║ t amet, consectetur ║ | ||
║ adipiscing elit. Pha ║ | ||
║ sellus pulvinar nibh ║ | ||
║ sed mauris convallis ║ | ||
║ dapibus. Nunc venena ║ | ||
║ tis tempus nulla sit ║ | ||
║ amet viverra. ║ | ||
╚══════════════════════╝ | ||
``` | ||
@@ -41,2 +41,3 @@ import _ from 'lodash'; | ||
width: maximumColumnWidthIndex[index], | ||
truncate: Infinity, | ||
paddingLeft: 1, | ||
@@ -43,0 +44,0 @@ paddingRight: 1 |
@@ -42,2 +42,5 @@ { | ||
}, | ||
"truncate": { | ||
"type": "number" | ||
}, | ||
"paddingLeft": { | ||
@@ -44,0 +47,0 @@ "type": "number" |
@@ -12,2 +12,3 @@ import _ from 'lodash'; | ||
import stringifyTableData from './stringifyTableData'; | ||
import truncateTableData from './truncateTableData'; | ||
@@ -26,2 +27,3 @@ /** | ||
* @property {number} width Column width (default: auto). | ||
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity). | ||
* @property {number} paddingLeft Cell content padding width left (default: 1). | ||
@@ -87,2 +89,4 @@ * @property {number} paddingRight Cell content padding width right (default: 1). | ||
rows = truncateTableData(data, config); | ||
rowHeightIndex = calculateRowHeightIndex(rows, config); | ||
@@ -89,0 +93,0 @@ |
@@ -20,3 +20,3 @@ import { | ||
it(`usage/column_width`, () => { | ||
it(`column_width`, () => { | ||
let config, | ||
@@ -23,0 +23,0 @@ data, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
380593
100
3126
539