table 6.5.1 → 6.6.0

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 (65) hide show
  1. package/README.md +20 -25
  2. package/dist/alignString.d.ts +2 -3
  3. package/dist/alignString.js +21 -4
  4. package/dist/alignTableData.d.ts +1 -2
  5. package/dist/alignTableData.js +7 -5
  6. package/dist/calculateCellHeight.d.ts +4 -2
  7. package/dist/calculateCellHeight.js +8 -9
  8. package/dist/calculateCellWidths.d.ts +5 -0
  9. package/dist/{calculateCellWidthIndex.js → calculateCellWidths.js} +6 -6
  10. package/dist/{calculateMaximumColumnWidthIndex.d.ts → calculateColumnWidths.d.ts} +0 -0
  11. package/dist/calculateColumnWidths.js +16 -0
  12. package/dist/calculateRowHeights.d.ts +5 -0
  13. package/dist/calculateRowHeights.js +18 -0
  14. package/dist/createStream.d.ts +1 -2
  15. package/dist/createStream.js +29 -30
  16. package/dist/drawBorder.d.ts +4 -4
  17. package/dist/drawBorder.js +16 -13
  18. package/dist/drawContent.d.ts +11 -0
  19. package/dist/drawContent.js +26 -0
  20. package/dist/drawRow.d.ts +1 -2
  21. package/dist/drawRow.js +11 -13
  22. package/dist/drawTable.d.ts +1 -2
  23. package/dist/drawTable.js +20 -40
  24. package/dist/generated/validators.d.ts +2 -2
  25. package/dist/generated/validators.js +282 -274
  26. package/dist/getBorderCharacters.d.ts +1 -2
  27. package/dist/getBorderCharacters.js +3 -1
  28. package/dist/index.d.ts +3 -3
  29. package/dist/index.js +6 -9
  30. package/dist/makeConfig.d.ts +1 -2
  31. package/dist/makeConfig.js +12 -19
  32. package/dist/makeStreamConfig.d.ts +1 -2
  33. package/dist/makeStreamConfig.js +8 -19
  34. package/dist/mapDataUsingRowHeights.d.ts +2 -0
  35. package/dist/mapDataUsingRowHeights.js +29 -0
  36. package/dist/padTableData.d.ts +1 -2
  37. package/dist/padTableData.js +6 -4
  38. package/dist/stringifyTableData.d.ts +1 -2
  39. package/dist/stringifyTableData.js +7 -2
  40. package/dist/table.d.ts +1 -2
  41. package/dist/table.js +23 -24
  42. package/dist/truncateTableData.d.ts +1 -2
  43. package/dist/truncateTableData.js +6 -4
  44. package/dist/types/api.d.ts +2 -1
  45. package/dist/utils.d.ts +1 -0
  46. package/dist/utils.js +93 -0
  47. package/dist/validateConfig.d.ts +1 -2
  48. package/dist/validateConfig.js +3 -1
  49. package/dist/validateTableData.d.ts +1 -2
  50. package/dist/validateTableData.js +5 -2
  51. package/dist/wrapCell.d.ts +1 -2
  52. package/dist/wrapCell.js +9 -24
  53. package/dist/wrapString.d.ts +1 -2
  54. package/dist/wrapString.js +3 -1
  55. package/dist/wrapWord.d.ts +1 -2
  56. package/dist/wrapWord.js +3 -1
  57. package/package.json +1 -1
  58. package/dist/calculateCellWidthIndex.d.ts +0 -6
  59. package/dist/calculateMaximumColumnWidthIndex.js +0 -24
  60. package/dist/calculateRowHeightIndex.d.ts +0 -6
  61. package/dist/calculateRowHeightIndex.js +0 -21
  62. package/dist/drawHorizontalContent.d.ts +0 -11
  63. package/dist/drawHorizontalContent.js +0 -18
  64. package/dist/mapDataUsingRowHeightIndex.d.ts +0 -3
  65. package/dist/mapDataUsingRowHeightIndex.js +0 -26
package/dist/wrapWord.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.wrapWord = void 0;
6
7
  const slice_ansi_1 = __importDefault(require("slice-ansi"));
7
8
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
8
9
  const calculateStringLengths = (input, size) => {
@@ -28,7 +29,7 @@ const calculateStringLengths = (input, size) => {
28
29
  } while (subject.length);
29
30
  return chunks;
30
31
  };
31
- exports.default = (input, size) => {
32
+ const wrapWord = (input, size) => {
32
33
  const result = [];
33
34
  let startIndex = 0;
34
35
  calculateStringLengths(input, size).forEach(([length, offset]) => {
@@ -37,3 +38,4 @@ exports.default = (input, size) => {
37
38
  });
38
39
  return result;
39
40
  };
41
+ exports.wrapWord = wrapWord;
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "lint": "eslint --ignore-path .gitignore ./src ./test",
92
92
  "test": "npm run create-validators && mocha --require ts-node/register ./test/**/*.ts"
93
93
  },
94
- "version": "6.5.1"
94
+ "version": "6.6.0"
95
95
  }
