Socket
Socket
Sign inDemoInstall

table

Package Overview
Dependencies
8
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 3.3.0

1

.README/README.md

@@ -28,3 +28,4 @@ # Table

{"gitdown": "include", "file": "./usage/custom_border.md"}
{"gitdown": "include", "file": "./usage/draw_join.md"}
{"gitdown": "include", "file": "./usage/padding_cell_content.md"}
{"gitdown": "include", "file": "./usage/predefined_border_templates.md"}

@@ -66,2 +66,3 @@ ## Usage

* @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

@@ -68,0 +69,0 @@ */

@@ -56,4 +56,42 @@ ### Predefined Border Templates

+----+----+----+
# void (no borders; see "bordless table" section of the documentation)
0A 0B 0C
1A 1B 1C
2A 2B 2C
```
Raise [an issue](https://github.com/gajus/table/issues) if you'd like to contribute a new border template.
#### Borderless Table
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
```

@@ -100,2 +100,25 @@ /**

if (name === "void") {
return {
topBody: "",
topJoin: "",
topLeft: "",
topRight: "",
bottomBody: "",
bottomJoin: "",
bottomLeft: "",
bottomRight: "",
bodyLeft: "",
bodyRight: "",
bodyJoin: "",
joinBody: "",
joinLeft: "",
joinRight: "",
joinJoin: ""
};
}
throw new Error("Unknown border template \"" + name + "\".");

@@ -102,0 +125,0 @@ };

25

dist/makeConfig.js

@@ -46,2 +46,3 @@ 'use strict';

* @param {Object} columns
* @param {Object} columnDefault
* @returns {Object}

@@ -51,2 +52,3 @@ */

var columns = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var columnDefault = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

@@ -62,17 +64,8 @@ var maximumColumnWidthIndex = undefined;

if (_lodash2['default'].isUndefined(columns[index].alignment)) {
columns[index].alignment = 'left';
}
if (_lodash2['default'].isUndefined(columns[index].width)) {
columns[index].width = maximumColumnWidthIndex[index];
}
if (_lodash2['default'].isUndefined(columns[index].paddingLeft)) {
columns[index].paddingLeft = 1;
}
if (_lodash2['default'].isUndefined(columns[index].paddingRight)) {
columns[index].paddingRight = 1;
}
columns[index] = _lodash2['default'].assign({
alignment: 'left',
width: maximumColumnWidthIndex[index],
paddingLeft: 1,
paddingRight: 1
}, columnDefault, columns[index]);
});

@@ -102,3 +95,3 @@

config.border = makeBorder(config.border);
config.columns = makeColumns(rows, config.columns);
config.columns = makeColumns(rows, config.columns, config.columnDefault);

@@ -105,0 +98,0 @@ if (!config.drawJoin) {

@@ -10,2 +10,5 @@ {

},
"columnDefault": {
"$ref": "#/definitions/column"
},
"drawJoin": {

@@ -21,23 +24,3 @@ "type": "function"

"^[0-9]+$": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center"
]
},
"width": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
"$ref": "#/definitions/column"
}

