table 4.0.1 → 4.0.2

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 (45) hide show
  1. package/dist/alignString.js +3 -3
  2. package/dist/alignTableData.js +2 -6
  3. package/dist/calculateCellHeight.js +2 -2
  4. package/dist/calculateCellWidthIndex.js +1 -5
  5. package/dist/calculateRowHeightIndex.js +2 -2
  6. package/dist/createStream.js +1 -1
  7. package/dist/drawTable.js +3 -1
  8. package/dist/makeConfig.js +3 -3
  9. package/dist/makeStreamConfig.js +2 -2
  10. package/dist/mapDataUsingRowHeightIndex.js +1 -1
  11. package/dist/schemas/config.json +2 -2
  12. package/dist/schemas/streamConfig.json +2 -2
  13. package/dist/stringifyTableData.js +3 -9
  14. package/dist/validateConfig.js +20 -23
  15. package/dist/validateStreamConfig.js +17 -19
  16. package/dist/validateTableData.js +9 -15
  17. package/package.json +22 -22
  18. package/test/README/usage/basic.js +0 -27
  19. package/test/README/usage/cell_content_alignment.js +0 -47
  20. package/test/README/usage/column_width.js +0 -35
  21. package/test/README/usage/custom_border.js +0 -52
  22. package/test/README/usage/draw_horizontal_line.js +0 -43
  23. package/test/README/usage/expectTable.js +0 -13
  24. package/test/README/usage/moon_mission.js +0 -68
  25. package/test/README/usage/padding_cell_content.js +0 -41
  26. package/test/README/usage/predefined_border_templates.js +0 -92
  27. package/test/README/usage/streaming.js +0 -56
  28. package/test/README/usage/text_truncating.js +0 -34
  29. package/test/README/usage/text_wrapping.js +0 -69
  30. package/test/alignString.js +0 -102
  31. package/test/calculateCellHeight.js +0 -44
  32. package/test/calculateCellWidthIndex.js +0 -20
  33. package/test/calculateMaximumColumnWidthIndex.js +0 -59
  34. package/test/calculateRowHeightIndex.js +0 -78
  35. package/test/config.js +0 -43
  36. package/test/configSamples.js +0 -153
  37. package/test/createStream.js +0 -41
  38. package/test/drawBorder.js +0 -71
  39. package/test/makeConfig.js +0 -75
  40. package/test/mapDataUsingRowHeightIndex.js +0 -119
  41. package/test/streamConfig.js +0 -43
  42. package/test/streamConfigSamples.js +0 -151
  43. package/test/validateTableData.js +0 -65
  44. package/test/wrapString.js +0 -45
  45. package/test/wrapWord.js +0 -32
