table 3.8.2 → 4.0.3

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 (56) hide show
  1. package/README.md +35 -16
  2. package/dist/alignString.js +19 -842
  3. package/dist/alignTableData.js +4 -226
  4. package/dist/calculateCellHeight.js +6 -343
  5. package/dist/calculateCellWidthIndex.js +2 -112
  6. package/dist/calculateMaximumColumnWidthIndex.js +5 -299
  7. package/dist/calculateRowHeightIndex.js +8 -333
  8. package/dist/createStream.js +19 -814
  9. package/dist/drawBorder.js +11 -292
  10. package/dist/drawRow.js +1 -69
  11. package/dist/drawTable.js +7 -474
  12. package/dist/getBorderCharacters.js +1 -315
  13. package/dist/index.js +4 -28
  14. package/dist/makeConfig.js +15 -544
  15. package/dist/makeStreamConfig.js +13 -587
  16. package/dist/mapDataUsingRowHeightIndex.js +9 -349
  17. package/dist/padTableData.js +5 -166
  18. package/dist/schemas/config.json +2 -2
  19. package/dist/schemas/streamConfig.json +2 -2
  20. package/dist/stringifyTableData.js +4 -116
  21. package/dist/table.js +5 -203
  22. package/dist/truncateTableData.js +3 -147
  23. package/dist/validateConfig.js +20 -23
  24. package/dist/validateStreamConfig.js +17 -19
  25. package/dist/validateTableData.js +11 -528
  26. package/dist/wrapString.js +3 -135
  27. package/dist/wrapWord.js +4 -257
  28. package/package.json +27 -24
  29. package/test/README/usage/basic.js +0 -25
  30. package/test/README/usage/cell_content_alignment.js +0 -45
  31. package/test/README/usage/column_width.js +0 -33
  32. package/test/README/usage/custom_border.js +0 -50
  33. package/test/README/usage/draw_horizontal_line.js +0 -41
  34. package/test/README/usage/expectTable.js +0 -13
  35. package/test/README/usage/moon_mission.js +0 -67
  36. package/test/README/usage/padding_cell_content.js +0 -39
  37. package/test/README/usage/predefined_border_templates.js +0 -91
  38. package/test/README/usage/streaming.js +0 -56
  39. package/test/README/usage/text_truncating.js +0 -32
  40. package/test/README/usage/text_wrapping.js +0 -67
  41. package/test/alignString.js +0 -102
  42. package/test/calculateCellHeight.js +0 -44
  43. package/test/calculateCellWidthIndex.js +0 -20
  44. package/test/calculateMaximumColumnWidthIndex.js +0 -59
  45. package/test/calculateRowHeightIndex.js +0 -78
  46. package/test/config.js +0 -43
  47. package/test/configSamples.js +0 -153
  48. package/test/createStream.js +0 -41
  49. package/test/drawBorder.js +0 -71
  50. package/test/makeConfig.js +0 -75
  51. package/test/mapDataUsingRowHeightIndex.js +0 -119
  52. package/test/streamConfig.js +0 -43
  53. package/test/streamConfigSamples.js +0 -151
  54. package/test/validateTableData.js +0 -65
  55. package/test/wrapString.js +0 -45
  56. package/test/wrapWord.js +0 -32
