table 6.0.9 → 6.3.1

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 (107) hide show
  1. package/README.md +53 -1
  2. package/dist/src/alignString.d.ts +6 -0
  3. package/dist/src/alignString.js +64 -0
  4. package/dist/src/alignTableData.d.ts +3 -0
  5. package/dist/src/alignTableData.js +21 -0
  6. package/dist/src/calculateCellHeight.d.ts +2 -0
  7. package/dist/src/calculateCellHeight.js +17 -0
  8. package/dist/src/calculateCellWidthIndex.d.ts +6 -0
  9. package/dist/src/calculateCellWidthIndex.js +17 -0
  10. package/dist/src/calculateMaximumColumnWidthIndex.d.ts +6 -0
  11. package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
  12. package/dist/src/calculateRowHeightIndex.d.ts +6 -0
  13. package/dist/src/calculateRowHeightIndex.js +30 -0
  14. package/dist/src/createStream.d.ts +3 -0
  15. package/dist/src/createStream.js +74 -0
  16. package/dist/src/drawBorder.d.ts +25 -0
  17. package/dist/src/drawBorder.js +55 -0
  18. package/dist/src/drawHorizontalContent.d.ts +11 -0
  19. package/dist/src/drawHorizontalContent.js +19 -0
  20. package/dist/src/drawRow.d.ts +7 -0
  21. package/dist/src/drawRow.js +17 -0
  22. package/dist/src/drawTable.d.ts +3 -0
  23. package/dist/src/drawTable.js +38 -0
  24. package/dist/src/getBorderCharacters.d.ts +3 -0
  25. package/dist/src/getBorderCharacters.js +83 -0
  26. package/dist/{index.js.flow → src/index.d.ts} +2 -6
  27. package/dist/src/index.js +24 -0
  28. package/dist/src/makeConfig.d.ts +8 -0
  29. package/dist/src/makeConfig.js +59 -0
  30. package/dist/src/makeStreamConfig.d.ts +8 -0
  31. package/dist/src/makeStreamConfig.js +60 -0
  32. package/dist/src/mapDataUsingRowHeightIndex.d.ts +3 -0
  33. package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
  34. package/dist/src/padTableData.d.ts +3 -0
  35. package/dist/src/padTableData.js +11 -0
  36. package/dist/src/stringifyTableData.d.ts +3 -0
  37. package/dist/src/stringifyTableData.js +8 -0
  38. package/dist/src/table.d.ts +3 -0
  39. package/dist/src/table.js +28 -0
  40. package/dist/src/truncateTableData.d.ts +6 -0
  41. package/dist/src/truncateTableData.js +20 -0
  42. package/dist/src/types/api.d.ts +100 -0
  43. package/dist/src/types/api.js +3 -0
  44. package/dist/src/types/internal.d.ts +1 -0
  45. package/dist/src/types/internal.js +3 -0
  46. package/dist/src/validateConfig.d.ts +3 -0
  47. package/dist/src/validateConfig.js +27 -0
  48. package/dist/src/validateTableData.d.ts +2 -0
  49. package/dist/src/validateTableData.js +29 -0
  50. package/dist/{validators.js → src/validators.js} +54 -14
  51. package/dist/src/wrapCell.d.ts +9 -0
  52. package/dist/src/wrapCell.js +33 -0
  53. package/dist/src/wrapString.d.ts +10 -0
  54. package/dist/src/wrapString.js +25 -0
  55. package/dist/src/wrapWord.d.ts +2 -0
  56. package/dist/src/wrapWord.js +29 -0
  57. package/package.json +32 -25
  58. package/dist/alignString.js +0 -107
  59. package/dist/alignString.js.flow +0 -97
  60. package/dist/alignTableData.js +0 -34
  61. package/dist/alignTableData.js.flow +0 -21
  62. package/dist/calculateCellHeight.js +0 -37
  63. package/dist/calculateCellHeight.js.flow +0 -24
  64. package/dist/calculateCellWidthIndex.js +0 -27
  65. package/dist/calculateCellWidthIndex.js.flow +0 -17
  66. package/dist/calculateMaximumColumnWidthIndex.js +0 -36
  67. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  68. package/dist/calculateRowHeightIndex.js +0 -45
  69. package/dist/calculateRowHeightIndex.js.flow +0 -36
  70. package/dist/createStream.js +0 -124
  71. package/dist/createStream.js.flow +0 -125
  72. package/dist/drawBorder.js +0 -109
  73. package/dist/drawBorder.js.flow +0 -101
  74. package/dist/drawRow.js +0 -25
  75. package/dist/drawRow.js.flow +0 -15
  76. package/dist/drawTable.js +0 -58
  77. package/dist/drawTable.js.flow +0 -53
  78. package/dist/getBorderCharacters.js +0 -118
  79. package/dist/getBorderCharacters.js.flow +0 -120
  80. package/dist/index.js +0 -31
  81. package/dist/makeConfig.js +0 -91
  82. package/dist/makeConfig.js.flow +0 -76
  83. package/dist/makeStreamConfig.js +0 -97
  84. package/dist/makeStreamConfig.js.flow +0 -83
  85. package/dist/mapDataUsingRowHeightIndex.js +0 -41
  86. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  87. package/dist/padTableData.js +0 -23
  88. package/dist/padTableData.js.flow +0 -14
  89. package/dist/schemas/config.json +0 -23
  90. package/dist/schemas/shared.json +0 -98
  91. package/dist/schemas/streamConfig.json +0 -20
  92. package/dist/stringifyTableData.js +0 -21
  93. package/dist/stringifyTableData.js.flow +0 -11
  94. package/dist/table.js +0 -109
  95. package/dist/table.js.flow +0 -96
  96. package/dist/truncateTableData.js +0 -29
  97. package/dist/truncateTableData.js.flow +0 -17
  98. package/dist/validateConfig.js +0 -40
  99. package/dist/validateConfig.js.flow +0 -27
  100. package/dist/validateTableData.js +0 -54
  101. package/dist/validateTableData.js.flow +0 -44
  102. package/dist/wrapCell.js +0 -47
  103. package/dist/wrapCell.js.flow +0 -35
  104. package/dist/wrapString.js +0 -39
  105. package/dist/wrapString.js.flow +0 -29
  106. package/dist/wrapWord.js +0 -46
  107. package/dist/wrapWord.js.flow +0 -39
