table 6.1.0 → 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/dist/alignString.d.ts +6 -0
  3. package/dist/alignString.js +51 -95
  4. package/dist/alignTableData.d.ts +3 -0
  5. package/dist/alignTableData.js +17 -31
  6. package/dist/calculateCellHeight.d.ts +2 -0
  7. package/dist/calculateCellHeight.js +14 -35
  8. package/dist/calculateCellWidthIndex.d.ts +6 -0
  9. package/dist/calculateCellWidthIndex.js +11 -22
  10. package/dist/calculateMaximumColumnWidthIndex.d.ts +6 -0
  11. package/dist/calculateMaximumColumnWidthIndex.js +18 -30
  12. package/dist/calculateRowHeightIndex.d.ts +6 -0
  13. package/dist/calculateRowHeightIndex.js +23 -39
  14. package/dist/createStream.d.ts +3 -0
  15. package/dist/createStream.js +65 -116
  16. package/dist/drawBorder.d.ts +25 -0
  17. package/dist/drawBorder.js +45 -106
  18. package/dist/drawHorizontalContent.d.ts +11 -0
  19. package/dist/drawHorizontalContent.js +17 -40
  20. package/dist/drawRow.d.ts +7 -0
  21. package/dist/drawRow.js +14 -39
  22. package/dist/drawTable.d.ts +3 -0
  23. package/dist/drawTable.js +33 -56
  24. package/dist/generated/validators.d.ts +13 -0
  25. package/dist/{validators.js → generated/validators.js} +309 -315
  26. package/dist/getBorderCharacters.d.ts +3 -0
  27. package/dist/getBorderCharacters.js +79 -115
  28. package/dist/{index.js.flow → index.d.ts} +2 -6
  29. package/dist/index.js +22 -30
  30. package/dist/makeConfig.d.ts +8 -0
  31. package/dist/makeConfig.js +42 -84
  32. package/dist/makeStreamConfig.d.ts +8 -0
  33. package/dist/makeStreamConfig.js +42 -90
  34. package/dist/mapDataUsingRowHeightIndex.d.ts +3 -0
  35. package/dist/mapDataUsingRowHeightIndex.js +23 -38
  36. package/dist/padTableData.d.ts +3 -0
  37. package/dist/padTableData.js +7 -20
  38. package/dist/stringifyTableData.d.ts +3 -0
  39. package/dist/stringifyTableData.js +5 -19
  40. package/dist/table.d.ts +3 -0
  41. package/dist/table.js +25 -119
  42. package/dist/truncateTableData.d.ts +6 -0
  43. package/dist/truncateTableData.js +13 -23
  44. package/dist/types/api.d.ts +100 -0
  45. package/dist/types/api.js +2 -0
  46. package/dist/types/internal.d.ts +1 -0
  47. package/dist/types/internal.js +2 -0
  48. package/dist/validateConfig.d.ts +3 -0
  49. package/dist/validateConfig.js +22 -38
  50. package/dist/validateTableData.d.ts +2 -0
  51. package/dist/validateTableData.js +23 -49
  52. package/dist/wrapCell.d.ts +9 -0
  53. package/dist/wrapCell.js +23 -38
  54. package/dist/wrapString.d.ts +10 -0
  55. package/dist/wrapString.js +14 -29
  56. package/dist/wrapWord.d.ts +2 -0
  57. package/dist/wrapWord.js +26 -44
  58. package/package.json +32 -24
  59. package/dist/alignString.js.flow +0 -97
  60. package/dist/alignTableData.js.flow +0 -21
  61. package/dist/calculateCellHeight.js.flow +0 -24
  62. package/dist/calculateCellWidthIndex.js.flow +0 -17
  63. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  64. package/dist/calculateRowHeightIndex.js.flow +0 -36
  65. package/dist/createStream.js.flow +0 -125
  66. package/dist/drawBorder.js.flow +0 -89
  67. package/dist/drawHorizontalContent.js.flow +0 -31
  68. package/dist/drawRow.js.flow +0 -29
  69. package/dist/drawTable.js.flow +0 -64
  70. package/dist/getBorderCharacters.js.flow +0 -120
  71. package/dist/makeConfig.js.flow +0 -85
  72. package/dist/makeStreamConfig.js.flow +0 -92
  73. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  74. package/dist/padTableData.js.flow +0 -14
  75. package/dist/schemas/config.json +0 -26
  76. package/dist/schemas/shared.json +0 -98
  77. package/dist/schemas/streamConfig.json +0 -23
  78. package/dist/stringifyTableData.js.flow +0 -11
  79. package/dist/table.js.flow +0 -108
  80. package/dist/truncateTableData.js.flow +0 -17
  81. package/dist/validateConfig.js.flow +0 -27
  82. package/dist/validateTableData.js.flow +0 -44
  83. package/dist/wrapCell.js.flow +0 -35
  84. package/dist/wrapString.js.flow +0 -29
  85. package/dist/wrapWord.js.flow +0 -39