@@ -1,78 +0,0 @@
1
- /* eslint-disable max-nested-callbacks */
2
-
3
- import {
4
- expect
5
- } from 'chai';
6
- import calculateRowHeightIndex from './../src/calculateRowHeightIndex';
7
-
8
- describe('calculateRowHeightIndex', () => {
9
- context('single column', () => {
10
- context('cell content width is lesser than column width', () => {
11
- it('is equal to 1', () => {
12
- const data = [
13
- [
14
- 'aaa'
15
- ]
16
- ];
17
-
18
- const config = {
19
- columns: {
20
- 0: {
21
- width: 10,
22
- wrapWord: false
23
- }
24
- }
25
- };
26
-
27
- const rowSpanIndex = calculateRowHeightIndex(data, config);
28
-
29
- expect(rowSpanIndex[0]).to.equal(1);
30
- });
31
- });
32
- context('cell content width is twice the size of the column width', () => {
33
- it('is equal to 2', () => {
34
- const data = [
35
- [
36
- 'aaabbb'
37
- ]
38
- ];
39
-
40
- const config = {
41
- columns: {
42
- 0: {
43
- width: 3,
44
- wrapWord: false
45
- }
46
- }
47
- };
48
-
49
- const rowSpanIndex = calculateRowHeightIndex(data, config);
50
-
51
- expect(rowSpanIndex[0]).to.equal(2);
52
- });
53
- });
54
- });
55
- context('multiple columns', () => {
56
- context('multiple cell content width is greater than the column width', () => {
57
- it('uses the largest height', () => {
58
- const data = [
59
- ['aaabbb'],
60
- ['aaabbb']
61
- ];
62
-
63
- const config = {
64
- columns: {
65
- 0: {
66
- width: 2,
67
- wrapWord: false
68
- }
69
- }
70
- };
71
-
72
- const rowSpanIndex = calculateRowHeightIndex(data, config);
73
-
74
- expect(rowSpanIndex[0]).to.equal(3);
75
- });
76
- });
77
- });
78
- });
package/test/config.js DELETED
@@ -1,43 +0,0 @@
1
- import {
2
- expect
3
- } from 'chai';
4
- import configSamples from './configSamples';
5
- import validateConfig from '../dist/validateConfig';
6
- import configSchema from '../src/schemas/config.json';
7
- import Ajv from 'ajv';
8
- import ajvKeywords from 'ajv-keywords';
9
-
10
- describe('config.json schema', () => {
11
- var validate;
12
-
13
- before(() => {
14
- var ajv = new Ajv({allErrors: true});
15
- ajvKeywords(ajv, 'typeof');
16
- validate = ajv.compile(configSchema);
17
- });
18
-
19
- it('should pass validation of valid config samples', () => {
20
- configSamples.valid.forEach((sample, i) => {
21
- testValid(sample, validate);
22
- testValid(sample, validateConfig);
23
- });
24
-
25
- function testValid(sample, validate) {
26
- var valid = validate(sample);
27
- if (!valid) console.log(validate.errors);
28
- expect(valid).to.equal(true);
29
- }
30
- });
31
-
32
- it('should fail validation of invalid config samples', () => {
33
- configSamples.invalid.forEach((sample, i) => {
34
- testInvalid(sample, validate);
35
- testInvalid(sample, validateConfig);
36
- });
37
-
38
- function testInvalid(sample, validate) {
39
- var valid = validate(sample);
40
- expect(valid).to.equal(false);
41
- }
42
- });
43
- });
@@ -1,153 +0,0 @@
1
- export default {
2
- valid: [
3
- {
4
- columns: {
5
- 0: {
6
- alignment: 'left',
7
- // minWidth: 10,
8
- width: 10
9
- },
10
- 1: {
11
- alignment: 'center',
12
- // minWidth: 10,
13
- width: 10
14
- },
15
- 2: {
16
- alignment: 'right',
17
- // minWidth: 10,
18
- width: 10
19
- }
20
- }
21
- },
22
- {
23
- border: {
24
- topBody: `─`,
25
- topJoin: `┬`,
26
- topLeft: `┌`,
27
- topRight: `┐`,
28
-
29
- bottomBody: `─`,
30
- bottomJoin: `┴`,
31
- bottomLeft: `└`,
32
- bottomRight: `┘`,
33
-
34
- bodyLeft: `│`,
35
- bodyRight: `│`,
36
- bodyJoin: `│`,
37
-
38
- joinBody: `─`,
39
- joinLeft: `├`,
40
- joinRight: `┤`,
41
- joinJoin: `┼`
42
- }
43
- },
44
- {
45
- columns: {
46
- 0: {
47
- paddingLeft: 3
48
- },
49
- 1: {
50
- width: 2,
51
- paddingRight: 3
52
- }
53
- }
54
- },
55
- {
56
- border: {},
57
- columnDefault: {
58
- paddingLeft: 0,
59
- paddingRight: 1
60
- },
61
- // drawJoin: () => {
62
- // return false
63
- // }
64
- },
65
- {
66
- columnDefault: {
67
- width: 50
68
- },
69
- // columnCount: 3,
70
- columns: {
71
- 0: {
72
- width: 10,
73
- alignment: 'right'
74
- },
75
- 1: {
76
- alignment: 'center',
77
- },
78
- 2: {
79
- width: 10
80
- }
81
- }
82
- },
83
- { border: { topBody: '-' } },
84
- { border: { topJoin: '-' } },
85
- { border: { topLeft: '-' } },
86
- { border: { topRight: '-' } },
87
- { border: { bottomBody: '-' } },
88
- { border: { bottomJoin: '-' } },
89
- { border: { bottomLeft: '-' } },
90
- { border: { bottomRight: '-' } },
91
- { border: { bodyLeft: '-' } },
92
- { border: { bodyRight: '-' } },
93
- { border: { bodyJoin: '-' } },
94
- { border: { joinBody: '-' } },
95
- { border: { joinLeft: '-' } },
96
- { border: { joinRight: '-' } },
97
- { border: { joinJoin: '-' } },
98
- { columns: { '1': { alignment: 'left' } } },
99
- { columns: { '1': { width: 5 } } },
100
- { columns: { '1': { wrapWord: true } } },
101
- { columns: { '1': { truncate: 1 } } },
102
- { columns: { '1': { paddingLeft: 1 } } },
103
- { columns: { '1': { paddingRight: 1 } } },
104
- { columnDefault: { alignment: 'left' } },
105
- { columnDefault: { width: 5 } },
106
- { columnDefault: { wrapWord: true } },
107
- { columnDefault: { truncate: 1 } },
108
- { columnDefault: { paddingLeft: 1 } },
109
- { columnDefault: { paddingRight: 1 } },
110
- { drawHorizontalLine: function(){} }
111
- ],
112
- invalid: [
113
- { border: 1 },
114
- { border: { unknown: '-' } },
115
- { border: { topBody: 1 } },
116
- { border: { topJoin: 1 } },
117
- { border: { topLeft: 1 } },
118
- { border: { topRight: 1 } },
119
- { border: { bottomBody: 1 } },
120
- { border: { bottomJoin: 1 } },
121
- { border: { bottomLeft: 1 } },
122
- { border: { bottomRight: 1 } },
123
- { border: { bodyLeft: 1 } },
124
- { border: { bodyRight: 1 } },
125
- { border: { bodyJoin: 1 } },
126
- { border: { joinBody: 1 } },
127
- { border: { joinLeft: 1 } },
128
- { border: { joinRight: 1 } },
129
- { border: { joinJoin: 1 } },
130
- { columns: 1 },
131
- { columns: { a: { width: 5 } } },
132
- { columns: { '1': 1 } },
133
- { columns: { '1': { unknown: 1 } } },
134
- { columns: { '1': { alignment: 1 } } },
135
- { columns: { '1': { alignment: '1' } } },
136
- { columns: { '1': { width: '5' } } },
137
- { columns: { '1': { wrapWord: 1 } } },
138
- { columns: { '1': { truncate: '1' } } },
139
- { columns: { '1': { paddingLeft: '1' } } },
140
- { columns: { '1': { paddingRight: '1' } } },
141
- { columnDefault: 1 },
142
- { columnDefault: { unknown: 1 } },
143
- { columnDefault: { alignment: 1 } },
144
- { columnDefault: { alignment: '1' } },
145
- { columnDefault: { width: '5' } },
146
- { columnDefault: { wrapWord: 1 } },
147
- { columnDefault: { truncate: '1' } },
148
- { columnDefault: { paddingLeft: '1' } },
149
- { columnDefault: { paddingRight: '1' } },
150
- { drawHorizontalLine: 1 },
151
- { unknown: 1 }
152
- ]
153
- };
@@ -1,41 +0,0 @@
1
- /* eslint-disable max-nested-callbacks */
2
-
3
- import {
4
- expect
5
- } from 'chai';
6
- import createStream from './../src/createStream';
7
-
8
- describe('createStream', () => {
9
- context('"config.columnDefault.width" property is not provided', () => {
10
- it('throws an error', () => {
11
- expect(() => {
12
- createStream();
13
- }).to.throw(Error, 'Must provide config.columnDefault.width when creating a stream.');
14
- });
15
- });
16
- context('"config.columnCount" property is not provided', () => {
17
- it('throws an error', () => {
18
- expect(() => {
19
- createStream({
20
- columnDefault: {
21
- width: 10
22
- }
23
- });
24
- }).to.throw(Error, 'Must provide config.columnCount.');
25
- });
26
- });
27
- context('Table data cell count does not match the columnCount.', () => {
28
- it('throws an error', () => {
29
- expect(() => {
30
- const stream = createStream({
31
- columnCount: 10,
32
- columnDefault: {
33
- width: 10
34
- }
35
- });
36
-
37
- stream.write(['foo']);
38
- }).to.throw(Error, 'Row cell count does not match the config.columnCount.');
39
- });
40
- });
41
- });
@@ -1,71 +0,0 @@
1
- /* eslint-disable sort-keys */
2
-
3
- import {
4
- expect
5
- } from 'chai';
6
- import {
7
- drawBorder,
8
- drawBorderTop,
9
- drawBorderJoin,
10
- drawBorderBottom
11
- } from './../src/drawBorder';
12
-
13
- describe('drawBorder', () => {
14
- it('draws a border using parts', () => {
15
- const parts = {
16
- left: '╔',
17
- right: '╗',
18
- body: '═',
19
- join: '╤'
20
- };
21
-
22
- expect(drawBorder([1], parts)).to.equal('╔═╗\n');
23
- expect(drawBorder([1, 1], parts)).to.equal('╔═╤═╗\n');
24
- expect(drawBorder([5, 10], parts)).to.equal('╔═════╤══════════╗\n');
25
- });
26
- });
27
-
28
- describe('drawBorderTop', () => {
29
- it('draws a border using parts', () => {
30
- const parts = {
31
- topLeft: '╔',
32
- topRight: '╗',
33
- topBody: '═',
34
- topJoin: '╤'
35
- };
36
-
37
- expect(drawBorderTop([1], parts)).to.equal('╔═╗\n');
38
- expect(drawBorderTop([1, 1], parts)).to.equal('╔═╤═╗\n');
39
- expect(drawBorderTop([5, 10], parts)).to.equal('╔═════╤══════════╗\n');
40
- });
41
- });
42
-
43
- describe('drawBorderJoin', () => {
44
- it('draws a border using parts', () => {
45
- const parts = {
46
- joinBody: '─',
47
- joinLeft: '╟',
48
- joinRight: '╢',
49
- joinJoin: '┼'
50
- };
51
-
52
- expect(drawBorderJoin([1], parts)).to.equal('╟─╢\n');
53
- expect(drawBorderJoin([1, 1], parts)).to.equal('╟─┼─╢\n');
54
- expect(drawBorderJoin([5, 10], parts)).to.equal('╟─────┼──────────╢\n');
55
- });
56
- });
57
-
58
- describe('drawBorderBottom', () => {
59
- it('draws a border using parts', () => {
60
- const parts = {
61
- bottomBody: '═',
62
- bottomJoin: '╧',
63
- bottomLeft: '╚',
64
- bottomRight: '╝'
65
- };
66
-
67
- expect(drawBorderBottom([1], parts)).to.equal('╚═╝\n');
68
- expect(drawBorderBottom([1, 1], parts)).to.equal('╚═╧═╝\n');
69
- expect(drawBorderBottom([5, 10], parts)).to.equal('╚═════╧══════════╝\n');
70
- });
71
- });
@@ -1,75 +0,0 @@
1
- /* eslint-disable max-nested-callbacks */
2
-
3
- import {
4
- expect
5
- } from 'chai';
6
- import makeConfig from './../src/makeConfig';
7
-
8
- describe('makeConfig', () => {
9
- it('does not affect the parameter configuration object', () => {
10
- const config = {};
11
-
12
- makeConfig([
13
- [
14
- 'aaaaa'
15
- ]
16
- ], config);
17
-
18
- expect(config).to.deep.equal({});
19
- });
20
-
21
- context('column', () => {
22
- context('"alignment"', () => {
23
- context('is not provided', () => {
24
- it('defaults to "left"', () => {
25
- const config = makeConfig([
26
- [
27
- 'aaaaa'
28
- ]
29
- ]);
30
-
31
- expect(config.columns[0].alignment).to.equal('left');
32
- });
33
- });
34
- });
35
- context('"width"', () => {
36
- context('is not provided', () => {
37
- it('defaults to the maximum column width', () => {
38
- const config = makeConfig([
39
- [
40
- 'aaaaa'
41
- ]
42
- ]);
43
-
44
- expect(config.columns[0].width).to.equal(5);
45
- });
46
- });
47
- });
48
- context('"paddingLeft"', () => {
49
- context('is not provided', () => {
50
- it('defaults to 1', () => {
51
- const config = makeConfig([
52
- [
53
- 'aaaaa'
54
- ]
55
- ]);
56
-
57
- expect(config.columns[0].paddingLeft).to.equal(1);
58
- });
59
- });
60
- });
61
- context('"paddingRight"', () => {
62
- context('is not provided', () => {
63
- it('defaults to 1', () => {
64
- const config = makeConfig([
65
- [
66
- 'aaaaa'
67
- ]
68
- ]);
69
-
70
- expect(config.columns[0].paddingRight).to.equal(1);
71
- });
72
- });
73
- });
74
- });
75
- });
@@ -1,119 +0,0 @@
1
- import {
2
- expect
3
- } from 'chai';
4
- import mapDataUsingRowHeightIndex from './../src/mapDataUsingRowHeightIndex';
5
-
6
- describe('mapDataUsingRowHeightIndex', () => {
7
- context('no data spans multiple rows', () => {
8
- it('maps data to a single cell', () => {
9
- const config = {
10
- columns: {
11
- 0: {
12
- width: 2
13
- }
14
- }
15
- };
16
-
17
- const rowSpanIndex = [
18
- 1
19
- ];
20
-
21
- const data = [
22
- [
23
- 'aa'
24
- ]
25
- ];
26
-
27
- const mappedData = mapDataUsingRowHeightIndex(data, rowSpanIndex, config);
28
-
29
- expect(mappedData).to.deep.equal([
30
- [
31
- 'aa'
32
- ]
33
- ]);
34
- });
35
- });
36
-
37
- context('single cell spans multiple rows', () => {
38
- it('maps data to multiple rows', () => {
39
- const config = {
40
- columns: {
41
- 0: {
42
- width: 2
43
- }
44
- }
45
- };
46
-
47
- const rowSpanIndex = [
48
- 5
49
- ];
50
-
51
- const data = [
52
- [
53
- 'aabbccddee'
54
- ]
55
- ];
56
-
57
- const mappedData = mapDataUsingRowHeightIndex(data, rowSpanIndex, config);
58
-
59
- expect(mappedData).to.deep.equal([
60
- ['aa'],
61
- ['bb'],
62
- ['cc'],
63
- ['dd'],
64
- ['ee']
65
- ]);
66
- });
67
- });
68
-
69
- context('multiple cells spans multiple rows', () => {
70
- it('maps data to multiple rows', () => {
71
- const config = {
72
- columns: {
73
- 0: {
74
- width: 2
75
- },
76
- 1: {
77
- width: 4
78
- }
79
- }
80
- };
81
-
82
- const rowSpanIndex = [
83
- 5
84
- ];
85
-
86
- const data = [
87
- [
88
- 'aabbccddee',
89
- '00001111'
90
- ]
91
- ];
92
-
93
- const mappedData = mapDataUsingRowHeightIndex(data, rowSpanIndex, config);
94
-
95
- expect(mappedData).to.deep.equal([
96
- [
97
- 'aa',
98
- '0000'
99
- ],
100
- [
101
- 'bb',
102
- '1111'
103
- ],
104
- [
105
- 'cc',
106
- ''
107
- ],
108
- [
109
- 'dd',
110
- ''
111
- ],
112
- [
113
- 'ee',
114
- ''
115
- ]
116
- ]);
117
- });
118
- });
119
- });
@@ -1,43 +0,0 @@
1
- import {
2
- expect
3
- } from 'chai';
4
- import configSamples from './streamConfigSamples';
5
- import validateConfig from '../dist/validateStreamConfig';
6
- import configSchema from '../src/schemas/streamConfig.json';
7
- import Ajv from 'ajv';
8
- import ajvKeywords from 'ajv-keywords';
9
-
10
- describe('streamConfig.json schema', () => {
11
- var validate;
12
-
13
- before(() => {
14
- var ajv = new Ajv({allErrors: true});
15
- ajvKeywords(ajv, 'typeof');
16
- validate = ajv.compile(configSchema);
17
- });
18
-
19
- it('should pass validation of valid streamConfig samples', () => {
20
- configSamples.valid.forEach((sample, i) => {
21
- testValid(sample, validate);
22
- testValid(sample, validateConfig);
23
- });
24
-
25
- function testValid(sample, validate) {
26
- var valid = validate(sample);
27
- if (!valid) console.log(validate.errors);
28
- expect(valid).to.equal(true);
29
- }
30
- });
31
-
32
- it('should fail validation of invalid streamConfig samples', () => {
33
- configSamples.invalid.forEach((sample, i) => {
34
- testInvalid(sample, validate);
35
- testInvalid(sample, validateConfig);
36
- });
37
-
38
- function testInvalid(sample, validate) {
39
- var valid = validate(sample);
40
- expect(valid).to.equal(false);
41
- }
42
- });
43
- });