@@ -0,0 +1,33 @@
1
+ "use strict";
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 wrapString_1 = __importDefault(require("./wrapString"));
7
+ const wrapWord_1 = __importDefault(require("./wrapWord"));
8
+ /**
9
+ * Wrap a single cell value into a list of lines
10
+ *
11
+ * Always wraps on newlines, for the remainder uses either word or string wrapping
12
+ * depending on user configuration.
13
+ *
14
+ */
15
+ exports.default = (cellValue, columnWidth, useWrapWord) => {
16
+ // First split on literal newlines
17
+ const cellLines = cellValue.split('\n');
18
+ // Then iterate over the list and word-wrap every remaining line if necessary.
19
+ for (let lineNr = 0; lineNr < cellLines.length;) {
20
+ let lineChunks;
21
+ if (useWrapWord) {
22
+ lineChunks = wrapWord_1.default(cellLines[lineNr], columnWidth);
23
+ }
24
+ else {
25
+ lineChunks = wrapString_1.default(cellLines[lineNr], columnWidth);
26
+ }
27
+ // Replace our original array element with whatever the wrapping returned
28
+ cellLines.splice(lineNr, 1, ...lineChunks);
29
+ lineNr += lineChunks.length;
30
+ }
31
+ return cellLines;
32
+ };
33
+ //# sourceMappingURL=wrapCell.js.map
@@ -0,0 +1,10 @@
1
+ declare const _default: (subject: string, size: number) => string[];
2
+ /**
3
+ * Creates an array of strings split into groups the length of size.
4
+ * This function works with strings that contain ASCII characters.
5
+ *
6
+ * wrapText is different from would-be "chunk" implementation
7
+ * in that whitespace characters that occur on a chunk size limit are trimmed.
8
+ *
9
+ */
10
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
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
+ /**
9
+ * Creates an array of strings split into groups the length of size.
10
+ * This function works with strings that contain ASCII characters.
11
+ *
12
+ * wrapText is different from would-be "chunk" implementation
13
+ * in that whitespace characters that occur on a chunk size limit are trimmed.
14
+ *
15
+ */
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;
24
+ };
25
+ //# sourceMappingURL=wrapString.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: (input: string, size: number) => string[];
2
+ export default _default;
@@ -0,0 +1,29 @@
1
+ "use strict";
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;
28
+ };
29
+ //# sourceMappingURL=wrapWord.js.map
package/package.json CHANGED
@@ -17,32 +17,34 @@
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
+ "typescript": "4.2.4"
46
48
  },
