table 3.8.0 → 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.
- package/README.md +34 -15
- package/dist/alignString.js +4 -6
- package/dist/alignTableData.js +3 -9
- package/dist/calculateCellHeight.js +4 -6
- package/dist/calculateCellWidthIndex.js +2 -8
- package/dist/calculateMaximumColumnWidthIndex.js +1 -3
- package/dist/calculateRowHeightIndex.js +3 -5
- package/dist/createStream.js +3 -5
- package/dist/drawRow.js +1 -3
- package/dist/drawTable.js +4 -4
- package/dist/getBorderCharacters.js +1 -3
- package/dist/index.js +4 -4
- package/dist/makeConfig.js +8 -10
- package/dist/makeStreamConfig.js +7 -9
- package/dist/mapDataUsingRowHeightIndex.js +2 -4
- package/dist/padTableData.js +1 -3
- package/dist/schemas/config.json +2 -2
- package/dist/schemas/streamConfig.json +2 -2
- package/dist/stringifyTableData.js +4 -12
- package/dist/table.js +2 -4
- package/dist/truncateTableData.js +1 -3
- package/dist/validateConfig.js +749 -58
- package/dist/validateStreamConfig.js +737 -50
- package/dist/validateTableData.js +10 -18
- package/dist/wrapString.js +1 -3
- package/dist/wrapWord.js +1 -3
- package/package.json +40 -22
- package/dist/alignString.js.map +0 -1
- package/dist/alignTableData.js.map +0 -1
- package/dist/calculateCellHeight.js.map +0 -1
- package/dist/calculateCellWidthIndex.js.map +0 -1
- package/dist/calculateMaximumColumnWidthIndex.js.map +0 -1
- package/dist/calculateRowHeightIndex.js.map +0 -1
- package/dist/createStream.js.map +0 -1
- package/dist/drawBorder.js.map +0 -1
- package/dist/drawRow.js.map +0 -1
- package/dist/drawTable.js.map +0 -1
- package/dist/getBorderCharacters.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/makeConfig.js.map +0 -1
- package/dist/makeStreamConfig.js.map +0 -1
- package/dist/mapDataUsingRowHeightIndex.js.map +0 -1
- package/dist/padTableData.js.map +0 -1
- package/dist/stringifyTableData.js.map +0 -1
- package/dist/table.js.map +0 -1
- package/dist/truncateTableData.js.map +0 -1
- package/dist/validateConfig.js.map +0 -1
- package/dist/validateStreamConfig.js.map +0 -1
- package/dist/validateTableData.js.map +0 -1
- package/dist/wrapString.js.map +0 -1
- package/dist/wrapWord.js.map +0 -1
- 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/createStream.js +0 -41
- package/test/drawBorder.js +0 -71
- package/test/makeConfig.js +0 -75
- package/test/mapDataUsingRowHeightIndex.js +0 -119
- package/test/validateTableData.js +0 -65
- package/test/wrapString.js +0 -45
- package/test/wrapWord.js +0 -32
|
@@ -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
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import table, {
|
|
3
|
-
getBorderCharacters
|
|
4
|
-
} from './../../../src';
|
|
5
|
-
import expectTable from './expectTable';
|
|
6
|
-
|
|
7
|
-
describe('README.md usage/predefined_border_templates', () => {
|
|
8
|
-
let data;
|
|
9
|
-
|
|
10
|
-
before(() => {
|
|
11
|
-
data = [
|
|
12
|
-
['0A', '0B', '0C'],
|
|
13
|
-
['1A', '1B', '1C'],
|
|
14
|
-
['2A', '2B', '2C']
|
|
15
|
-
];
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('honeywell', () => {
|
|
19
|
-
const output = table(data, {
|
|
20
|
-
border: getBorderCharacters('honeywell')
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
24
|
-
expectTable(output, `
|
|
25
|
-
╔════╤════╤════╗
|
|
26
|
-
║ 0A │ 0B │ 0C ║
|
|
27
|
-
╟────┼────┼────╢
|
|
28
|
-
║ 1A │ 1B │ 1C ║
|
|
29
|
-
╟────┼────┼────╢
|
|
30
|
-
║ 2A │ 2B │ 2C ║
|
|
31
|
-
╚════╧════╧════╝
|
|
32
|
-
`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('norc', () => {
|
|
36
|
-
const output = table(data, {
|
|
37
|
-
border: getBorderCharacters('norc')
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
41
|
-
expectTable(output, `
|
|
42
|
-
┌────┬────┬────┐
|
|
43
|
-
│ 0A │ 0B │ 0C │
|
|
44
|
-
├────┼────┼────┤
|
|
45
|
-
│ 1A │ 1B │ 1C │
|
|
46
|
-
├────┼────┼────┤
|
|
47
|
-
│ 2A │ 2B │ 2C │
|
|
48
|
-
└────┴────┴────┘
|
|
49
|
-
`);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('ramac', () => {
|
|
53
|
-
const output = table(data, {
|
|
54
|
-
border: getBorderCharacters('ramac')
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
58
|
-
expectTable(output, `
|
|
59
|
-
+----+----+----+
|
|
60
|
-
| 0A | 0B | 0C |
|
|
61
|
-
|----|----|----|
|
|
62
|
-
| 1A | 1B | 1C |
|
|
63
|
-
|----|----|----|
|
|
64
|
-
| 2A | 2B | 2C |
|
|
65
|
-
+----+----+----+
|
|
66
|
-
`);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('void', () => {
|
|
70
|
-
const output = table(data, {
|
|
71
|
-
border: getBorderCharacters('void')
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expectTable(_.trim(output) + '\n', '0A 0B 0C \n\n 1A 1B 1C \n\n 2A 2B 2C');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('borderless', () => {
|
|
78
|
-
const output = table(data, {
|
|
79
|
-
border: getBorderCharacters('void'),
|
|
80
|
-
columnDefault: {
|
|
81
|
-
paddingLeft: 0,
|
|
82
|
-
paddingRight: 1
|
|
83
|
-
},
|
|
84
|
-
drawHorizontalLine: () => {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expectTable(_.trim(output) + '\n', '0A 0B 0C \n1A 1B 1C \n2A 2B 2C');
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStream
|
|
3
|
-
} from './../../../src';
|
|
4
|
-
import expectTable from './expectTable';
|
|
5
|
-
|
|
6
|
-
describe('README.md usage/', () => {
|
|
7
|
-
describe('process.stdout.write', () => {
|
|
8
|
-
let processStdoutWriteBuffer;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @var {Function} Reference to the original process.stdout.write function.
|
|
12
|
-
*/
|
|
13
|
-
const processStdoutWrite = process.stdout.write;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @returns {undefined}
|
|
17
|
-
*/
|
|
18
|
-
const overwriteProcessStdoutWrite = () => {
|
|
19
|
-
processStdoutWriteBuffer = '';
|
|
20
|
-
|
|
21
|
-
process.stdout.write = (text) => {
|
|
22
|
-
processStdoutWriteBuffer += text;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @returns {string}
|
|
28
|
-
*/
|
|
29
|
-
const resetProcessStdoudWrite = () => {
|
|
30
|
-
process.stdout.write = processStdoutWrite;
|
|
31
|
-
|
|
32
|
-
return processStdoutWriteBuffer;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
it('streaming', () => {
|
|
36
|
-
const config = {
|
|
37
|
-
columnCount: 3,
|
|
38
|
-
columnDefault: {
|
|
39
|
-
width: 2
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const stream = createStream(config);
|
|
44
|
-
|
|
45
|
-
overwriteProcessStdoutWrite();
|
|
46
|
-
|
|
47
|
-
stream.write(['0A', '0B', '0C']);
|
|
48
|
-
stream.write(['1A', '1B', '1C']);
|
|
49
|
-
stream.write(['2A', '2B', '2C']);
|
|
50
|
-
|
|
51
|
-
const output = resetProcessStdoudWrite();
|
|
52
|
-
|
|
53
|
-
expectTable(output + '\n', '╔════╤════╤════╗\n║ 0A │ 0B │ 0C ║\n╚════╧════╧════╝\r\u001b[K╟────┼────┼────╢\n║ 1A │ 1B │ 1C ║\n╚════╧════╧════╝\r\u001b[K╟────┼────┼────╢\n║ 2A │ 2B │ 2C ║\n╚════╧════╧════╝');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import table from './../../../src';
|
|
2
|
-
import expectTable from './expectTable';
|
|
3
|
-
|
|
4
|
-
describe('README.md usage/', () => {
|
|
5
|
-
it('text_truncating', () => {
|
|
6
|
-
const data = [
|
|
7
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
const config = {
|
|
11
|
-
columns: {
|
|
12
|
-
0: {
|
|
13
|
-
truncate: 100,
|
|
14
|
-
width: 20
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const output = table(data, config);
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
22
|
-
expectTable(output, `
|
|
23
|
-
╔══════════════════════╗
|
|
24
|
-
║ Lorem ipsum dolor si ║
|
|
25
|
-
║ t amet, consectetur ║
|
|
26
|
-
║ adipiscing elit. Pha ║
|
|
27
|
-
║ sellus pulvinar nibh ║
|
|
28
|
-
║ sed mauris conva... ║
|
|
29
|
-
╚══════════════════════╝
|
|
30
|
-
`);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import table from './../../../src';
|
|
2
|
-
import expectTable from './expectTable';
|
|
3
|
-
|
|
4
|
-
describe('README.md usage/', () => {
|
|
5
|
-
it('text_wrapping (no wrap word)', () => {
|
|
6
|
-
const data = [
|
|
7
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
const config = {
|
|
11
|
-
columns: {
|
|
12
|
-
0: {
|
|
13
|
-
width: 20
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const output = table(data, config);
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
21
|
-
expectTable(output, `
|
|
22
|
-
╔══════════════════════╗
|
|
23
|
-
║ Lorem ipsum dolor si ║
|
|
24
|
-
║ t amet, consectetur ║
|
|
25
|
-
║ adipiscing elit. Pha ║
|
|
26
|
-
║ sellus pulvinar nibh ║
|
|
27
|
-
║ sed mauris convallis ║
|
|
28
|
-
║ dapibus. Nunc venena ║
|
|
29
|
-
║ tis tempus nulla sit ║
|
|
30
|
-
║ amet viverra. ║
|
|
31
|
-
╚══════════════════════╝
|
|
32
|
-
`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('text_wrapping (wrap word)', () => {
|
|
36
|
-
const data = [
|
|
37
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
const config = {
|
|
41
|
-
columns: {
|
|
42
|
-
0: {
|
|
43
|
-
width: 20,
|
|
44
|
-
wrapWord: true
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const output = table(data, config);
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
52
|
-
expectTable(output, `
|
|
53
|
-
╔══════════════════════╗
|
|
54
|
-
║ Lorem ipsum dolor ║
|
|
55
|
-
║ sit amet, ║
|
|
56
|
-
║ consectetur ║
|
|
57
|
-
║ adipiscing elit. ║
|
|
58
|
-
║ Phasellus pulvinar ║
|
|
59
|
-
║ nibh sed mauris ║
|
|
60
|
-
║ convallis dapibus. ║
|
|
61
|
-
║ Nunc venenatis ║
|
|
62
|
-
║ tempus nulla sit ║
|
|
63
|
-
║ amet viverra. ║
|
|
64
|
-
╚══════════════════════╝
|
|
65
|
-
`);
|
|
66
|
-
});
|
|
67
|
-
});
|
package/test/alignString.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-nested-callbacks */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
expect
|
|
5
|
-
} from 'chai';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import alignString from './../src/alignString';
|
|
8
|
-
|
|
9
|
-
describe('alignString', () => {
|
|
10
|
-
context('subject parameter value is not a string', () => {
|
|
11
|
-
it('throws an error', () => {
|
|
12
|
-
expect(() => {
|
|
13
|
-
alignString();
|
|
14
|
-
}).to.throw(Error, 'Subject parameter value must be a string.');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
context('container width parameter value is not a string', () => {
|
|
18
|
-
it('throws an error', () => {
|
|
19
|
-
expect(() => {
|
|
20
|
-
alignString('');
|
|
21
|
-
}).to.throw(Error, 'Container width parameter value must be a number.');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
context('subject parameter value width is greater than the container width', () => {
|
|
25
|
-
it('throws an error', () => {
|
|
26
|
-
expect(() => {
|
|
27
|
-
alignString('aa', 1, 'left');
|
|
28
|
-
}).to.throw(Error, 'Subject parameter value width cannot be greater than the container width.');
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
context('container alignment parameter value is not a string', () => {
|
|
32
|
-
it('throws an error', () => {
|
|
33
|
-
expect(() => {
|
|
34
|
-
alignString('', 1);
|
|
35
|
-
}).to.throw(Error, 'Alignment parameter value must be a string.');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
context('container alignment parameter value is not a known alignment parameter value', () => {
|
|
39
|
-
it('throws an error', () => {
|
|
40
|
-
expect(() => {
|
|
41
|
-
alignString('', 1, 'foo');
|
|
42
|
-
}).to.throw(Error, 'Alignment parameter value must be a known alignment parameter value (left, right, center).');
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
context('subject parameter value', () => {
|
|
46
|
-
context('0 width', () => {
|
|
47
|
-
it('produces a string consisting of container width number of whitespace characters', () => {
|
|
48
|
-
expect(alignString('', 5, 'left')).to.equal(' ', 'left');
|
|
49
|
-
expect(alignString('', 5, 'center')).to.equal(' ', 'center');
|
|
50
|
-
expect(alignString('', 5, 'right')).to.equal(' ', 'right');
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
context('plain text', () => {
|
|
54
|
-
context('alignment', () => {
|
|
55
|
-
context('left', () => {
|
|
56
|
-
it('pads the string on the right side using a whitespace character', () => {
|
|
57
|
-
expect(alignString('aa', 6, 'left')).to.equal('aa ');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
context('right', () => {
|
|
61
|
-
it('pads the string on the left side using a whitespace character', () => {
|
|
62
|
-
expect(alignString('aa', 6, 'right')).to.equal(' aa');
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
context('center', () => {
|
|
66
|
-
it('pads the string on both sides using a whitespace character', () => {
|
|
67
|
-
expect(alignString('aa', 6, 'center')).to.equal(' aa ');
|
|
68
|
-
});
|
|
69
|
-
context('uneven number of available with', () => {
|
|
70
|
-
it('floors the available width; adds extra space to the end of the string', () => {
|
|
71
|
-
expect(alignString('aa', 7, 'center')).to.equal(' aa ');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
context('text containing ANSI escape codes', () => {
|
|
78
|
-
context('alignment', () => {
|
|
79
|
-
context('left', () => {
|
|
80
|
-
it('pads the string on the right side using a whitespace character', () => {
|
|
81
|
-
expect(alignString(chalk.red('aa'), 6, 'left')).to.equal(chalk.red('aa') + ' ');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
context('right', () => {
|
|
85
|
-
it('pads the string on the left side using a whitespace character', () => {
|
|
86
|
-
expect(alignString(chalk.red('aa'), 6, 'right')).to.equal(' ' + chalk.red('aa'));
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
context('center', () => {
|
|
90
|
-
it('pads the string on both sides using a whitespace character', () => {
|
|
91
|
-
expect(alignString(chalk.red('aa'), 6, 'center')).to.equal(' ' + chalk.red('aa') + ' ');
|
|
92
|
-
});
|
|
93
|
-
context('uneven number of available with', () => {
|
|
94
|
-
it('floors the available width; adds extra space to the end of the string', () => {
|
|
95
|
-
expect(alignString(chalk.red('aa'), 7, 'center')).to.equal(' ' + chalk.red('aa') + ' ');
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-nested-callbacks */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
expect
|
|
5
|
-
} from 'chai';
|
|
6
|
-
import calculateCellHeight from './../src/calculateCellHeight';
|
|
7
|
-
|
|
8
|
-
describe('calculateCellHeight', () => {
|
|
9
|
-
describe('value', () => {
|
|
10
|
-
context('is not a string', () => {
|
|
11
|
-
it('throws an error', () => {
|
|
12
|
-
expect(() => {
|
|
13
|
-
calculateCellHeight(null);
|
|
14
|
-
}).to.throw(Error, 'Value must be a string.');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('context width', () => {
|
|
19
|
-
context('is not an integer', () => {
|
|
20
|
-
it('throws an error', () => {
|
|
21
|
-
expect(() => {
|
|
22
|
-
calculateCellHeight('foo', null);
|
|
23
|
-
}).to.throw(Error, 'Column width must be an integer.');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
context('is 0', () => {
|
|
27
|
-
it('throws an error', () => {
|
|
28
|
-
expect(() => {
|
|
29
|
-
calculateCellHeight('foo', 0);
|
|
30
|
-
}).to.throw(Error, 'Column width must be greater than 0.');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
context('is lesser than the column width', () => {
|
|
34
|
-
it('has height 1', () => {
|
|
35
|
-
expect(calculateCellHeight('foo', 10)).to.equal(1);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
context('is 2 and half times greater than the column width', () => {
|
|
39
|
-
it('has height 3', () => {
|
|
40
|
-
expect(calculateCellHeight('aabbc', 2)).to.equal(3);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expect
|
|
3
|
-
} from 'chai';
|
|
4
|
-
import calculateCellWidthIndex from './../src/calculateCellWidthIndex';
|
|
5
|
-
|
|
6
|
-
describe('calculateCellWidthIndex', () => {
|
|
7
|
-
context('all cells have different width', () => {
|
|
8
|
-
it('describes each cell contents width', () => {
|
|
9
|
-
const cellWidthIndex = calculateCellWidthIndex([
|
|
10
|
-
'a',
|
|
11
|
-
'aaa',
|
|
12
|
-
'aaaaaa'
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
expect(cellWidthIndex[0]).to.equal(1, 'first column');
|
|
16
|
-
expect(cellWidthIndex[1]).to.equal(3, 'second column');
|
|
17
|
-
expect(cellWidthIndex[2]).to.equal(6, 'third column');
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
expect
|
|
3
|
-
} from 'chai';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import calculateMaximumColumnWidthIndex from './../src/calculateMaximumColumnWidthIndex';
|
|
6
|
-
|
|
7
|
-
describe('calculateMaximumColumnWidthIndex', () => {
|
|
8
|
-
it('throws an error when attempting to calculate maximum column value index for an empty data set', () => {
|
|
9
|
-
expect(() => {
|
|
10
|
-
calculateMaximumColumnWidthIndex([]);
|
|
11
|
-
}).to.throw(Error, 'Dataset must have at least one row.');
|
|
12
|
-
});
|
|
13
|
-
it('calculates the maximum column value index', () => {
|
|
14
|
-
const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
|
|
15
|
-
[
|
|
16
|
-
'',
|
|
17
|
-
'a',
|
|
18
|
-
'b',
|
|
19
|
-
'c'
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
'',
|
|
23
|
-
'a',
|
|
24
|
-
'bbbbbbbbbb',
|
|
25
|
-
'c'
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
'',
|
|
29
|
-
'',
|
|
30
|
-
'b',
|
|
31
|
-
'ccccc'
|
|
32
|
-
]
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
expect(maximumColumnValueIndex).to.deep.equal([0, 1, 10, 5]);
|
|
36
|
-
});
|
|
37
|
-
context('cell values contain ANSI codes', () => {
|
|
38
|
-
it('uses visual width of the string', () => {
|
|
39
|
-
const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
|
|
40
|
-
[
|
|
41
|
-
chalk.red('aaaaa')
|
|
42
|
-
]
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
expect(maximumColumnValueIndex[0]).to.equal(5);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
context('cell values contain fullwidth characters', () => {
|
|
49
|
-
it('uses visual width of the string', () => {
|
|
50
|
-
const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
|
|
51
|
-
[
|
|
52
|
-
chalk.red('古')
|
|
53
|
-
]
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
expect(maximumColumnValueIndex[0]).to.equal(2);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -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/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
|
-
});
|