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.
- package/README.md +35 -16
- package/dist/alignString.js +19 -842
- package/dist/alignTableData.js +4 -226
- package/dist/calculateCellHeight.js +6 -343
- package/dist/calculateCellWidthIndex.js +2 -112
- package/dist/calculateMaximumColumnWidthIndex.js +5 -299
- package/dist/calculateRowHeightIndex.js +8 -333
- package/dist/createStream.js +19 -814
- package/dist/drawBorder.js +11 -292
- package/dist/drawRow.js +1 -69
- package/dist/drawTable.js +7 -474
- package/dist/getBorderCharacters.js +1 -315
- package/dist/index.js +4 -28
- package/dist/makeConfig.js +15 -544
- package/dist/makeStreamConfig.js +13 -587
- package/dist/mapDataUsingRowHeightIndex.js +9 -349
- package/dist/padTableData.js +5 -166
- package/dist/schemas/config.json +2 -2
- package/dist/schemas/streamConfig.json +2 -2
- package/dist/stringifyTableData.js +4 -116
- package/dist/table.js +5 -203
- package/dist/truncateTableData.js +3 -147
- package/dist/validateConfig.js +20 -23
- package/dist/validateStreamConfig.js +17 -19
- package/dist/validateTableData.js +11 -528
- package/dist/wrapString.js +3 -135
- package/dist/wrapWord.js +4 -257
- package/package.json +27 -24
- package/test/README/usage/basic.js +0 -25
- package/test/README/usage/cell_content_alignment.js +0 -45
- package/test/README/usage/column_width.js +0 -33
- package/test/README/usage/custom_border.js +0 -50
- package/test/README/usage/draw_horizontal_line.js +0 -41
- package/test/README/usage/expectTable.js +0 -13
- package/test/README/usage/moon_mission.js +0 -67
- package/test/README/usage/padding_cell_content.js +0 -39
- package/test/README/usage/predefined_border_templates.js +0 -91
- package/test/README/usage/streaming.js +0 -56
- package/test/README/usage/text_truncating.js +0 -32
- package/test/README/usage/text_wrapping.js +0 -67
- package/test/alignString.js +0 -102
- package/test/calculateCellHeight.js +0 -44
- package/test/calculateCellWidthIndex.js +0 -20
- package/test/calculateMaximumColumnWidthIndex.js +0 -59
- package/test/calculateRowHeightIndex.js +0 -78
- package/test/config.js +0 -43
- package/test/configSamples.js +0 -153
- package/test/createStream.js +0 -41
- package/test/drawBorder.js +0 -71
- package/test/makeConfig.js +0 -75
- package/test/mapDataUsingRowHeightIndex.js +0 -119
- package/test/streamConfig.js +0 -43
- package/test/streamConfigSamples.js +0 -151
- package/test/validateTableData.js +0 -65
- package/test/wrapString.js +0 -45
- package/test/wrapWord.js +0 -32
package/test/configSamples.js
DELETED
|
@@ -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
|
-
};
|
package/test/createStream.js
DELETED
|
@@ -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
|
-
});
|
package/test/drawBorder.js
DELETED
|
@@ -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
|
-
});
|
package/test/makeConfig.js
DELETED
|
@@ -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
|
-
});
|
package/test/streamConfig.js
DELETED
|
@@ -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
|
-
});
|
|
@@ -1,151 +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
|
-
],
|
|
111
|
-
invalid: [
|
|
112
|
-
{ border: 1 },
|
|
113
|
-
{ border: { unknown: '-' } },
|
|
114
|
-
{ border: { topBody: 1 } },
|
|
115
|
-
{ border: { topJoin: 1 } },
|
|
116
|
-
{ border: { topLeft: 1 } },
|
|
117
|
-
{ border: { topRight: 1 } },
|
|
118
|
-
{ border: { bottomBody: 1 } },
|
|
119
|
-
{ border: { bottomJoin: 1 } },
|
|
120
|
-
{ border: { bottomLeft: 1 } },
|
|
121
|
-
{ border: { bottomRight: 1 } },
|
|
122
|
-
{ border: { bodyLeft: 1 } },
|
|
123
|
-
{ border: { bodyRight: 1 } },
|
|
124
|
-
{ border: { bodyJoin: 1 } },
|
|
125
|
-
{ border: { joinBody: 1 } },
|
|
126
|
-
{ border: { joinLeft: 1 } },
|
|
127
|
-
{ border: { joinRight: 1 } },
|
|
128
|
-
{ border: { joinJoin: 1 } },
|
|
129
|
-
{ columns: 1 },
|
|
130
|
-
{ columns: { a: { width: 5 } } },
|
|
131
|
-
{ columns: { '1': 1 } },
|
|
132
|
-
{ columns: { '1': { unknown: 1 } } },
|
|
133
|
-
{ columns: { '1': { alignment: 1 } } },
|
|
134
|
-
{ columns: { '1': { alignment: '1' } } },
|
|
135
|
-
{ columns: { '1': { width: '5' } } },
|
|
136
|
-
{ columns: { '1': { wrapWord: 1 } } },
|
|
137
|
-
{ columns: { '1': { truncate: '1' } } },
|
|
138
|
-
{ columns: { '1': { paddingLeft: '1' } } },
|
|
139
|
-
{ columns: { '1': { paddingRight: '1' } } },
|
|
140
|
-
{ columnDefault: 1 },
|
|
141
|
-
{ columnDefault: { unknown: 1 } },
|
|
142
|
-
{ columnDefault: { alignment: 1 } },
|
|
143
|
-
{ columnDefault: { alignment: '1' } },
|
|
144
|
-
{ columnDefault: { width: '5' } },
|
|
145
|
-
{ columnDefault: { wrapWord: 1 } },
|
|
146
|
-
{ columnDefault: { truncate: '1' } },
|
|
147
|
-
{ columnDefault: { paddingLeft: '1' } },
|
|
148
|
-
{ columnDefault: { paddingRight: '1' } },
|
|
149
|
-
{ unknown: 1 }
|
|
150
|
-
]
|
|
151
|
-
};
|