47
49
  "engines": {
48
50
  "node": ">=10.0.0"
@@ -50,7 +52,7 @@
50
52
  "husky": {
51
53
  "hooks": {
52
54
  "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"
55
+ "pre-commit": "npm run build && npm run lint && npm run test"
54
56
  }
55
57
  },
56
58
  "keywords": [
@@ -61,31 +63,36 @@
61
63
  "ansi"
62
64
  ],
63
65
  "license": "BSD-3-Clause",
64
- "main": "./dist/index.js",
66
+ "main": "./dist/src/index.js",
67
+ "files": [
68
+ "dist/src/**/*.js",
69
+ "dist/src/**/*.d.ts"
70
+ ],
65
71
  "name": "table",
66
72
  "nyc": {
67
- "include": [
68
- "src/**/*.js"
73
+ "extensions": [
74
+ ".ts"
75
+ ],
76
+ "exclude": [
77
+ "dist/src/validators.js",
78
+ "test/**/*.ts"
69
79
  ],
70
- "instrument": false,
71
80
  "reporter": [
72
81
  "text-lcov"
73
- ],
74
- "require": [
75
- "@babel/register"
76
- ],
77
- "sourceMap": false
82
+ ]
78
83
  },
79
84
  "repository": {
80
85
  "type": "git",
81
86
  "url": "https://github.com/gajus/table"
82
87
  },
83
88
  "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",
89
+ "compile": "tsc",
90
+ "prebuild": "rm -fr ./dist && mkdirp dist/src",
91
+ "build": "npm run create-validators && npm run compile",
85
92
  "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"
93
+ "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/src/validators.js",
94
+ "lint": "eslint ./src ./test",
95
+ "test": "mocha ./dist/test/**/*.js"
89
96
  },