package/dist/wrapWord.js CHANGED
@@ -4,240 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var cov_2in591hdkb = function () {
8
- var path = '/Users/gajuskuizinas/Documents/dev/gajus/table/src/wrapWord.js',
9
- hash = 'b859c23198f963a8e98116f29b9c80fef9051c0e',
10
- global = new Function('return this')(),
11
- gcv = '__coverage__',
12
- coverageData = {
13
- path: '/Users/gajuskuizinas/Documents/dev/gajus/table/src/wrapWord.js',
14
- statementMap: {
15
- '0': {
16
- start: {
17
- line: 13,
18
- column: 2
19
- },
20
- end: {
21
- line: 13,
22
- column: 18
23
- }
24
- },
25
- '1': {
26
- start: {
27
- line: 15,
28
- column: 17
29
- },
30
- end: {
31
- line: 15,
32
- column: 19
33
- }
34
- },
35
- '2': {
36
- start: {
37
- line: 18,
38
- column: 13
39
- },
40
- end: {
41
- line: 18,
42
- column: 102
43
- }
44
- },
45
- '3': {
46
- start: {
47
- line: 20,
48
- column: 2
49
- },
50
- end: {
51
- line: 37,
52
- column: 33
53
- }
54
- },
55
- '4': {
56
- start: {
57
- line: 23,
58
- column: 4
59
- },
60
- end: {
61
- line: 23,
62
- column: 30
63
- }
64
- },
65
- '5': {
66
- start: {
67
- line: 25,
68
- column: 4
69
- },
70
- end: {
71
- line: 34,
72
- column: 5
73
- }
74
- },
75
- '6': {
76
- start: {
77
- line: 26,
78
- column: 6
79
- },
80
- end: {
81
- line: 26,
82
- column: 23
83
- }
84
- },
85
- '7': {
86
- start: {
87
- line: 28,
88
- column: 6
89
- },
90
- end: {
91
- line: 28,
92
- column: 51
93
- }
94
- },
95
- '8': {
96
- start: {
97
- line: 30,
98
- column: 6
99
- },
100
- end: {
101
- line: 30,
102
- column: 28
103
- }
104
- },
105
- '9': {
106
- start: {
107
- line: 32,
108
- column: 6
109
- },
110
- end: {
111
- line: 32,
112
- column: 38
113
- }
114
- },
115
- '10': {
116
- start: {
117
- line: 33,
118
- column: 6
119
- },
120
- end: {
121
- line: 33,
122
- column: 37
123
- }
124
- },
125
- '11': {
126
- start: {
127
- line: 36,
128
- column: 4
129
- },
130
- end: {
131
- line: 36,
132
- column: 23
133
- }
134
- },
135
- '12': {
136
- start: {
137
- line: 39,
138
- column: 2
139
- },
140
- end: {
141
- line: 39,
142
- column: 16
143
- }
144
- }
145
- },
146
- fnMap: {
147
- '0': {
148
- name: '(anonymous_0)',
149
- decl: {
150
- start: {
151
- line: 10,
152
- column: 15
153
- },
154
- end: {
155
- line: 10,
156
- column: 16
157
- }
158
- },
159
- loc: {
160
- start: {
161
- line: 10,
162
- column: 32
163
- },
164
- end: {
165
- line: 40,
166
- column: 1
167
- }
168
- }
169
- }
170
- },
171
- branchMap: {
172
- '0': {
173
- loc: {
174
- start: {
175
- line: 25,
176
- column: 4
177
- },
178
- end: {
179
- line: 34,
180
- column: 5
181
- }
182
- },
183
- type: 'if',
184
- locations: [{
185
- start: {
186
- line: 25,
187
- column: 4
188
- },
189
- end: {
190
- line: 34,
191
- column: 5
192
- }
193
- }, {
194
- start: {
195
- line: 25,
196
- column: 4
197
- },
198
- end: {
199
- line: 34,
200
- column: 5
201
- }
202
- }]
203
- }
204
- },
205
- s: {
206
- '0': 0,
207
- '1': 0,
208
- '2': 0,
209
- '3': 0,
210
- '4': 0,
211
- '5': 0,
212
- '6': 0,
213
- '7': 0,
214
- '8': 0,
215
- '9': 0,
216
- '10': 0,
217
- '11': 0,
218
- '12': 0
219
- },
220
- f: {
221
- '0': 0
222
- },
223
- b: {
224
- '0': [0, 0]
225
- }
226
- },
227
- coverage = global[gcv] || (global[gcv] = {});
228
-
229
- if (coverage[path] && coverage[path].hash === hash) {
230
- return coverage[path];
231
- }
232
-
233
- coverageData.hash = hash;
234
- return coverage[path] = coverageData;
235
- }();
236
-
237
- var _lodash = require('lodash');
238
-
239
- var _lodash2 = _interopRequireDefault(_lodash);
240
-
241
7
  var _sliceAnsi = require('slice-ansi');
242
8
 
