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
@@ -1,3 +1,2 @@
1
1
  import type { BorderConfig } from './types/api';
2
- declare const _default: (name: string) => BorderConfig;
3
- export default _default;
2
+ export declare const getBorderCharacters: (name: string) => BorderConfig;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  /* eslint-disable sort-keys-fix/sort-keys-fix */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.default = (name) => {
4
+ exports.getBorderCharacters = void 0;
5
+ const getBorderCharacters = (name) => {
5
6
  if (name === 'honeywell') {
6
7
  return {
7
8
  topBody: '═',
@@ -80,3 +81,4 @@ exports.default = (name) => {
80
81
  }
81
82
  throw new Error('Unknown border template "' + name + '".');
82
83
  };
84
+ exports.getBorderCharacters = getBorderCharacters;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import createStream from './createStream';
2
- import getBorderCharacters from './getBorderCharacters';
3
- import table from './table';
1
+ import { createStream } from './createStream';
2
+ import { getBorderCharacters } from './getBorderCharacters';
3
+ import { table } from './table';
4
4
  export { table, createStream, getBorderCharacters, };
5
5
  export * from './types/api';
package/dist/index.js CHANGED
@@ -9,15 +9,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
12
  Object.defineProperty(exports, "__esModule", { value: true });
16
13
  exports.getBorderCharacters = exports.createStream = exports.table = void 0;
17
- const createStream_1 = __importDefault(require("./createStream"));
18
- exports.createStream = createStream_1.default;
19
- const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters"));
20
- exports.getBorderCharacters = getBorderCharacters_1.default;
21
- const table_1 = __importDefault(require("./table"));
22
- exports.table = table_1.default;
14
+ const createStream_1 = require("./createStream");
15
+ Object.defineProperty(exports, "createStream", { enumerable: true, get: function () { return createStream_1.createStream; } });
16
+ const getBorderCharacters_1 = require("./getBorderCharacters");
17
+ Object.defineProperty(exports, "getBorderCharacters", { enumerable: true, get: function () { return getBorderCharacters_1.getBorderCharacters; } });
18
+ const table_1 = require("./table");
19
+ Object.defineProperty(exports, "table", { enumerable: true, get: function () { return table_1.table; } });
23
20
  __exportStar(require("./types/api"), exports);
@@ -1,8 +1,7 @@
1
1
  import type { TableUserConfig } from './types/api';
2
2
  import type { Row, TableConfig } from './types/internal';
3
- declare const _default: (rows: Row[], userConfig?: TableUserConfig) => TableConfig;
4
3
  /**
5
4
  * Makes a new configuration object out of the userConfig object
6
5
  * using default values for the missing configuration properties.
7
6
  */
8
- export default _default;
7
+ export declare const makeConfig: (rows: Row[], userConfig?: TableUserConfig) => TableConfig;
@@ -3,35 +3,27 @@ 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.makeConfig = void 0;
6
7
  const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
7
- const calculateMaximumColumnWidthIndex_1 = __importDefault(require("./calculateMaximumColumnWidthIndex"));
8
- const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters"));
9
- const validateConfig_1 = __importDefault(require("./validateConfig"));
10
- /**
11
- * Merges user provided border characters with the default border ("honeywell") characters.
12
- */
13
- const makeBorder = (border) => {
14
- return {
15
- ...getBorderCharacters_1.default('honeywell'),
16
- ...border,
17
- };
18
- };
8
+ const calculateColumnWidths_1 = __importDefault(require("./calculateColumnWidths"));
9
+ const utils_1 = require("./utils");
10
+ const validateConfig_1 = require("./validateConfig");
19
11
  /**
20
12
  * Creates a configuration for every column using default
21
13
  * values for the missing configuration properties.
22
14
  */
23
15
  const makeColumns = (rows, columns, columnDefault) => {
24
- const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex_1.default(rows);
25
- return rows[0].map((_cell, index) => {
16
+ const columnWidths = calculateColumnWidths_1.default(rows);
17
+ return rows[0].map((_, columnIndex) => {
26
18
  return {
27
19
  alignment: 'left',
28
20
  paddingLeft: 1,
29
21
  paddingRight: 1,
30
22
  truncate: Number.POSITIVE_INFINITY,
31
- width: maximumColumnWidthIndex[index],
23
+ width: columnWidths[columnIndex],
32
24
  wrapWord: false,
33
25
  ...columnDefault,
34
- ...columns === null || columns === void 0 ? void 0 : columns[index],
26
+ ...columns === null || columns === void 0 ? void 0 : columns[columnIndex],
35
27
  };
36
28
  });
37
29
  };
@@ -39,13 +31,13 @@ const makeColumns = (rows, columns, columnDefault) => {
39
31
  * Makes a new configuration object out of the userConfig object
40
32
  * using default values for the missing configuration properties.
41
33
  */
42
- exports.default = (rows, userConfig = {}) => {
34
+ const makeConfig = (rows, userConfig = {}) => {
43
35
  var _a, _b, _c;
44
- validateConfig_1.default('config.json', userConfig);
36
+ validateConfig_1.validateConfig('config.json', userConfig);
45
37
  const config = lodash_clonedeep_1.default(userConfig);
46
38
  return {
47
39
  ...config,
48
- border: makeBorder(config.border),
40
+ border: utils_1.makeBorder(config.border),
49
41
  columns: makeColumns(rows, config.columns, config.columnDefault),
50
42
  drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => {
51
43
  return true;
@@ -56,3 +48,4 @@ exports.default = (rows, userConfig = {}) => {
56
48
  singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false,
57
49
  };
58
50
  };
51
+ exports.makeConfig = makeConfig;
@@ -1,8 +1,7 @@
1
1
  import type { StreamUserConfig } from './types/api';
2
2
  import type { StreamConfig } from './types/internal';
3
- declare const _default: (userConfig: StreamUserConfig) => StreamConfig;
4
3
  /**
5
4
  * Makes a new configuration object out of the userConfig object
6
5
  * using default values for the missing configuration properties.
7
6
  */
8
- export default _default;
7
+ export declare const makeStreamConfig: (userConfig: StreamUserConfig) => StreamConfig;
@@ -3,19 +3,10 @@ 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.makeStreamConfig = void 0;
6
7
  const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
7
- const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters"));
8
- const validateConfig_1 = __importDefault(require("./validateConfig"));
9
- /**
10
- * Merges user provided border characters with the default border ("honeywell") characters.
11
- *
12
- */
13
- const makeBorder = (border) => {
14
- return {
15
- ...getBorderCharacters_1.default('honeywell'),
16
- ...border,
17
- };
18
- };
8
+ const utils_1 = require("./utils");
9
+ const validateConfig_1 = require("./validateConfig");
19
10
  /**
20
11
  * Creates a configuration for every column using default
21
12
  * values for the missing configuration properties.
@@ -37,19 +28,16 @@ const makeColumns = (columnCount, columns = {}, columnDefault) => {
37
28
  * Makes a new configuration object out of the userConfig object
38
29
  * using default values for the missing configuration properties.
39
30
  */
40
- exports.default = (userConfig) => {
31
+ const makeStreamConfig = (userConfig) => {
41
32
  var _a;
42
- validateConfig_1.default('streamConfig.json', userConfig);
33
+ validateConfig_1.validateConfig('streamConfig.json', userConfig);
43
34
  const config = lodash_clonedeep_1.default(userConfig);
44
- if (!config.columnDefault || !config.columnDefault.width) {
35
+ if (config.columnDefault.width === undefined) {
45
36
  throw new Error('Must provide config.columnDefault.width when creating a stream.');
46
37
  }
47
- if (!config.columnCount) {
48
- throw new Error('Must provide config.columnCount.');
49
- }
50
38
  return {
51
39
  ...config,
52
- border: makeBorder(config.border),
40
+ border: utils_1.makeBorder(config.border),
53
41
  columnCount: config.columnCount,
54
42
  columns: makeColumns(config.columnCount, config.columns, config.columnDefault),
55
43
  drawVerticalLine: (_a = config.drawVerticalLine) !== null && _a !== void 0 ? _a : (() => {
@@ -57,3 +45,4 @@ exports.default = (userConfig) => {
57
45
  }),
58
46
  };
59
47
  };
48
+ exports.makeStreamConfig = makeStreamConfig;
@@ -0,0 +1,2 @@
1
+ import type { BaseConfig, Row } from './types/internal';
2
+ export declare const mapDataUsingRowHeights: (unmappedRows: Row[], rowHeights: number[], config: BaseConfig) => Row[];
@@ -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
+ exports.mapDataUsingRowHeights = void 0;
7
+ const lodash_flatten_1 = __importDefault(require("lodash.flatten"));
8
+ const wrapCell_1 = require("./wrapCell");
9
+ const mapDataUsingRowHeights = (unmappedRows, rowHeights, config) => {
10
+ const tableWidth = unmappedRows[0].length;
11
+ const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => {
12
+ const outputRowHeight = rowHeights[unmappedRowIndex];
13
+ const outputRow = Array.from({ length: outputRowHeight }, () => {
14
+ return new Array(tableWidth).fill('');
15
+ });
16
+ // rowHeight
17
+ // [{row index within rowSaw; index2}]
18
+ // [{cell index within a virtual row; index1}]
19
+ unmappedRow.forEach((cell, cellIndex) => {
20
+ const cellLines = wrapCell_1.wrapCell(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
21
+ cellLines.forEach((cellLine, cellLineIndex) => {
22
+ outputRow[cellLineIndex][cellIndex] = cellLine;
23
+ });
24
+ });
25
+ return outputRow;
26
+ });
27
+ return lodash_flatten_1.default(mappedRows);
28
+ };
29
+ exports.mapDataUsingRowHeights = mapDataUsingRowHeights;
@@ -1,3 +1,2 @@
1
1
  import type { BaseConfig, Row } from './types/internal';
2
- declare const _default: (rows: Row[], config: BaseConfig) => Row[];
3
- export default _default;
2
+ export declare const padTableData: (rows: Row[], config: BaseConfig) => Row[];
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (rows, config) => {
3
+ exports.padTableData = void 0;
4
+ const padTableData = (rows, config) => {
4
5
  return rows.map((cells) => {
5
- return cells.map((value, index1) => {
6
- const column = config.columns[index1];
7
- return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight);
6
+ return cells.map((cell, cellIndex) => {
7
+ const column = config.columns[cellIndex];
8
+ return ' '.repeat(column.paddingLeft) + cell + ' '.repeat(column.paddingRight);
8
9
  });
9
10
  });
10
11
  };
12
+ exports.padTableData = padTableData;
@@ -1,3 +1,2 @@
1
1
  import type { Row } from './types/internal';
2
- declare const _default: (rows: unknown[][]) => Row[];
3
- export default _default;
2
+ export declare const stringifyTableData: (rows: unknown[][]) => Row[];
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (rows) => {
3
+ exports.stringifyTableData = void 0;
4
+ const utils_1 = require("./utils");
5
+ const stringifyTableData = (rows) => {
4
6
  return rows.map((cells) => {
5
- return cells.map(String);
7
+ return cells.map((cell) => {
8
+ return utils_1.normalizeString(String(cell));
9
+ });
6
10
  });
7
11
  };
12
+ exports.stringifyTableData = stringifyTableData;
package/dist/table.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import type { TableUserConfig } from './types/api';
2
- declare const _default: (data: unknown[][], userConfig?: TableUserConfig) => string;
3
- export default _default;
2
+ export declare const table: (data: unknown[][], userConfig?: TableUserConfig) => string;
package/dist/table.js CHANGED
@@ -1,27 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const alignTableData_1 = __importDefault(require("./alignTableData"));
7
- const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex"));
8
- const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex"));
9
- const drawTable_1 = __importDefault(require("./drawTable"));
10
- const makeConfig_1 = __importDefault(require("./makeConfig"));
11
- const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex"));
12
- const padTableData_1 = __importDefault(require("./padTableData"));
13
- const stringifyTableData_1 = __importDefault(require("./stringifyTableData"));
14
- const truncateTableData_1 = __importDefault(require("./truncateTableData"));
15
- const validateTableData_1 = __importDefault(require("./validateTableData"));
16
- exports.default = (data, userConfig = {}) => {
17
- validateTableData_1.default(data);
18
- let rows = stringifyTableData_1.default(data);
19
- const config = makeConfig_1.default(rows, userConfig);
20
- rows = truncateTableData_1.default(rows, config);
21
- const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config);
22
- rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config);
23
- rows = alignTableData_1.default(rows, config);
24
- rows = padTableData_1.default(rows, config);
25
- const cellWidthIndex = calculateCellWidthIndex_1.default(rows[0]);
26
- return drawTable_1.default(rows, cellWidthIndex, rowHeightIndex, config);
3
+ exports.table = void 0;
4
+ const alignTableData_1 = require("./alignTableData");
5
+ const calculateCellWidths_1 = require("./calculateCellWidths");
6
+ const calculateRowHeights_1 = require("./calculateRowHeights");
7
+ const drawTable_1 = require("./drawTable");
8
+ const makeConfig_1 = require("./makeConfig");
9
+ const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
10
+ const padTableData_1 = require("./padTableData");
11
+ const stringifyTableData_1 = require("./stringifyTableData");
12
+ const truncateTableData_1 = require("./truncateTableData");
13
+ const validateTableData_1 = require("./validateTableData");
14
+ const table = (data, userConfig = {}) => {
15
+ validateTableData_1.validateTableData(data);
16
+ let rows = stringifyTableData_1.stringifyTableData(data);
17
+ const config = makeConfig_1.makeConfig(rows, userConfig);
18
+ rows = truncateTableData_1.truncateTableData(rows, config);
19
+ const rowHeights = calculateRowHeights_1.calculateRowHeights(rows, config);
20
+ rows = mapDataUsingRowHeights_1.mapDataUsingRowHeights(rows, rowHeights, config);
21
+ rows = alignTableData_1.alignTableData(rows, config);
22
+ rows = padTableData_1.padTableData(rows, config);
23
+ const cellWidths = calculateCellWidths_1.calculateCellWidths(rows[0]);
24
+ return drawTable_1.drawTable(rows, cellWidths, rowHeights, config);
27
25
  };
26
+ exports.table = table;
@@ -1,6 +1,5 @@
1
1
  import type { BaseConfig, Row } from './types/internal';
2
- declare const _default: (rows: Row[], config: BaseConfig) => Row[];
3
2
  /**
4
3
  * @todo Make it work with ASCII content.
5
4
  */
6
- export default _default;
5
+ export declare const truncateTableData: (rows: Row[], config: BaseConfig) => Row[];
@@ -3,17 +3,19 @@ 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.truncateTableData = void 0;
6
7
  const lodash_truncate_1 = __importDefault(require("lodash.truncate"));
7
8
  /**
8
9
  * @todo Make it work with ASCII content.
9
10
  */
10
- exports.default = (rows, config) => {
11
+ const truncateTableData = (rows, config) => {
11
12
  return rows.map((cells) => {
12
- return cells.map((content, index) => {
13
- return lodash_truncate_1.default(content, {
14
- length: config.columns[index].truncate,
13
+ return cells.map((cell, cellIndex) => {
14
+ return lodash_truncate_1.default(cell, {
15
+ length: config.columns[cellIndex].truncate,
15
16
  omission: '…',
16
17
  });
17
18
  });
18
19
  });
19
20
  };
21
+ exports.truncateTableData = truncateTableData;
@@ -19,11 +19,12 @@ export declare type BorderUserConfig = {
19
19
  readonly joinJoin?: string;
20
20
  };
21
21
  export declare type BorderConfig = Required<BorderUserConfig>;
22
+ export declare type Alignment = 'center' | 'justify' | 'left' | 'right';
22
23
  export declare type ColumnUserConfig = {
23
24
  /**
24
25
  * Cell content horizontal alignment (default: left)
25
26
  */
26
- readonly alignment?: 'center' | 'left' | 'right';
27
+ readonly alignment?: Alignment;
27
28
  /**
28
29
  * Column width (default: auto calculation based on the cell content)
29
30
  */
@@ -0,0 +1 @@
1
+ export {};
package/dist/utils.js ADDED
@@ -0,0 +1,93 @@
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
+ exports.distributeUnevenly = exports.countSpaceSequence = exports.groupBySizes = exports.makeBorder = exports.splitAnsi = exports.normalizeString = void 0;
7
+ const slice_ansi_1 = __importDefault(require("slice-ansi"));
8
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
+ const getBorderCharacters_1 = require("./getBorderCharacters");
10
+ /**
11
+ * Converts Windows-style newline to Unix-style
12
+ *
13
+ * @internal
14
+ */
15
+ const normalizeString = (input) => {
16
+ return input.replace(/\r\n/g, '\n');
17
+ };
18
+ exports.normalizeString = normalizeString;
19
+ /**
20
+ * Splits ansi string by newlines
21
+ *
22
+ * @internal
23
+ */
24
+ const splitAnsi = (input) => {
25
+ const lengths = strip_ansi_1.default(input).split('\n').map(({ length }) => {
26
+ return length;
27
+ });
28
+ const result = [];
29
+ let startIndex = 0;
30
+ lengths.forEach((length) => {
31
+ result.push(length === 0 ? '' : slice_ansi_1.default(input, startIndex, startIndex + length));
32
+ // Plus 1 for the newline character itself
33
+ startIndex += length + 1;
34
+ });
35
+ return result;
36
+ };
37
+ exports.splitAnsi = splitAnsi;
38
+ /**
39
+ * Merges user provided border characters with the default border ("honeywell") characters.
40
+ *
41
+ * @internal
42
+ */
43
+ const makeBorder = (border) => {
44
+ return {
45
+ ...getBorderCharacters_1.getBorderCharacters('honeywell'),
46
+ ...border,
47
+ };
48
+ };
49
+ exports.makeBorder = makeBorder;
50
+ /**
51
+ * Groups the array into sub-arrays by sizes.
52
+ *
53
+ * @internal
54
+ * @example
55
+ * groupBySizes(['a', 'b', 'c', 'd', 'e'], [2, 1, 2]) = [ ['a', 'b'], ['c'], ['d', 'e'] ]
56
+ */
57
+ const groupBySizes = (array, sizes) => {
58
+ let startIndex = 0;
59
+ return sizes.map((size) => {
60
+ const group = array.slice(startIndex, startIndex + size);
61
+ startIndex += size;
62
+ return group;
63
+ });
64
+ };
65
+ exports.groupBySizes = groupBySizes;
66
+ /**
67
+ * Counts the number of continuous spaces in a string
68
+ *
69
+ * @internal
70
+ * @example
71
+ * countGroupSpaces('a bc de f') = 3
72
+ */
73
+ const countSpaceSequence = (input) => {
74
+ var _a, _b;
75
+ return (_b = (_a = input.match(/\s+/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
76
+ };
77
+ exports.countSpaceSequence = countSpaceSequence;
78
+ /**
79
+ * Creates the non-increasing number array given sum and length
80
+ * whose the difference between maximum and minimum is not greater than 1
81
+ *
82
+ * @internal
83
+ * @example
84
+ * distributeUnevenly(6, 3) = [2, 2, 2]
85
+ * distributeUnevenly(8, 3) = [3, 3, 2]
86
+ */
87
+ const distributeUnevenly = (sum, length) => {
88
+ const result = Array.from({ length }).fill(Math.floor(sum / length));
89
+ return result.map((element, index) => {
90
+ return element + (index < sum % length ? 1 : 0);
91
+ });
92
+ };
93
+ exports.distributeUnevenly = distributeUnevenly;
@@ -1,3 +1,2 @@
1
1
  import type { TableUserConfig } from './types/api';
2
- declare const _default: (schemaId: 'config.json' | 'streamConfig.json', config: TableUserConfig) => void;
3
- export default _default;
2
+ export declare const validateConfig: (schemaId: 'config.json' | 'streamConfig.json', config: TableUserConfig) => void;
@@ -3,8 +3,9 @@ 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.validateConfig = void 0;
6
7
  const validators_1 = __importDefault(require("./generated/validators"));
7
- exports.default = (schemaId, config) => {
8
+ const validateConfig = (schemaId, config) => {
8
9
  const validate = validators_1.default[schemaId];
9
10
  if (!validate(config) && validate.errors) {
10
11
  const errors = validate.errors.map((error) => {
@@ -21,3 +22,4 @@ exports.default = (schemaId, config) => {
21
22
  throw new Error('Invalid config.');
22
23
  }
23
24
  };
25
+ exports.validateConfig = validateConfig;
@@ -1,2 +1 @@
1
- declare const _default: (rows: unknown[][]) => void;
2
- export default _default;
1
+ export declare const validateTableData: (rows: unknown[][]) => void;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (rows) => {
3
+ exports.validateTableData = void 0;
4
+ const utils_1 = require("./utils");
5
+ const validateTableData = (rows) => {
4
6
  if (!Array.isArray(rows)) {
5
7
  throw new TypeError('Table data must be an array.');
6
8
  }
@@ -20,9 +22,10 @@ exports.default = (rows) => {
20
22
  }
21
23
  for (const cell of row) {
22
24
  // eslint-disable-next-line no-control-regex
23
- if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
25
+ if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(utils_1.normalizeString(String(cell)))) {
24
26
  throw new Error('Table data must not contain control characters.');
25
27
  }
26
28
  }
27
29
  }
28
30
  };
31
+ exports.validateTableData = validateTableData;
@@ -1,4 +1,3 @@
1
- declare const _default: (cellValue: string, columnWidth: number, useWrapWord: boolean) => string[];
2
1
  /**
3
2
  * Wrap a single cell value into a list of lines
4
3
  *
@@ -6,4 +5,4 @@ declare const _default: (cellValue: string, columnWidth: number, useWrapWord: bo
6
5
  * depending on user configuration.
7
6
  *
8
7
  */
9
- export default _default;
8
+ export declare const wrapCell: (cellValue: string, cellWidth: number, useWrapWord: boolean) => string[];
package/dist/wrapCell.js CHANGED
@@ -1,25 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const slice_ansi_1 = __importDefault(require("slice-ansi"));
7
- const strip_ansi_1 = __importDefault(require("strip-ansi"));
8
- const wrapString_1 = __importDefault(require("./wrapString"));
9
- const wrapWord_1 = __importDefault(require("./wrapWord"));
10
- const splitAnsi = (input) => {
11
- const lengths = strip_ansi_1.default(input).split('\n').map(({ length }) => {
12
- return length;
13
- });
14
- const result = [];
15
- let startIndex = 0;
16
- lengths.forEach((length) => {
17
- result.push(length === 0 ? '' : slice_ansi_1.default(input, startIndex, startIndex + length));
18
- // Plus 1 for the newline character itself
19
- startIndex += length + 1;
20
- });
21
- return result;
22
- };
3
+ exports.wrapCell = void 0;
4
+ const utils_1 = require("./utils");
5
+ const wrapString_1 = require("./wrapString");
6
+ const wrapWord_1 = require("./wrapWord");
23
7
  /**
24
8
  * Wrap a single cell value into a list of lines
25
9
  *
@@ -27,17 +11,17 @@ const splitAnsi = (input) => {
27
11
  * depending on user configuration.
28
12
  *
29
13
  */
30
- exports.default = (cellValue, columnWidth, useWrapWord) => {
14
+ const wrapCell = (cellValue, cellWidth, useWrapWord) => {
31
15
  // First split on literal newlines
32
- const cellLines = splitAnsi(cellValue);
16
+ const cellLines = utils_1.splitAnsi(cellValue);
33
17
  // Then iterate over the list and word-wrap every remaining line if necessary.
34
18
  for (let lineNr = 0; lineNr < cellLines.length;) {
35
19
  let lineChunks;
36
20
  if (useWrapWord) {
37
- lineChunks = wrapWord_1.default(cellLines[lineNr], columnWidth);
21
+ lineChunks = wrapWord_1.wrapWord(cellLines[lineNr], cellWidth);
38
22
  }
39
23
  else {
40
- lineChunks = wrapString_1.default(cellLines[lineNr], columnWidth);
24
+ lineChunks = wrapString_1.wrapString(cellLines[lineNr], cellWidth);
41
25
  }
42
26
  // Replace our original array element with whatever the wrapping returned
43
27
  cellLines.splice(lineNr, 1, ...lineChunks);
@@ -45,3 +29,4 @@ exports.default = (cellValue, columnWidth, useWrapWord) => {
45
29
  }
46
30
  return cellLines;
47
31
  };
32
+ exports.wrapCell = wrapCell;
@@ -1,4 +1,3 @@
1
- declare const _default: (subject: string, size: number) => string[];
2
1
  /**
3
2
  * Creates an array of strings split into groups the length of size.
4
3
  * This function works with strings that contain ASCII characters.
@@ -7,4 +6,4 @@ declare const _default: (subject: string, size: number) => string[];
7
6
  * in that whitespace characters that occur on a chunk size limit are trimmed.
8
7
  *
9
8
  */
10
- export default _default;
9
+ export declare const wrapString: (subject: string, size: number) => string[];
@@ -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.wrapString = void 0;
6
7
  const slice_ansi_1 = __importDefault(require("slice-ansi"));
7
8
  const string_width_1 = __importDefault(require("string-width"));
8
9
  /**
@@ -13,7 +14,7 @@ const string_width_1 = __importDefault(require("string-width"));
13
14
  * in that whitespace characters that occur on a chunk size limit are trimmed.
14
15
  *
15
16
  */
16
- exports.default = (subject, size) => {
17
+ const wrapString = (subject, size) => {
17
18
  let subjectSlice = subject;
18
19
  const chunks = [];
19
20
  do {
@@ -22,3 +23,4 @@ exports.default = (subject, size) => {
22
23
  } while (string_width_1.default(subjectSlice));
23
24
  return chunks;
24
25
  };
26
+ exports.wrapString = wrapString;
@@ -1,2 +1 @@
1
- declare const _default: (input: string, size: number) => string[];
2
- export default _default;
1
+ export declare const wrapWord: (input: string, size: number) => string[];