@@ -47,2 +30,25 @@ },

},
"column": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center"
]
},
"width": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
},
"borders": {

@@ -49,0 +55,0 @@ "type": "object",

@@ -102,2 +102,3 @@ 'use strict';

* @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

@@ -104,0 +105,0 @@ */

{
"name": "table",
"version": "3.2.0",
"version": "3.3.0",
"description": "Formats data into a string table.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -13,2 +13,3 @@ <h1 id="table">Table</h1>

* [Custom Border](#table-usage-custom-border)
* [Draw Join](#table-usage-draw-join)
* [Padding Cell Content](#table-usage-padding-cell-content)

@@ -84,5 +85,16 @@ * [Predefined Border Templates](#table-usage-predefined-border-templates)

/**
* Used to dynamically tell table whether to draw a line separating rows or not.
* The default behavior is to always return true.
*
* @typedef {function} drawJoin
* @param {number} index
* @param {number} size
* @return {boolean}
*/
/**
* @typedef {Object} table~config
* @property {table~border} border
* @property {table~columns[]} columns Column specific configuration.
* @property {table~drawJoin} drawJoin
*/

@@ -115,3 +127,3 @@

`config.columns[{number}].alignment` property controls content horizontal alignment within a cell.
`{string} config.columns[{number}].alignment` property controls content horizontal alignment within a cell.

@@ -165,3 +177,3 @@ Valid values are: "left", "right" and "center".

`config.columns[{number}].width` property restrictions column width to a fixed width.
`{number} config.columns[{number}].width` property restricts column width to a fixed width.

@@ -204,3 +216,3 @@ ```js

`config.border` property describes characters used to draw the table border.
`{object} config.border` property describes characters used to draw the table border.

@@ -256,5 +268,58 @@ ```js

<h3 id="table-usage-draw-join">Draw Join</h3>
`{function} config.drawJoin` property is a function that is called for every row in the table. The result of the function `{boolean}` determines whether a join/separating row is drawn.
```js
let data,
output,
options;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C'],
['3A', '3B', '3C'],
['4A', '4B', '4C']
];
options = {
/**
* Used to dynamically tell table whether to draw a line separating rows or not.
* The default behavior is to always return true.
*
* @typedef {function} drawJoin
* @param {number} index
* @param {number} size
* @return {boolean}
*/
drawJoin: (index, size) => {
// This implementation draws a separating line only after the first row
// and before the last row.
if (index === 1 || index === size - 1) {
return true;
}
}
};
output = table(data, options);
console.log(output);
```
```
╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
║ 2A │ 2B │ 2C ║
║ 3A │ 3B │ 3C ║
╟────┼────┼────╢
║ 4A │ 4B │ 4C ║
╚════╧════╧════╝
```
<h3 id="table-usage-padding-cell-content">Padding Cell Content</h3>
`config.columns[{number}].paddingLeft` and `config.columns[{number}].paddingRight` properties control content padding within a cell. Property value represents a number of whitespaces used to pad the content.
`{number} config.columns[{number}].paddingLeft` and `{number} config.columns[{number}].paddingRight` properties control content padding within a cell. Property value represents a number of whitespaces used to pad the content.

@@ -261,0 +326,0 @@ ```js

@@ -94,3 +94,26 @@ /**

if (name === `void`) {
return {
topBody: ``,
topJoin: ``,
topLeft: ``,
topRight: ``,
bottomBody: ``,
bottomJoin: ``,
bottomLeft: ``,
bottomRight: ``,
bodyLeft: ``,
bodyRight: ``,
bodyJoin: ``,
joinBody: ``,
joinLeft: ``,
joinRight: ``,
joinJoin: ``
};
}
throw new Error(`Unknown border template "${name}".`);
};

@@ -25,5 +25,6 @@ import _ from 'lodash';

* @param {Object} columns
* @param {Object} columnDefault
* @returns {Object}
*/
makeColumns = (rows, columns = {}) => {
makeColumns = (rows, columns = {}, columnDefault = {}) => {
let maximumColumnWidthIndex;

@@ -38,17 +39,8 @@

if (_.isUndefined(columns[index].alignment)) {
columns[index].alignment = `left`;
}
if (_.isUndefined(columns[index].width)) {
columns[index].width = maximumColumnWidthIndex[index];
}
if (_.isUndefined(columns[index].paddingLeft)) {
columns[index].paddingLeft = 1;
}
if (_.isUndefined(columns[index].paddingRight)) {
columns[index].paddingRight = 1;
}
columns[index] = _.assign({
alignment: `left`,
width: maximumColumnWidthIndex[index],
paddingLeft: 1,
paddingRight: 1
}, columnDefault, columns[index]);
});

@@ -75,3 +67,3 @@

config.border = makeBorder(config.border);
config.columns = makeColumns(rows, config.columns);
config.columns = makeColumns(rows, config.columns, config.columnDefault);

@@ -78,0 +70,0 @@ if (!config.drawJoin) {

@@ -10,2 +10,5 @@ {

},
"columnDefault": {
"$ref": "#/definitions/column"
},
"drawJoin": {

@@ -21,23 +24,3 @@ "type": "function"

"^[0-9]+$": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center"
]
},
"width": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
"$ref": "#/definitions/column"
}

@@ -47,2 +30,25 @@ },

},
"column": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center"
]
},
"width": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
},
"borders": {

@@ -49,0 +55,0 @@ "type": "object",

@@ -62,2 +62,3 @@ import _ from 'lodash';

* @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

@@ -64,0 +65,0 @@ */

@@ -86,2 +86,33 @@ import {

});
it(`void`, () => {
let output;
output = table(data, {
border: getBorderCharacters(`void`)
});
// console.log(output);
expectTable(_.trim(output) + `\n`, `0A 0B 0C \n\n 1A 1B 1C \n\n 2A 2B 2C`);
});
it(`borderless`, () => {
let output;
output = table(data, {
border: getBorderCharacters(`void`),
columnDefault: {
paddingLeft: 0,
paddingRight: 1
},
drawJoin: () => {
return false
}
});
// console.log(output);
expectTable(_.trim(output) + `\n`, `0A 0B 0C \n1A 1B 1C \n2A 2B 2C`);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc