table 6.2.0 → 6.3.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 (84) hide show
  1. package/README.md +1 -1
  2. package/dist/src/alignString.js +64 -0
  3. package/dist/src/alignTableData.js +21 -0
  4. package/dist/src/calculateCellHeight.js +17 -0
  5. package/dist/src/calculateCellWidthIndex.js +17 -0
  6. package/dist/src/calculateMaximumColumnWidthIndex.js +25 -0
  7. package/dist/src/calculateRowHeightIndex.js +30 -0
  8. package/dist/src/createStream.js +74 -0
  9. package/dist/src/drawBorder.js +55 -0
  10. package/dist/src/drawHorizontalContent.js +19 -0
  11. package/dist/src/drawRow.js +17 -0
  12. package/dist/src/drawTable.js +38 -0
  13. package/dist/src/getBorderCharacters.js +83 -0
  14. package/dist/{index.js.flow → src/index.d.ts} +2 -6
  15. package/dist/src/index.js +24 -0
  16. package/dist/src/makeConfig.js +59 -0
  17. package/dist/src/makeStreamConfig.js +60 -0
  18. package/dist/src/mapDataUsingRowHeightIndex.js +27 -0
  19. package/dist/src/padTableData.js +11 -0
  20. package/dist/src/stringifyTableData.js +8 -0
  21. package/dist/src/table.js +28 -0
  22. package/dist/src/truncateTableData.js +20 -0
  23. package/dist/src/types/api.d.ts +99 -0
  24. package/dist/src/types/api.js +3 -0
  25. package/dist/src/types/internal.js +3 -0
  26. package/dist/src/validateConfig.js +27 -0
  27. package/dist/src/validateTableData.js +29 -0
  28. package/dist/{validators.js → src/validators.js} +0 -0
  29. package/dist/src/wrapCell.js +33 -0
  30. package/dist/src/wrapString.js +25 -0
  31. package/dist/src/wrapWord.js +29 -0
  32. package/package.json +33 -25
  33. package/dist/alignString.js +0 -107
  34. package/dist/alignString.js.flow +0 -97
  35. package/dist/alignTableData.js +0 -34
  36. package/dist/alignTableData.js.flow +0 -21
  37. package/dist/calculateCellHeight.js +0 -37
  38. package/dist/calculateCellHeight.js.flow +0 -24
  39. package/dist/calculateCellWidthIndex.js +0 -27
  40. package/dist/calculateCellWidthIndex.js.flow +0 -17
  41. package/dist/calculateMaximumColumnWidthIndex.js +0 -36
  42. package/dist/calculateMaximumColumnWidthIndex.js.flow +0 -27
  43. package/dist/calculateRowHeightIndex.js +0 -45
  44. package/dist/calculateRowHeightIndex.js.flow +0 -36
  45. package/dist/createStream.js +0 -124
  46. package/dist/createStream.js.flow +0 -125
  47. package/dist/drawBorder.js +0 -115
  48. package/dist/drawBorder.js.flow +0 -89
  49. package/dist/drawHorizontalContent.js +0 -41
  50. package/dist/drawHorizontalContent.js.flow +0 -31
  51. package/dist/drawRow.js +0 -41
  52. package/dist/drawRow.js.flow +0 -29
  53. package/dist/drawTable.js +0 -60
  54. package/dist/drawTable.js.flow +0 -64
  55. package/dist/getBorderCharacters.js +0 -118
  56. package/dist/getBorderCharacters.js.flow +0 -120
  57. package/dist/index.js +0 -31
  58. package/dist/makeConfig.js +0 -100
  59. package/dist/makeConfig.js.flow +0 -85
  60. package/dist/makeStreamConfig.js +0 -107
  61. package/dist/makeStreamConfig.js.flow +0 -92
  62. package/dist/mapDataUsingRowHeightIndex.js +0 -41
  63. package/dist/mapDataUsingRowHeightIndex.js.flow +0 -34
  64. package/dist/padTableData.js +0 -23
  65. package/dist/padTableData.js.flow +0 -14
  66. package/dist/schemas/config.json +0 -26
  67. package/dist/schemas/shared.json +0 -98
  68. package/dist/schemas/streamConfig.json +0 -23
  69. package/dist/stringifyTableData.js +0 -21
  70. package/dist/stringifyTableData.js.flow +0 -11
  71. package/dist/table.js +0 -121
  72. package/dist/table.js.flow +0 -108
  73. package/dist/truncateTableData.js +0 -30
  74. package/dist/truncateTableData.js.flow +0 -18
  75. package/dist/validateConfig.js +0 -40
  76. package/dist/validateConfig.js.flow +0 -27
  77. package/dist/validateTableData.js +0 -54
  78. package/dist/validateTableData.js.flow +0 -44
  79. package/dist/wrapCell.js +0 -47
  80. package/dist/wrapCell.js.flow +0 -35
  81. package/dist/wrapString.js +0 -39
  82. package/dist/wrapString.js.flow +0 -29
  83. package/dist/wrapWord.js +0 -46
  84. package/dist/wrapWord.js.flow +0 -39
package/dist/table.js DELETED
@@ -1,121 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _alignTableData = _interopRequireDefault(require("./alignTableData"));
9
-
10
- var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex"));
11
-
12
- var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex"));
13
-
14
- var _drawTable = _interopRequireDefault(require("./drawTable"));
15
-
16
- var _makeConfig = _interopRequireDefault(require("./makeConfig"));
17
-
18
- var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex"));
19
-
20
- var _padTableData = _interopRequireDefault(require("./padTableData"));
21
-
22
- var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData"));
23
-
24
- var _truncateTableData = _interopRequireDefault(require("./truncateTableData"));
25
-
26
- var _validateTableData = _interopRequireDefault(require("./validateTableData"));
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- /**
31
- * @typedef {string} table~cell
32
- */
33
-
34
- /**
35
- * @typedef {table~cell[]} table~row
36
- */
37
-
38
- /**
39
- * @typedef {object} table~columns
40
- * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
41
- * @property {number} width Column width (default: auto).
42
- * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
43
- * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
44
- * @property {number} paddingLeft Cell content padding width left (default: 1).
45
- * @property {number} paddingRight Cell content padding width right (default: 1).
46
- */
47
-
48
- /**
49
- * @typedef {object} table~border
50
- * @property {string} topBody
51
- * @property {string} topJoin
52
- * @property {string} topLeft
53
- * @property {string} topRight
54
- * @property {string} bottomBody
55
- * @property {string} bottomJoin
56
- * @property {string} bottomLeft
57
- * @property {string} bottomRight
58
- * @property {string} bodyLeft
59
- * @property {string} bodyRight
60
- * @property {string} bodyJoin
61
- * @property {string} joinBody
62
- * @property {string} joinLeft
63
- * @property {string} joinRight
64
- * @property {string} joinJoin
65
- */
66
-
67
- /**
68
- * Used to tell whether to draw a vertical line.
69
- * This callback is called for each non-content line of the table.
70
- * The default behavior is to always return true.
71
- *
72
- * @typedef {Function} drawVerticalLine
73
- * @param {number} index
74
- * @param {number} size
75
- * @returns {boolean}
76
- */
77
-
78
- /**
79
- * Used to tell whether to draw a horizontal line.
80
- * This callback is called for each non-content line of the table.
81
- * The default behavior is to always return true.
82
- *
83
- * @typedef {Function} drawHorizontalLine
84
- * @param {number} index
85
- * @param {number} size
86
- * @returns {boolean}
87
- */
88
-
89
- /**
90
- * @typedef {object} table~config
91
- * @property {table~border} border
92
- * @property {table~columns[]} columns Column specific configuration.
93
- * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
94
- * @property {table~drawVerticalLine} drawVerticalLine
95
- * @property {table~drawHorizontalLine} drawHorizontalLine
96
- * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
97
- */
98
-
99
- /**
100
- * Generates a text table.
101
- *
102
- * @param {table~row[]} data
103
- * @param {table~config} userConfig
104
- * @returns {string}
105
- */
106
- const table = (data, userConfig = {}) => {
107
- let rows;
108
- (0, _validateTableData.default)(data);
109
- rows = (0, _stringifyTableData.default)(data);
110
- const config = (0, _makeConfig.default)(rows, userConfig);
111
- rows = (0, _truncateTableData.default)(data, config);
112
- const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config);
113
- rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config);
114
- rows = (0, _alignTableData.default)(rows, config);
115
- rows = (0, _padTableData.default)(rows, config);
116
- const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]);
117
- return (0, _drawTable.default)(rows, cellWidthIndex, rowHeightIndex, config);
118
- };
119
-
120
- var _default = table;
121
- exports.default = _default;
@@ -1,108 +0,0 @@
1
- import alignTableData from './alignTableData';
2
- import calculateCellWidthIndex from './calculateCellWidthIndex';
3
- import calculateRowHeightIndex from './calculateRowHeightIndex';
4
- import drawTable from './drawTable';
5
- import makeConfig from './makeConfig';
6
- import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex';
7
- import padTableData from './padTableData';
8
- import stringifyTableData from './stringifyTableData';
9
- import truncateTableData from './truncateTableData';
10
- import validateTableData from './validateTableData';
11
-
12
- /**
13
- * @typedef {string} table~cell
14
- */
15
-
16
- /**
17
- * @typedef {table~cell[]} table~row
18
- */
19
-
20
- /**
21
- * @typedef {object} table~columns
22
- * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
23
- * @property {number} width Column width (default: auto).
24
- * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
25
- * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters
26
- * @property {number} paddingLeft Cell content padding width left (default: 1).
27
- * @property {number} paddingRight Cell content padding width right (default: 1).
28
- */
29
-
30
- /**
31
- * @typedef {object} table~border
32
- * @property {string} topBody
33
- * @property {string} topJoin
34
- * @property {string} topLeft
35
- * @property {string} topRight
36
- * @property {string} bottomBody
37
- * @property {string} bottomJoin
38
- * @property {string} bottomLeft
39
- * @property {string} bottomRight
40
- * @property {string} bodyLeft
41
- * @property {string} bodyRight
42
- * @property {string} bodyJoin
43
- * @property {string} joinBody
44
- * @property {string} joinLeft
45
- * @property {string} joinRight
46
- * @property {string} joinJoin
47
- */
48
-
49
- /**
50
- * Used to tell whether to draw a vertical line.
51
- * This callback is called for each non-content line of the table.
52
- * The default behavior is to always return true.
53
- *
54
- * @typedef {Function} drawVerticalLine
55
- * @param {number} index
56
- * @param {number} size
57
- * @returns {boolean}
58
- */
59
-
60
- /**
61
- * Used to tell whether to draw a horizontal line.
62
- * This callback is called for each non-content line of the table.
63
- * The default behavior is to always return true.
64
- *
65
- * @typedef {Function} drawHorizontalLine
66
- * @param {number} index
67
- * @param {number} size
68
- * @returns {boolean}
69
- */
70
-
71
- /**
72
- * @typedef {object} table~config
73
- * @property {table~border} border
74
- * @property {table~columns[]} columns Column specific configuration.
75
- * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
76
- * @property {table~drawVerticalLine} drawVerticalLine
77
- * @property {table~drawHorizontalLine} drawHorizontalLine
78
- * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn.
79
- */
80
-
81
- /**
82
- * Generates a text table.
83
- *
84
- * @param {table~row[]} data
85
- * @param {table~config} userConfig
86
- * @returns {string}
87
- */
88
- export default (data, userConfig = {}) => {
89
- let rows;
90
-
91
- validateTableData(data);
92
-
93
- rows = stringifyTableData(data);
94
-
95
- const config = makeConfig(rows, userConfig);
96
-
97
- rows = truncateTableData(data, config);
98
-
99
- const rowHeightIndex = calculateRowHeightIndex(rows, config);
100
-
101
- rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config);
102
- rows = alignTableData(rows, config);
103
- rows = padTableData(rows, config);
104
-
105
- const cellWidthIndex = calculateCellWidthIndex(rows[0]);
106
-
107
- return drawTable(rows, cellWidthIndex, rowHeightIndex, config);
108
- };
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash.truncate"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * @todo Make it work with ASCII content.
14
- * @param {table~row[]} rows
15
- * @param {object} config
16
- * @returns {table~row[]}
17
- */
18
- const truncateTableData = (rows, config) => {
19
- return rows.map(cells => {
20
- return cells.map((content, index) => {
21
- return (0, _lodash.default)(content, {
22
- length: config.columns[index].truncate,
23
- omission: '…'
24
- });
25
- });
26
- });
27
- };
28
-
29
- var _default = truncateTableData;
30
- exports.default = _default;
@@ -1,18 +0,0 @@
1
- import truncate from 'lodash.truncate';
2
-
3
- /**
4
- * @todo Make it work with ASCII content.
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((content, index) => {
12
- return truncate(content, {
13
- length: config.columns[index].truncate,
14
- omission: '…',
15
- });
16
- });
17
- });
18
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _validators = _interopRequireDefault(require("../dist/validators"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * @param {string} schemaId
14
- * @param {formatData~config} config
15
- * @returns {undefined}
16
- */
17
- const validateConfig = (schemaId, config = {}) => {
18
- const validate = _validators.default[schemaId];
19
-
20
- if (!validate(config)) {
21
- const errors = validate.errors.map(error => {
22
- return {
23
- dataPath: error.dataPath,
24
- message: error.message,
25
- params: error.params,
26
- schemaPath: error.schemaPath
27
- };
28
- });
29
- /* eslint-disable no-console */
30
-
31
- console.log('config', config);
32
- console.log('errors', errors);
33
- /* eslint-enable no-console */
34
-
35
- throw new Error('Invalid config.');
36
- }
37
- };
38
-
39
- var _default = validateConfig;
40
- exports.default = _default;
@@ -1,27 +0,0 @@
1
- import validators from '../dist/validators';
2
-
3
- /**
4
- * @param {string} schemaId
5
- * @param {formatData~config} config
6
- * @returns {undefined}
7
- */
8
- export default (schemaId, config = {}) => {
9
- const validate = validators[schemaId];
10
- if (!validate(config)) {
11
- const errors = validate.errors.map((error) => {
12
- return {
13
- dataPath: error.dataPath,
14
- message: error.message,
15
- params: error.params,
16
- schemaPath: error.schemaPath,
17
- };
18
- });
19
-
20
- /* eslint-disable no-console */
21
- console.log('config', config);
22
- console.log('errors', errors);
23
- /* eslint-enable no-console */
24
-
25
- throw new Error('Invalid config.');
26
- }
27
- };
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /**
9
- * @typedef {string} cell
10
- */
11
-
12
- /**
13
- * @typedef {cell[]} validateData~column
14
- */
15
-
16
- /**
17
- * @param {column[]} rows
18
- * @returns {undefined}
19
- */
20
- const validateTableData = rows => {
21
- if (!Array.isArray(rows)) {
22
- throw new TypeError('Table data must be an array.');
23
- }
24
-
25
- if (rows.length === 0) {
26
- throw new Error('Table must define at least one row.');
27
- }
28
-
29
- if (rows[0].length === 0) {
30
- throw new Error('Table must define at least one column.');
31
- }
32
-
33
- const columnNumber = rows[0].length;
34
-
35
- for (const cells of rows) {
36
- if (!Array.isArray(cells)) {
37
- throw new TypeError('Table row data must be an array.');
38
- }
39
-
40
- if (cells.length !== columnNumber) {
41
- throw new Error('Table must have a consistent number of cells.');
42
- }
43
-
44
- for (const cell of cells) {
45
- // eslint-disable-next-line no-control-regex
46
- if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
47
- throw new Error('Table data must not contain control characters.');
48
- }
49
- }
50
- }
51
- };
52
-
53
- var _default = validateTableData;
54
- exports.default = _default;
@@ -1,44 +0,0 @@
1
- /**
2
- * @typedef {string} cell
3
- */
4
-
5
- /**
6
- * @typedef {cell[]} validateData~column
7
- */
8
-
9
- /**
10
- * @param {column[]} rows
11
- * @returns {undefined}
12
- */
13
- export default (rows) => {
14
- if (!Array.isArray(rows)) {
15
- throw new TypeError('Table data must be an array.');
16
- }
17
-
18
- if (rows.length === 0) {
19
- throw new Error('Table must define at least one row.');
20
- }
21
-
22
- if (rows[0].length === 0) {
23
- throw new Error('Table must define at least one column.');
24
- }
25
-
26
- const columnNumber = rows[0].length;
27
-
28
- for (const cells of rows) {
29
- if (!Array.isArray(cells)) {
30
- throw new TypeError('Table row data must be an array.');
31
- }
32
-
33
- if (cells.length !== columnNumber) {
34
- throw new Error('Table must have a consistent number of cells.');
35
- }
36
-
37
- for (const cell of cells) {
38
- // eslint-disable-next-line no-control-regex
39
- if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) {
40
- throw new Error('Table data must not contain control characters.');
41
- }
42
- }
43
- }
44
- };
package/dist/wrapCell.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _wrapString = _interopRequireDefault(require("./wrapString"));
9
-
10
- var _wrapWord = _interopRequireDefault(require("./wrapWord"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * Wrap a single cell value into a list of lines
16
- *
17
- * Always wraps on newlines, for the remainder uses either word or string wrapping
18
- * depending on user configuration.
19
- *
20
- * @param {string} cellValue
21
- * @param {number} columnWidth
22
- * @param {boolean} useWrapWord
23
- * @returns {Array}
24
- */
25
- const wrapCell = (cellValue, columnWidth, useWrapWord) => {
26
- // First split on literal newlines
27
- const cellLines = cellValue.split('\n'); // Then iterate over the list and word-wrap every remaining line if necessary.
28
-
29
- for (let lineNr = 0; lineNr < cellLines.length;) {
30
- let lineChunks;
31
-
32
- if (useWrapWord) {
33
- lineChunks = (0, _wrapWord.default)(cellLines[lineNr], columnWidth);
34
- } else {
35
- lineChunks = (0, _wrapString.default)(cellLines[lineNr], columnWidth);
36
- } // Replace our original array element with whatever the wrapping returned
37
-
38
-
39
- cellLines.splice(lineNr, 1, ...lineChunks);
40
- lineNr += lineChunks.length;
41
- }
42
-
43
- return cellLines;
44
- };
45
-
46
- var _default = wrapCell;
47
- exports.default = _default;
@@ -1,35 +0,0 @@
1
- import wrapString from './wrapString';
2
- import wrapWord from './wrapWord';
3
-
4
- /**
5
- * Wrap a single cell value into a list of lines
6
- *
7
- * Always wraps on newlines, for the remainder uses either word or string wrapping
8
- * depending on user configuration.
9
- *
10
- * @param {string} cellValue
11
- * @param {number} columnWidth
12
- * @param {boolean} useWrapWord
13
- * @returns {Array}
14
- */
15
- export default (cellValue, columnWidth, useWrapWord) => {
16
- // First split on literal newlines
17
- const cellLines = cellValue.split('\n');
18
-
19
- // Then iterate over the list and word-wrap every remaining line if necessary.
20
- for (let lineNr = 0; lineNr < cellLines.length;) {
21
- let lineChunks;
22
-
23
- if (useWrapWord) {
24
- lineChunks = wrapWord(cellLines[lineNr], columnWidth);
25
- } else {
26
- lineChunks = wrapString(cellLines[lineNr], columnWidth);
27
- }
28
-
29
- // Replace our original array element with whatever the wrapping returned
30
- cellLines.splice(lineNr, 1, ...lineChunks);
31
- lineNr += lineChunks.length;
32
- }
33
-
34
- return cellLines;
35
- };
@@ -1,39 +0,0 @@
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
- * Creates an array of strings split into groups the length of size.
16
- * This function works with strings that contain ASCII characters.
17
- *
18
- * wrapText is different from would-be "chunk" implementation
19
- * in that whitespace characters that occur on a chunk size limit are trimmed.
20
- *
21
- * @param {string} subject
22
- * @param {number} size
23
- * @returns {Array}
24
- */
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;
36
- };
37
-
38
- var _default = wrapString;
39
- exports.default = _default;
@@ -1,29 +0,0 @@
1
- import slice from 'slice-ansi';
2
- import stringWidth from 'string-width';
3
-
4
- /**
5
- * Creates an array of strings split into groups the length of size.
6
- * This function works with strings that contain ASCII characters.
7
- *
8
- * wrapText is different from would-be "chunk" implementation
9
- * in that whitespace characters that occur on a chunk size limit are trimmed.
10
- *
11
- * @param {string} subject
12
- * @param {number} size
13
- * @returns {Array}
14
- */
15
- export default (subject, size) => {
16
- let subjectSlice;
17
-
18
- subjectSlice = subject;
19
-
20
- const chunks = [];
21
-
22
- do {
23
- chunks.push(slice(subjectSlice, 0, size));
24
-
25
- subjectSlice = slice(subjectSlice, size).trim();
26
- } while (stringWidth(subjectSlice));
27
-
28
- return chunks;
29
- };
package/dist/wrapWord.js DELETED
@@ -1,46 +0,0 @@
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;
43
- };
44
-
45
- var _default = wrapWord;
46
- exports.default = _default;
@@ -1,39 +0,0 @@
1
- import slice from 'slice-ansi';
2
- import stringWidth from 'string-width';
3
-
4
- /**
5
- * @param {string} input
6
- * @param {number} size
7
- * @returns {Array}
8
- */
9
- export default (input, size) => {
10
- let subject;
11
-
12
- subject = input;
13
-
14
- const chunks = [];
15
-
16
- // https://regex101.com/r/gY5kZ1/1
17
- const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
18
-
19
- do {
20
- let chunk;
21
-
22
- chunk = subject.match(re);
23
-
24
- if (chunk) {
25
- chunk = chunk[0];
26
-
27
- subject = slice(subject, stringWidth(chunk));
28
-
29
- chunk = chunk.trim();
30
- } else {
31
- chunk = slice(subject, 0, size);
32
- subject = slice(subject, size);
33
- }
34
-
35
- chunks.push(chunk);
36
- } while (stringWidth(subject));
37
-
38
- return chunks;
39
- };