243
9
  var _sliceAnsi2 = _interopRequireDefault(_sliceAnsi);
@@ -254,52 +20,33 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
254
20
  * @returns {Array}
255
21
  */
256
22
  exports.default = (input, size) => {
257
- ++cov_2in591hdkb.f[0];
258
-
259
23
  let subject;
260
24
 
261
- ++cov_2in591hdkb.s[0];
262
25
  subject = input;
263
26
 
264
- const chunks = (++cov_2in591hdkb.s[1], []);
27
+ const chunks = [];
265
28
 
266
29
  // https://regex101.com/r/gY5kZ1/1
267
- const re = (++cov_2in591hdkb.s[2], new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))'));
30
+ const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
268
31
 
269
- ++cov_2in591hdkb.s[3];
270
32
  do {
271
33
  let chunk;
272
34
 
273
- ++cov_2in591hdkb.s[4];
274
35
  chunk = subject.match(re);
275
36
 
276
- ++cov_2in591hdkb.s[5];
277
37
  if (chunk) {
278
- ++cov_2in591hdkb.b[0][0];
279
- ++cov_2in591hdkb.s[6];
280
-
281
38
  chunk = chunk[0];
282
39
 
283
- ++cov_2in591hdkb.s[7];
284
40
  subject = (0, _sliceAnsi2.default)(subject, (0, _stringWidth2.default)(chunk));
285
41
 
286
- ++cov_2in591hdkb.s[8];
287
- chunk = _lodash2.default.trim(chunk);
42
+ chunk = chunk.trim();
288
43
  } else {
289
- ++cov_2in591hdkb.b[0][1];
290
- ++cov_2in591hdkb.s[9];
291
-
292
44
  chunk = (0, _sliceAnsi2.default)(subject, 0, size);
293
- ++cov_2in591hdkb.s[10];
294
45
  subject = (0, _sliceAnsi2.default)(subject, size);
295
46
  }
296
47
 
297
- ++cov_2in591hdkb.s[11];
298
48
  chunks.push(chunk);
299
49
  } while ((0, _stringWidth2.default)(subject));
300
50
 
301
- ++cov_2in591hdkb.s[12];
302
51
  return chunks;
303
- };
304
-
305
- module.exports = exports['default'];
52
+ };
package/package.json CHANGED
@@ -5,31 +5,33 @@
5
5
  "url": "http://gajus.com"
6
6
  },
7
7
  "dependencies": {
8
- "ajv": "^4.7.0",
9
- "ajv-keywords": "^1.0.0",
10
- "chalk": "^1.1.1",
11
- "lodash": "^4.0.0",
12
- "slice-ansi": "0.0.4",
13
- "string-width": "^2.0.0"
8
+ "ajv": "^6.0.1",
9
+ "ajv-keywords": "^3.0.0",
10
+ "chalk": "^2.1.0",
11
+ "lodash": "^4.17.4",
12
+ "slice-ansi": "1.0.0",
13
+ "string-width": "^2.1.1"
14
14
  },
15
15
  "description": "Formats data into a string table.",
16
16
  "devDependencies": {
17
- "ajv-cli": "^1.1.0",
18
- "babel": "^6.5.2",
19
- "babel-cli": "^6.14.0",
20
- "babel-core": "^6.14.0",
21
- "babel-plugin-add-module-exports": "^0.2.1",
22
- "babel-plugin-istanbul": "^2.0.3",
23
- "babel-preset-es2015-node4": "^2.1.0",
24
- "babel-register": "^6.14.0",
25
- "chai": "^3.4.1",
26
- "eslint": "^3.5.0",
27
- "eslint-config-canonical": "^1.8.6",
28
- "gitdown": "^2.4.0",
29
- "husky": "^0.11.7",
30
- "mocha": "^3.0.2",
31
- "nyc": "^8.3.1",
32
- "sinon": "^1.17.2"
17
+ "ajv-cli": "^3.0.0",
18
+ "babel": "^6.23.0",
19
+ "babel-cli": "^6.26.0",
20
+ "babel-core": "^6.26.0",
21
+ "babel-plugin-istanbul": "^4.1.5",
22
+ "babel-preset-es2015-node4": "^2.1.1",
23
+ "babel-register": "^6.26.0",
24
+ "chai": "^4.1.2",
25
+ "eslint": "^4.7.2",
26
+ "eslint-config-canonical": "^9.3.1",
27
+ "gitdown": "^2.5.1",
28
+ "husky": "^0.14.3",
29
+ "mocha": "^5.0.0",
30
+ "nyc": "^11.2.1",
31
+ "sinon": "^4.0.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=4.0.0"
33
35
  },