@@ -1,16 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
9
-
10
- var _stringWidth = _interopRequireDefault(require("string-width"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const slice_ansi_1 = __importDefault(require("slice-ansi"));
7
+ const string_width_1 = __importDefault(require("string-width"));
14
8
  /**
15
9
  * Creates an array of strings split into groups the length of size.
16
10
  * This function works with strings that contain ASCII characters.
@@ -18,22 +12,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
12
  * wrapText is different from would-be "chunk" implementation
19
13
  * in that whitespace characters that occur on a chunk size limit are trimmed.
20
14
  *
21
- * @param {string} subject
22
- * @param {number} size
23
- * @returns {Array}
24
15
  */
25
- const wrapString = (subject, size) => {
26
- let subjectSlice;
27
- subjectSlice = subject;
28
- const chunks = [];
29
-
30
- do {
31
- chunks.push((0, _sliceAnsi.default)(subjectSlice, 0, size));
32
- subjectSlice = (0, _sliceAnsi.default)(subjectSlice, size).trim();
33
- } while ((0, _stringWidth.default)(subjectSlice));
34
-
35
- return chunks;
16
+ exports.default = (subject, size) => {
17
+ let subjectSlice = subject;
18
+ const chunks = [];
19
+ do {
20
+ chunks.push(slice_ansi_1.default(subjectSlice, 0, size));
21
+ subjectSlice = slice_ansi_1.default(subjectSlice, size).trim();
22
+ } while (string_width_1.default(subjectSlice));
23
+ return chunks;
36
24
  };
37
-
38
- var _default = wrapString;
39
- exports.default = _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: (input: string, size: number) => string[];
2
+ export default _default;
package/dist/wrapWord.js CHANGED
@@ -1,46 +1,28 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
9
-
10
- var _stringWidth = _interopRequireDefault(require("string-width"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {string} input
16
- * @param {number} size
17
- * @returns {Array}
18
- */
19
- const wrapWord = (input, size) => {
20
- let subject;
21
- subject = input;
22
- const chunks = []; // https://regex101.com/r/gY5kZ1/1
23
-
24
- const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
25
-
26
- do {
27
- let chunk;
28
- chunk = subject.match(re);
29
-
30
- if (chunk) {
31
- chunk = chunk[0];
32
- subject = (0, _sliceAnsi.default)(subject, (0, _stringWidth.default)(chunk));
33
- chunk = chunk.trim();
34
- } else {
35
- chunk = (0, _sliceAnsi.default)(subject, 0, size);
36
- subject = (0, _sliceAnsi.default)(subject, size);
37
- }
38
-
39
- chunks.push(chunk);
40
- } while ((0, _stringWidth.default)(subject));
41
-
42
- return chunks;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const slice_ansi_1 = __importDefault(require("slice-ansi"));
7
+ const string_width_1 = __importDefault(require("string-width"));
8
+ exports.default = (input, size) => {
9
+ let subject = input;
10
+ const chunks = [];
11
+ // https://regex101.com/r/gY5kZ1/1
12
+ const re = new RegExp('(^.{1,' + String(size) + '}(\\s+|$))|(^.{1,' + String(size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
13
+ do {
14
+ let chunk;
15
+ chunk = re.exec(subject);
16
+ if (chunk) {
17
+ chunk = chunk[0];
18
+ subject = slice_ansi_1.default(subject, string_width_1.default(chunk));
19
+ chunk = chunk.trim();
20
+ }
21
+ else {
22
+ chunk = slice_ansi_1.default(subject, 0, size);
23
+ subject = slice_ansi_1.default(subject, size);
24
+ }
25
+ chunks.push(chunk);
26
+ } while (string_width_1.default(subject));
27
+ return chunks;
43
28
  };
44
-
45
- var _default = wrapWord;
46
- exports.default = _default;
package/package.json CHANGED
@@ -17,32 +17,35 @@
17
17
  },
18
18
  "description": "Formats data into a string table.",
19
19
  "devDependencies": {
20
- "@babel/cli": "^7.12.10",
21
- "@babel/core": "^7.12.10",
22
- "@babel/plugin-transform-flow-strip-types": "^7.12.10",
23
- "@babel/preset-env": "^7.12.11",
24
- "@babel/register": "^7.12.10",
20
+ "@types/chai": "^4.2.16",
21
+ "@types/lodash.clonedeep": "^4.5.6",
22
+ "@types/lodash.flatten": "^4.4.6",
23
+ "@types/lodash.mapvalues": "^4.6.6",
24
+ "@types/lodash.truncate": "^4.4.6",
25
+ "@types/mocha": "^8.2.2",
26
+ "@types/node": "^14.14.37",
27
+ "@types/sinon": "^10.0.0",
28
+ "@types/slice-ansi": "^4.0.0",
25
29
  "ajv-cli": "^5.0.0",
26
30
  "ajv-keywords": "^5.0.0",
27
- "babel-plugin-istanbul": "^6.0.0",
28
- "babel-plugin-transform-export-default-name": "^2.1.0",
29
31
  "chai": "^4.2.0",
30
32
  "chalk": "^4.1.0",
31
33
  "coveralls": "^3.1.0",
32
34
  "eslint": "^7.16.0",
33
35
  "eslint-config-canonical": "^25.0.0",
34
- "flow-bin": "^0.141.0",
35
- "flow-copy-source": "^2.0.9",
36
36
  "gitdown": "^3.1.3",
37
37
  "husky": "^4.3.6",
38
38
  "js-beautify": "^1.13.0",
39
39
  "lodash.mapvalues": "^4.6.0",
40
40
  "lodash.random": "^3.2.0",
41
41
  "lodash.sample": "^4.2.1",
42
+ "mkdirp": "^1.0.4",
42
43
  "mocha": "^8.2.1",
43
44
  "nyc": "^15.1.0",
44
45
  "semantic-release": "^17.3.1",
45
- "sinon": "^9.2.2"
46
+ "sinon": "^9.2.2",
47
+ "ts-node": "^9.1.1",
48
+ "typescript": "4.2.4"
46
49
  },
47
50
  "engines": {
48
51
  "node": ">=10.0.0"
@@ -50,7 +53,7 @@
50
53
  "husky": {
51
54
  "hooks": {
52
55
  "post-commit": "npm run create-readme && git add README.md && git commit -m 'docs: generate docs' --no-verify",
53
- "pre-commit": "npm run lint && npm run test && npm run build"
56
+ "pre-commit": "npm run build && npm run lint && npm run test"
54
57
  }
55
58
  },
56
59
  "keywords": [
@@ -62,30 +65,35 @@
62
65
  ],
63
66
  "license": "BSD-3-Clause",
64
67
  "main": "./dist/index.js",
68
+ "files": [
69
+ "dist/**/*.js",
70
+ "dist/**/*.d.ts"
71
+ ],
65
72
  "name": "table",
66
73
  "nyc": {
67
- "include": [
68
- "src/**/*.js"
74
+ "extensions": [
75
+ ".ts"
76
+ ],
77
+ "exclude": [
78
+ "src/generated/validators.js",
79
+ "test/**/*.ts"
69
80
  ],
70
- "instrument": false,
71
81
  "reporter": [
72
82
  "text-lcov"
73
- ],
74
- "require": [
75
- "@babel/register"
76
- ],
77
- "sourceMap": false
83
+ ]
78
84
  },
79
85
  "repository": {
80
86
  "type": "git",
81
87
  "url": "https://github.com/gajus/table"
82
88
  },
83
89
  "scripts": {
84
- "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files && npm run create-validators && flow-copy-source src dist",
90
+ "compile": "tsc",
91
+ "prebuild": "rm -fr ./dist && mkdirp dist",
92
+ "build": "npm run create-validators && npm run compile",
85
93
  "create-readme": "gitdown ./.README/README.md --output-file ./README.md",
86
- "create-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > dist/validators.js",
87
- "lint": "npm run build && eslint ./src ./test && flow",
88
- "test": "mocha --require @babel/register"
94
+ "create-validators": "rm -fr ./src/generated && mkdirp ./src/generated && ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > ./src/generated/validators.js",
95
+ "lint": "eslint --ignore-path .gitignore ./src ./test",
96
+ "test": "npm run create-validators && mocha --require ts-node/register ./test/**/*.ts"
89
97
  },
90
- "version": "6.1.0"
98
+ "version": "6.3.2"
91
99
  }
@@ -1,97 +0,0 @@
1
- import isNumber from 'is-number-object';
2
- import isString from 'is-string';
3
- import stringWidth from 'string-width';
4
-
5
- const alignments = [
6
- 'left',
7
- 'right',
8
- 'center',
9
- ];
10
-
11
- /**
12
- * @param {string} subject
13
- * @param {number} width
14
- * @returns {string}
15
- */
16
- const alignLeft = (subject, width) => {
17
- return subject + ' '.repeat(width);
18
- };
19
-
20
- /**
21
- * @param {string} subject
22
- * @param {number} width
23
- * @returns {string}
24
- */
25
- const alignRight = (subject, width) => {
26
- return ' '.repeat(width) + subject;
27
- };
28
-
29
- /**
30
- * @param {string} subject
31
- * @param {number} width
32
- * @returns {string}
33
- */
34
- const alignCenter = (subject, width) => {
35
- let halfWidth;
36
-
37
- halfWidth = width / 2;
38
-
39
- if (width % 2 === 0) {
40
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
41
- } else {
42
- halfWidth = Math.floor(halfWidth);
43
-
44
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
45
- }
46
- };
47
-
48
- /**
49
- * Pads a string to the left and/or right to position the subject
50
- * text in a desired alignment within a container.
51
- *
52
- * @param {string} subject
53
- * @param {number} containerWidth
54
- * @param {string} alignment One of the valid options (left, right, center).
55
- * @returns {string}
56
- */
57
- export default (subject, containerWidth, alignment) => {
58
- if (!isString(subject)) {
59
- throw new TypeError('Subject parameter value must be a string.');
60
- }
61
-
62
- if (!isNumber(containerWidth)) {
63
- throw new TypeError('Container width parameter value must be a number.');
64
- }
65
-
66
- const subjectWidth = stringWidth(subject);
67
-
68
- if (subjectWidth > containerWidth) {
69
- // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
70
-
71
- throw new Error('Subject parameter value width cannot be greater than the container width.');
72
- }
73
-
74
- if (!isString(alignment)) {
75
- throw new TypeError('Alignment parameter value must be a string.');
76
- }
77
-
78
- if (!alignments.includes(alignment)) {
79
- throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
80
- }
81
-
82
- if (subjectWidth === 0) {
83
- return ' '.repeat(containerWidth);
84
- }
85
-
86
- const availableWidth = containerWidth - subjectWidth;
87
-
88
- if (alignment === 'left') {
89
- return alignLeft(subject, availableWidth);
90
- }
91
-
92
- if (alignment === 'right') {
93
- return alignRight(subject, availableWidth);
94
- }
95
-
96
- return alignCenter(subject, availableWidth);
97
- };
@@ -1,21 +0,0 @@
1
- import stringWidth from 'string-width';
2
- import alignString from './alignString';
3
-
4
- /**
5
- * @param {table~row[]} rows
6
- * @param {object} config
7
- * @returns {table~row[]}
8
- */
9
- export default (rows, config) => {
10
- return rows.map((cells) => {
11
- return cells.map((value, index1) => {
12
- const column = config.columns[index1];
13
-
14
- if (stringWidth(value) === column.width) {
15
- return value;
16
- } else {
17
- return alignString(value, column.width, column.alignment);
18
- }
19
- });
20
- });
21
- };
@@ -1,24 +0,0 @@
1
- import isString from 'is-string';
2
- import wrapCell from './wrapCell';
3
-
4
- /**
5
- * @param {string} value
6
- * @param {number} columnWidth
7
- * @param {boolean} useWrapWord
8
- * @returns {number}
9
- */
10
- export default (value, columnWidth, useWrapWord = false) => {
11
- if (!isString(value)) {
12
- throw new TypeError('Value must be a string.');
13
- }
14
-
15
- if (!Number.isInteger(columnWidth)) {
16
- throw new TypeError('Column width must be an integer.');
17
- }
18
-
19
- if (columnWidth < 1) {
20
- throw new Error('Column width must be greater than 0.');
21
- }
22
-
23
- return wrapCell(value, columnWidth, useWrapWord).length;
24
- };
@@ -1,17 +0,0 @@
1
- import stringWidth from 'string-width';
2
-
3
- /**
4
- * Calculates width of each cell contents.
5
- *
6
- * @param {string[]} cells
7
- * @returns {number[]}
8
- */
9
- export default (cells) => {
10
- return cells.map((value) => {
11
- return Math.max(
12
- ...value.split('\n').map((line) => {
13
- return stringWidth(line);
14
- }),
15
- );
16
- });
17
- };
@@ -1,27 +0,0 @@
1
- import calculateCellWidthIndex from './calculateCellWidthIndex';
2
-
3
- /**
4
- * Produces an array of values that describe the largest value length (width) in every column.
5
- *
6
- * @param {Array[]} rows
7
- * @returns {number[]}
8
- */
9
- export default (rows) => {
10
- if (!rows[0]) {
11
- throw new Error('Dataset must have at least one row.');
12
- }
13
-
14
- const columns = new Array(rows[0].length).fill(0);
15
-
16
- rows.forEach((row) => {
17
- const columnWidthIndex = calculateCellWidthIndex(row);
18
-
19
- columnWidthIndex.forEach((valueWidth, index0) => {
20
- if (columns[index0] < valueWidth) {
21
- columns[index0] = valueWidth;
22
- }
23
- });
24
- });
25
-
26
- return columns;
27
- };
@@ -1,36 +0,0 @@
1
- import isBoolean from 'is-boolean-object';
2
- import isNumber from 'is-number-object';
3
- import calculateCellHeight from './calculateCellHeight';
4
-
5
- /**
6
- * Calculates the vertical row span index.
7
- *
8
- * @param {Array[]} rows
9
- * @param {object} config
10
- * @returns {number[]}
11
- */
12
- export default (rows, config) => {
13
- const tableWidth = rows[0].length;
14
-
15
- const rowSpanIndex = [];
16
-
17
- rows.forEach((cells) => {
18
- const cellHeightIndex = new Array(tableWidth).fill(1);
19
-
20
- cells.forEach((value, index1) => {
21
- if (!isNumber(config.columns[index1].width)) {
22
- throw new TypeError('column[index].width must be a number.');
23
- }
24
-
25
- if (!isBoolean(config.columns[index1].wrapWord)) {
26
- throw new TypeError('column[index].wrapWord must be a boolean.');
27
- }
28
-
29
- cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
30
- });
31
-
32
- rowSpanIndex.push(Math.max(...cellHeightIndex));
33
- });
34
-
35
- return rowSpanIndex;
36
- };
@@ -1,125 +0,0 @@
1
- import alignTableData from './alignTableData';
2
- import calculateRowHeightIndex from './calculateRowHeightIndex';
3
- import {
4
- drawBorderBottom,
5
- drawBorderJoin,
6
- drawBorderTop,
7
- } from './drawBorder';
8
- import drawRow from './drawRow';
9
- import makeStreamConfig from './makeStreamConfig';
10
- import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
11
- import padTableData from './padTableData';
12
- import stringifyTableData from './stringifyTableData';
13
- import truncateTableData from './truncateTableData';
14
-
15
- /**
16
- * @param {Array} data
17
- * @param {streamConfig} config
18
- * @returns {Array}
19
- */
20
- const prepareData = (data, config) => {
21
- let rows;
22
-
23
- rows = stringifyTableData(data);
24
-
25
- rows = truncateTableData(rows, config);
26
-
27
- const rowHeightIndex = calculateRowHeightIndex(rows, config);
28
-
29
- rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
30
- rows = alignTableData(rows, config);
31
- rows = padTableData(rows, config);
32
-
33
- return rows;
34
- };
35
-
36
- /**
37
- * @param {string[]} row
38
- * @param {number[]} columnWidthIndex
39
- * @param {streamConfig} config
40
- * @returns {undefined}
41
- */
42
- const create = (row, columnWidthIndex, config) => {
43
- const rows = prepareData([row], config);
44
-
45
- const body = rows.map((literalRow) => {
46
- return drawRow(literalRow, config);
47
- }).join('');
48
-
49
- let output;
50
-
51
- output = '';
52
-
53
- output += drawBorderTop(columnWidthIndex, config);
54
- output += body;
55
- output += drawBorderBottom(columnWidthIndex, config);
56
-
57
- output = output.trimEnd();
58
-
59
- process.stdout.write(output);
60
- };
61
-
62
- /**
63
- * @param {string[]} row
64
- * @param {number[]} columnWidthIndex
65
- * @param {streamConfig} config
66
- * @returns {undefined}
67
- */
68
- const append = (row, columnWidthIndex, config) => {
69
- const rows = prepareData([row], config);
70
-
71
- const body = rows.map((literalRow) => {
72
- return drawRow(literalRow, config);
73
- }).join('');
74
-
75
- let output = '';
76
- const bottom = drawBorderBottom(columnWidthIndex, config);
77
-
78
- if (bottom !== '\n') {
79
- output = '\r\u001B[K';
80
- }
81
-
82
- output += drawBorderJoin(columnWidthIndex, config);
83
- output += body;
84
- output += bottom;
85
-
86
- output = output.trimEnd();
87
-
88
- process.stdout.write(output);
89
- };
90
-
91
- /**
92
- * @param {object} userConfig
93
- * @returns {object}
94
- */
95
- export default (userConfig = {}) => {
96
- const config = makeStreamConfig(userConfig);
97
-
98
- const columnWidthIndex = Object.values(config.columns).map((column) => {
99
- return column.width + column.paddingLeft + column.paddingRight;
100
- });
101
-
102
- let empty;
103
-
104
- empty = true;
105
-
106
- return {
107
- /**
108
- * @param {string[]} row
109
- * @returns {undefined}
110
- */
111
- write: (row) => {
112
- if (row.length !== config.columnCount) {
113
- throw new Error('Row cell count does not match the config.columnCount.');
114
- }
115
-
116
- if (empty) {
117
- empty = false;
118
-
119
- return create(row, columnWidthIndex, config);
120
- } else {
121
- return append(row, columnWidthIndex, config);
122
- }
123
- },
124
- };
125
- };
@@ -1,89 +0,0 @@
1
- import drawHorizontalContent from './drawHorizontalContent';
2
-
3
- /**
4
- * @typedef drawBorder~border
5
- * @property {string} left
6
- * @property {string} right
7
- * @property {string} body
8
- * @property {string} join
9
- */
10
-
11
- /**
12
- * @param {number[]} columnSizeIndex
13
- * @param {object} config
14
- * @param {drawBorder~border} config.border
15
- * @param {Function} config.drawVerticalLine
16
- * @returns {string}
17
- */
18
- const drawBorder = (columnSizeIndex, {border, drawVerticalLine}) => {
19
- const columns = columnSizeIndex.map((size) => {
20
- return border.body.repeat(size);
21
- });
22
-
23
- return drawHorizontalContent(columns, {
24
- drawVerticalLine,
25
- separator: border,
26
- });
27
- };
28
-
29
- /**
30
- * @param {number[]} columnSizeIndex
31
- * @param {table~config} config
32
- * @returns {string}
33
- */
34
- const drawBorderTop = (columnSizeIndex, {border, drawVerticalLine}) => {
35
- const result = drawBorder(columnSizeIndex, {border: {
36
- body: border.topBody,
37
- join: border.topJoin,
38
- left: border.topLeft,
39
- right: border.topRight,
40
- },
41
- drawVerticalLine});
42
-
43
- if (result === '\n') {
44
- return '';
45
- }
46
-
47
- return result;
48
- };
49
-
50
- /**
51
- * @param {number[]} columnSizeIndex
52
- * @param {table~config} config
53
- * @returns {string}
54
- */
55
- const drawBorderJoin = (columnSizeIndex, {border, drawVerticalLine}) => {
56
- return drawBorder(columnSizeIndex, {
57
- border: {
58
- body: border.joinBody,
59
- join: border.joinJoin,
60
- left: border.joinLeft,
61
- right: border.joinRight,
62
- },
63
- drawVerticalLine,
64
- });
65
- };
66
-
67
- /**
68
- * @param {number[]} columnSizeIndex
69
- * @param {table~config} config
70
- * @returns {string}
71
- */
72
- const drawBorderBottom = (columnSizeIndex, {border, drawVerticalLine}) => {
73
- return drawBorder(columnSizeIndex, {
74
- border: {
75
- body: border.bottomBody,
76
- join: border.bottomJoin,
77
- left: border.bottomLeft,
78
- right: border.bottomRight,
79
- },
80
- drawVerticalLine,
81
- });
82
- };
83
-
84
- export {
85
- drawBorder,
86
- drawBorderBottom,
87
- drawBorderJoin,
88
- drawBorderTop,
89
- };