90
- "version": "6.0.9"
97
+ "version": "6.3.1"
91
98
  }
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _isNumberObject = _interopRequireDefault(require("is-number-object"));
9
-
10
- var _isString = _interopRequireDefault(require("is-string"));
11
-
12
- var _stringWidth = _interopRequireDefault(require("string-width"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const alignments = ['left', 'right', 'center'];
17
- /**
18
- * @param {string} subject
19
- * @param {number} width
20
- * @returns {string}
21
- */
22
-
23
- const alignLeft = (subject, width) => {
24
- return subject + ' '.repeat(width);
25
- };
26
- /**
27
- * @param {string} subject
28
- * @param {number} width
29
- * @returns {string}
30
- */
31
-
32
-
33
- const alignRight = (subject, width) => {
34
- return ' '.repeat(width) + subject;
35
- };
36
- /**
37
- * @param {string} subject
38
- * @param {number} width
39
- * @returns {string}
40
- */
41
-
42
-
43
- const alignCenter = (subject, width) => {
44
- let halfWidth;
45
- halfWidth = width / 2;
46
-
47
- if (width % 2 === 0) {
48
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
49
- } else {
50
- halfWidth = Math.floor(halfWidth);
51
- return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
52
- }
53
- };
54
- /**
55
- * Pads a string to the left and/or right to position the subject
56
- * text in a desired alignment within a container.
57
- *
58
- * @param {string} subject
59
- * @param {number} containerWidth
60
- * @param {string} alignment One of the valid options (left, right, center).
61
- * @returns {string}
62
- */
63
-
64
-
65
- const alignString = (subject, containerWidth, alignment) => {
66
- if (!(0, _isString.default)(subject)) {
67
- throw new TypeError('Subject parameter value must be a string.');
68
- }
69
-
70
- if (!(0, _isNumberObject.default)(containerWidth)) {
71
- throw new TypeError('Container width parameter value must be a number.');
72
- }
73
-
74
- const subjectWidth = (0, _stringWidth.default)(subject);
75
-
76
- if (subjectWidth > containerWidth) {
77
- // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
78
- throw new Error('Subject parameter value width cannot be greater than the container width.');
79
- }
80
-
81
- if (!(0, _isString.default)(alignment)) {
82
- throw new TypeError('Alignment parameter value must be a string.');
83
- }
84
-
85
- if (!alignments.includes(alignment)) {
86
- throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
87
- }
88
-
89
- if (subjectWidth === 0) {
90
- return ' '.repeat(containerWidth);
91
- }
92
-
93
- const availableWidth = containerWidth - subjectWidth;
94
-
95
- if (alignment === 'left') {
96
- return alignLeft(subject, availableWidth);
97
- }
98
-
99
- if (alignment === 'right') {
100
- return alignRight(subject, availableWidth);
101
- }
102
-
103
- return alignCenter(subject, availableWidth);
104
- };
105
-
106
- var _default = alignString;
107
- exports.default = _default;
@@ -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,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stringWidth = _interopRequireDefault(require("string-width"));
9
-
10
- var _alignString = _interopRequireDefault(require("./alignString"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {table~row[]} rows
16
- * @param {object} config
17
- * @returns {table~row[]}
18
- */
19
- const alignTableData = (rows, config) => {
20
- return rows.map(cells => {
21
- return cells.map((value, index1) => {
22
- const column = config.columns[index1];
23
-
24
- if ((0, _stringWidth.default)(value) === column.width) {
25
- return value;
26
- } else {
27
- return (0, _alignString.default)(value, column.width, column.alignment);
28
- }
29
- });
30
- });
31
- };
32
-
33
- var _default = alignTableData;
34
- exports.default = _default;
@@ -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,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _isString = _interopRequireDefault(require("is-string"));
9
-
10
- var _wrapCell = _interopRequireDefault(require("./wrapCell"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * @param {string} value
16
- * @param {number} columnWidth
17
- * @param {boolean} useWrapWord
18
- * @returns {number}
19
- */
20
- const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
21
- if (!(0, _isString.default)(value)) {
22
- throw new TypeError('Value must be a string.');
23
- }
24
-
25
- if (!Number.isInteger(columnWidth)) {
26
- throw new TypeError('Column width must be an integer.');
27
- }
28
-
29
- if (columnWidth < 1) {
30
- throw new Error('Column width must be greater than 0.');
31
- }
32
-
33
- return (0, _wrapCell.default)(value, columnWidth, useWrapWord).length;
34
- };
35
-
36
- var _default = calculateCellHeight;
37
- exports.default = _default;
@@ -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,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stringWidth = _interopRequireDefault(require("string-width"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * Calculates width of each cell contents.
14
- *
15
- * @param {string[]} cells
16
- * @returns {number[]}
17
- */
18
- const calculateCellWidthIndex = cells => {
19
- return cells.map(value => {
20
- return Math.max(...value.split('\n').map(line => {
21
- return (0, _stringWidth.default)(line);
22
- }));
23
- });
24
- };
25
-
26
- var _default = calculateCellWidthIndex;
27
- exports.default = _default;
@@ -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,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * Produces an array of values that describe the largest value length (width) in every column.
14
- *
15
- * @param {Array[]} rows
16
- * @returns {number[]}
17
- */
18
- const calculateMaximumColumnWidthIndex = rows => {
19
- if (!rows[0]) {
20
- throw new Error('Dataset must have at least one row.');
21
- }
22
-
23
- const columns = new Array(rows[0].length).fill(0);
24
- rows.forEach(row => {
25
- const columnWidthIndex = (0, _calculateCellWidthIndex.default)(row);
26
- columnWidthIndex.forEach((valueWidth, index0) => {
27
- if (columns[index0] < valueWidth) {
28
- columns[index0] = valueWidth;
29
- }
30
- });
31
- });
32
- return columns;
33
- };
34
-
35
- var _default = calculateMaximumColumnWidthIndex;
36
- exports.default = _default;
@@ -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
- };