34
36
  "keywords": [
35
37
  "ascii",
@@ -57,12 +59,13 @@
57
59
  "url": "https://github.com/gajus/table"
58
60
  },
59
61
  "scripts": {
60
- "build": "rm -fr ./dist && babel --copy-files ./src --out-dir ./dist && npm run make-validators",
62
+ "build": "rm -fr ./dist && NODE_ENV=production babel --copy-files ./src --out-dir ./dist && npm run make-validators",
61
63
  "lint": "npm run build && eslint ./src ./tests",
62
64
  "make-readme": "gitdown ./.README/README.md --output-file ./README.md",
63
65
  "make-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -c ajv-keywords/keywords/typeof -o dist/validateConfig.js && ajv compile --all-errors --inline-refs=false -s src/schemas/streamConfig -c ajv-keywords/keywords/typeof -o dist/validateStreamConfig.js",
64
66
  "precommit": "npm run lint && npm run test",
67
+ "prepublish": "NODE_ENV=production npm run build",
65
68
  "test": "npm run build && nyc --check-coverage mocha"
66
69
  },
67
- "version": "3.8.2"
70
+ "version": "4.0.3"
68
71
  }
@@ -1,25 +0,0 @@
1
- import table from './../../../src';
2
- import expectTable from './expectTable';
3
-
4
- describe('README.md usage/', () => {
5
- it('basic', () => {
6
- const data = [
7
- ['0A', '0B', '0C'],
8
- ['1A', '1B', '1C'],
9
- ['2A', '2B', '2C']
10
- ];
11
-
12
- const output = table(data);
13
-
14
- // eslint-disable-next-line no-restricted-syntax
15
- expectTable(output, `
16
- ╔════╤════╤════╗
17
- ║ 0A │ 0B │ 0C ║
18
- ╟────┼────┼────╢
19
- ║ 1A │ 1B │ 1C ║
20
- ╟────┼────┼────╢
21
- ║ 2A │ 2B │ 2C ║
22
- ╚════╧════╧════╝
23
- `);
24
- });
25
- });
@@ -1,45 +0,0 @@
1
- import table from './../../../src';
2
- import expectTable from './expectTable';
3
-
4
- describe('README.md usage/', () => {
5
- it('cell_content_alignment', () => {
6
- const data = [
7
- ['0A', '0B', '0C'],
8
- ['1A', '1B', '1C'],
9
- ['2A', '2B', '2C']
10
- ];
11
-
12
- const config = {
13
- columns: {
14
- 0: {
15
- alignment: 'left',
16
- width: 10
17
- },
18
- 1: {
19
- alignment: 'center',
20
- width: 10
21
- },
22
- 2: {
23
- alignment: 'right',
24
- width: 10
25
- }
26
- }
27
- };
28
-
29
- const output = table(data, config);
30
-
31
- // console.log(output);
32
-
33
- /* eslint-disable no-restricted-syntax */
34
- expectTable(output, `
35
- ╔════════════╤════════════╤════════════╗
36
- ║ 0A │ 0B │ 0C ║
37
- ╟────────────┼────────────┼────────────╢
38
- ║ 1A │ 1B │ 1C ║
39
- ╟────────────┼────────────┼────────────╢
40
- ║ 2A │ 2B │ 2C ║
41
- ╚════════════╧════════════╧════════════╝
42
- `);
43
- /* eslint-enable no-restricted-syntax */
44
- });
45
- });
@@ -1,33 +0,0 @@
1
- import table from './../../../src';
2
- import expectTable from './expectTable';
3
-
4
- describe('README.md usage/', () => {
5
- it('column_width', () => {
6
- const data = [
7
- ['0A', '0B', '0C'],
8
- ['1A', '1B', '1C'],
9
- ['2A', '2B', '2C']
10
- ];
11
-
12
- const config = {
13
- columns: {
14
- 1: {
15
- width: 10
16
- }
17
- }
18
- };
19
-
20
- const output = table(data, config);
21
-
22
- // eslint-disable-next-line no-restricted-syntax
23
- expectTable(output, `
24
- ╔════╤════════════╤════╗
25
- ║ 0A │ 0B │ 0C ║
26
- ╟────┼────────────┼────╢
27
- ║ 1A │ 1B │ 1C ║
28
- ╟────┼────────────┼────╢
29
- ║ 2A │ 2B │ 2C ║
30
- ╚════╧════════════╧════╝
31
- `);
32
- });
33
- });
@@ -1,50 +0,0 @@
1
- import table from './../../../src';
2
- import expectTable from './expectTable';
3
-
4
- describe('README.md usage/', () => {
5
- it('usage/custom_border', () => {
6
- const data = [
7
- ['0A', '0B', '0C'],
8
- ['1A', '1B', '1C'],
9
- ['2A', '2B', '2C']
10
- ];
11
-
12
- /* eslint-disable sort-keys */
13
- const config = {
14
- border: {
15
- topBody: '─',
16
- topJoin: '┬',
17
- topLeft: '┌',
18
- topRight: '┐',
19
-
20
- bottomBody: '─',
21
- bottomJoin: '┴',
22
- bottomLeft: '└',
23
- bottomRight: '┘',
24
-
25
- bodyLeft: '│',
26
- bodyRight: '│',
27
- bodyJoin: '│',
28
-
29
- joinBody: '─',
30
- joinLeft: '├',
31
- joinRight: '┤',
32
- joinJoin: '┼'
33
- }
34
- };
35
- /* eslint-enable */
36
-
37
- const output = table(data, config);
38
-
39
- // eslint-disable-next-line no-restricted-syntax
40
- expectTable(output, `
41
- ┌────┬────┬────┐
42
- │ 0A │ 0B │ 0C │
43
- ├────┼────┼────┤
44
- │ 1A │ 1B │ 1C │
45
- ├────┼────┼────┤
46
- │ 2A │ 2B │ 2C │
47
- └────┴────┴────┘
48
- `);
49
- });
50
- });
@@ -1,41 +0,0 @@
1
- import table from './../../../src';
2
- import expectTable from './expectTable';
3
-
4
- describe('README.md usage/', () => {
5
- it('usage/draw_horizontal_line', () => {
6
- const data = [
7
- ['0A', '0B', '0C'],
8
- ['1A', '1B', '1C'],
9
- ['2A', '2B', '2C'],
10
- ['3A', '3B', '3C'],
11
- ['4A', '4B', '4C']
12
- ];
13
-
14
- const options = {
15
- /**
16
- * @typedef {Function} drawJoin
17
- * @param {number} index
18
- * @param {number} size
19
- * @returns {boolean}
20
- */
21
- drawHorizontalLine: (index, size) => {
22
- return index === 0 || index === 1 || index === size - 1 || index === size;
23
- }
24
- };
25
-
26
- const output = table(data, options);
27
-
28
- // eslint-disable-next-line no-restricted-syntax
29
- expectTable(output, `
30
- ╔════╤════╤════╗
31
- ║ 0A │ 0B │ 0C ║
32
- ╟────┼────┼────╢
33
- ║ 1A │ 1B │ 1C ║
34
- ║ 2A │ 2B │ 2C ║
35
- ║ 3A │ 3B │ 3C ║
36
- ╟────┼────┼────╢
37
- ║ 4A │ 4B │ 4C ║
38
- ╚════╧════╧════╝
39
- `);
40
- });
41
- });
@@ -1,13 +0,0 @@
1
- import {
2
- expect
3
- } from 'chai';
4
- import _ from 'lodash';
5
-
6
- /**
7
- * @param {string} result
8
- * @param {string} expectedResult
9
- * @returns {undefined}
10
- */
11
- export default (result, expectedResult) => {
12
- expect(result).to.equal(_.trim(expectedResult) + '\n');
13
- };
@@ -1,67 +0,0 @@
1
- import _ from 'lodash';
2
- import chalk from 'chalk';
3
- import table, {
4
- getBorderCharacters
5
- } from './../../../src';
6
-
7
- describe('README.md usage/', () => {
8
- it('moon_mission', () => {
9
- const data = [
10
- [
11
- chalk.bold('Spacecraft'),
12
- chalk.bold('Launch Date'),
13
- chalk.bold('Operator'),
14
- chalk.bold('Outcome'),
15
- chalk.bold('Remarks')
16
- ],
17
- [
18
- 'Able I',
19
- '17 August 1958',
20
- 'USAF',
21
- chalk.white.bold.bgRed('Launch failure'),
22
- 'First attempted launch beyond Earth orbit; failed to orbit due to turbopump gearbox malfunction resulting in first stage explosion.[3] Reached apogee of 16 kilometres (9.9 mi)'
23
- ],
24
- [
25
- 'Luna 2',
26
- '12 September 1959',
27
- 'OKB-1',
28
- chalk.black.bgGreen('Successful'),
29
- 'Successful impact at 21:02 on 14 September 1959. First spacecraft to reach lunar surface'
30
- ],
31
- [
32
- 'Lunar Orbiter 1',
33
- '10 August 1966',
34
- 'NASA',
35
- chalk.black.bgYellow('Partial failure'),
36
- 'Orbital insertion at around 15:36 UTC on 14 August. Deorbited early due to lack of fuel and to avoid communications interference with the next mission, impacted the Moon at 13:30 UTC on 29 October 1966.'
37
- ],
38
- [
39
- 'Apollo 8',
40
- '21 December 1968',
41
- 'NASA',
42
- chalk.black.bgGreen('Successful'),
43
- 'First manned mission to the Moon; entered orbit around the Moon with four-minute burn beginning at 09:59:52 UTC on 24 December. Completed ten orbits of the Moon before returning to Earth with an engine burn at 06:10:16 UTC on 25 December. Landed in the Pacific Ocean at 15:51 UTC on 27 December.'
44
- ],
45
- [
46
- 'Apollo 11',
47
- '16 July 1969',
48
- 'NASA',
49
- chalk.black.bgGreen('Successful'),
50
- 'First manned landing on the Moon. LM landed at 20:17 UTC on 20 July 1969'
51
- ]
52
- ];
53
-
54
- const tableBorder = _.mapValues(getBorderCharacters('honeywell'), (char) => {
55
- return chalk.gray(char);
56
- });
57
-
58
- table(data, {
59
- border: tableBorder,
60
- columns: {
61
- 4: {
62
- width: 50
63
- }
64
- }
65
- });
66
- });
67
- });
@@ -1,39 +0,0 @@
1
- import table from './../../../src';
2
- import expectTable from './expectTable';
3
-
4
- describe('README.md usage/', () => {
5
- it('usage/padding_cell_content', () => {
6
- const data = [
7
- ['0A', 'AABBCC', '0C'],
8
- ['1A', '1B', '1C'],
9
- ['2A', '2B', '2C']
10
- ];
11
-
12
- const config = {
13
- columns: {
14
- 0: {
15
- paddingLeft: 3
16
- },
17
- 1: {
18
- paddingRight: 3,
19
- width: 2
20
- }
21
- }
22
- };
23
-
24
- const output = table(data, config);
25
-
26
- // eslint-disable-next-line no-restricted-syntax
27
- expectTable(output, `
28
- ╔══════╤══════╤════╗
29
- ║ 0A │ AA │ 0C ║
30
- ║ │ BB │ ║
31
- ║ │ CC │ ║
32
- ╟──────┼──────┼────╢
33
- ║ 1A │ 1B │ 1C ║
34
- ╟──────┼──────┼────╢
35
- ║ 2A │ 2B │ 2C ║
36
- ╚══════╧══════╧════╝
37
- `);
38
- });
39
- });