@@ -1,6 +0,0 @@
1
- import type { Cell } from './types/internal';
2
- declare const _default: (cells: Cell[]) => number[];
3
- /**
4
- * Calculates width of each cell contents.
5
- */
6
- export default _default;
@@ -1,24 +0,0 @@
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 calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex"));
7
- /**
8
- * Produces an array of values that describe the largest value length (width) in every column.
9
- */
10
- exports.default = (rows) => {
11
- if (!rows[0]) {
12
- throw new Error('Dataset must have at least one row.');
13
- }
14
- const columns = new Array(rows[0].length).fill(0);
15
- rows.forEach((row) => {
16
- const columnWidthIndex = calculateCellWidthIndex_1.default(row);
17
- columnWidthIndex.forEach((valueWidth, index0) => {
18
- if (columns[index0] < valueWidth) {
19
- columns[index0] = valueWidth;
20
- }
21
- });
22
- });
23
- return columns;
24
- };
@@ -1,6 +0,0 @@
1
- import type { BaseConfig, Row } from './types/internal';
2
- declare const _default: (rows: Row[], config: BaseConfig) => number[];
3
- /**
4
- * Calculates the vertical row span index.
5
- */
6
- export default _default;
@@ -1,21 +0,0 @@
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 calculateCellHeight_1 = __importDefault(require("./calculateCellHeight"));
7
- /**
8
- * Calculates the vertical row span index.
9
- */
10
- exports.default = (rows, config) => {
11
- const tableWidth = rows[0].length;
12
- const rowSpanIndex = [];
13
- rows.forEach((cells) => {
14
- const cellHeightIndex = new Array(tableWidth).fill(1);
15
- cells.forEach((value, index1) => {
16
- cellHeightIndex[index1] = calculateCellHeight_1.default(value, config.columns[index1].width, config.columns[index1].wrapWord);
17
- });
18
- rowSpanIndex.push(Math.max(...cellHeightIndex));
19
- });
20
- return rowSpanIndex;
21
- };
@@ -1,11 +0,0 @@
1
- import type { DrawVerticalLine } from './types/api';
2
- declare type Separator = {
3
- readonly left: string;
4
- readonly right: string;
5
- readonly join: string;
6
- };
7
- export default function drawHorizontalContent(contents: string[], config: {
8
- separator: Separator;
9
- drawVerticalLine: DrawVerticalLine;
10
- }): string;
11
- export {};
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function drawHorizontalContent(contents, config) {
4
- const { separator, drawVerticalLine } = config;
5
- const contentSize = contents.length;
6
- const result = [];
7
- result.push(drawVerticalLine(0, contentSize) ? separator.left : '');
8
- contents.forEach((content, index) => {
9
- result.push(content);
10
- // Only append the join separator if it is not the last content
11
- if (index + 1 < contentSize) {
12
- result.push(drawVerticalLine(index + 1, contentSize) ? separator.join : '');
13
- }
14
- });
15
- result.push(drawVerticalLine(contentSize, contentSize) ? separator.right : '');
16
- return result.join('') + '\n';
17
- }
18
- exports.default = drawHorizontalContent;
@@ -1,3 +0,0 @@
1
- import type { BaseConfig, Row } from './types/internal';
2
- declare const _default: (unmappedRows: Row[], rowHeightIndex: number[], config: BaseConfig) => Row[];
3
- export default _default;
@@ -1,26 +0,0 @@
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 lodash_flatten_1 = __importDefault(require("lodash.flatten"));
7
- const wrapCell_1 = __importDefault(require("./wrapCell"));
8
- exports.default = (unmappedRows, rowHeightIndex, config) => {
9
- const tableWidth = unmappedRows[0].length;
10
- const mappedRows = unmappedRows.map((row, index0) => {
11
- const rowHeight = Array.from({ length: rowHeightIndex[index0] }, () => {
12
- return new Array(tableWidth).fill('');
13
- });
14
- // rowHeight
15
- // [{row index within rowSaw; index2}]
16
- // [{cell index within a virtual row; index1}]
17
- row.forEach((cell, index1) => {
18
- const cellLines = wrapCell_1.default(cell, config.columns[index1].width, config.columns[index1].wrapWord);
19
- cellLines.forEach((cellLine, index2) => {
20
- rowHeight[index2][index1] = cellLine;
21
- });
22
- });
23
- return rowHeight;
24
- });
25
- return lodash_flatten_1.default(mappedRows);
26
- };