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.
- package/dist/alignString.js +3 -3
- package/dist/alignTableData.js +2 -6
- package/dist/calculateCellHeight.js +2 -2
- package/dist/calculateCellWidthIndex.js +1 -5
- package/dist/calculateRowHeightIndex.js +2 -2
- package/dist/createStream.js +1 -1
- package/dist/drawTable.js +3 -1
- package/dist/makeConfig.js +3 -3
- package/dist/makeStreamConfig.js +2 -2
- package/dist/mapDataUsingRowHeightIndex.js +1 -1
- package/dist/schemas/config.json +2 -2
- package/dist/schemas/streamConfig.json +2 -2
- package/dist/stringifyTableData.js +3 -9
- package/dist/validateConfig.js +20 -23
- package/dist/validateStreamConfig.js +17 -19
- package/dist/validateTableData.js +9 -15
- package/package.json +22 -22
- package/test/README/usage/basic.js +0 -27
- package/test/README/usage/cell_content_alignment.js +0 -47
- package/test/README/usage/column_width.js +0 -35
- package/test/README/usage/custom_border.js +0 -52
- package/test/README/usage/draw_horizontal_line.js +0 -43
- package/test/README/usage/expectTable.js +0 -13
- package/test/README/usage/moon_mission.js +0 -68
- package/test/README/usage/padding_cell_content.js +0 -41
- package/test/README/usage/predefined_border_templates.js +0 -92
- package/test/README/usage/streaming.js +0 -56
- package/test/README/usage/text_truncating.js +0 -34
- package/test/README/usage/text_wrapping.js +0 -69
- 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
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
table
|
|
3
|
-
} from './../../../src';
|
|
4
|
-
import expectTable from './expectTable';
|
|
5
|
-
|
|
6
|
-
describe('README.md usage/', () => {
|
|
7
|
-
it('usage/draw_horizontal_line', () => {
|
|
8
|
-
const data = [
|
|
9
|
-
['0A', '0B', '0C'],
|
|
10
|
-
['1A', '1B', '1C'],
|
|
11
|
-
['2A', '2B', '2C'],
|
|
12
|
-
['3A', '3B', '3C'],
|
|
13
|
-
['4A', '4B', '4C']
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const options = {
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {Function} drawJoin
|
|
19
|
-
* @param {number} index
|
|
20
|
-
* @param {number} size
|
|
21
|
-
* @returns {boolean}
|
|
22
|
-
*/
|
|
23
|
-
drawHorizontalLine: (index, size) => {
|
|
24
|
-
return index === 0 || index === 1 || index === size - 1 || index === size;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const output = table(data, options);
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
31
|
-
expectTable(output, `
|
|
32
|
-
╔════╤════╤════╗
|
|
33
|
-
║ 0A │ 0B │ 0C ║
|
|
34
|
-
╟────┼────┼────╢
|
|
35
|
-
║ 1A │ 1B │ 1C ║
|
|
36
|
-
║ 2A │ 2B │ 2C ║
|
|
37
|
-
║ 3A │ 3B │ 3C ║
|
|
38
|
-
╟────┼────┼────╢
|
|
39
|
-
║ 4A │ 4B │ 4C ║
|
|
40
|
-
╚════╧════╧════╝
|
|
41
|
-
`);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -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,68 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
table,
|
|
5
|
-
getBorderCharacters
|
|
6
|
-
} from './../../../src';
|
|
7
|
-
|
|
8
|
-
describe('README.md usage/', () => {
|
|
9
|
-
it('moon_mission', () => {
|
|
10
|
-
const data = [
|
|
11
|
-
[
|
|
12
|
-
chalk.bold('Spacecraft'),
|
|
13
|
-
chalk.bold('Launch Date'),
|
|
14
|
-
chalk.bold('Operator'),
|
|
15
|
-
chalk.bold('Outcome'),
|
|
16
|
-
chalk.bold('Remarks')
|
|
17
|
-
],
|
|
18
|
-
[
|
|
19
|
-
'Able I',
|
|
20
|
-
'17 August 1958',
|
|
21
|
-
'USAF',
|
|
22
|
-
chalk.white.bold.bgRed('Launch failure'),
|
|
23
|
-
'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)'
|
|
24
|
-
],
|
|
25
|
-
[
|
|
26
|
-
'Luna 2',
|
|
27
|
-
'12 September 1959',
|
|
28
|
-
'OKB-1',
|
|
29
|
-
chalk.black.bgGreen('Successful'),
|
|
30
|
-
'Successful impact at 21:02 on 14 September 1959. First spacecraft to reach lunar surface'
|
|
31
|
-
],
|
|
32
|
-
[
|
|
33
|
-
'Lunar Orbiter 1',
|
|
34
|
-
'10 August 1966',
|
|
35
|
-
'NASA',
|
|
36
|
-
chalk.black.bgYellow('Partial failure'),
|
|
37
|
-
'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.'
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
'Apollo 8',
|
|
41
|
-
'21 December 1968',
|
|
42
|
-
'NASA',
|
|
43
|
-
chalk.black.bgGreen('Successful'),
|
|
44
|
-
'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.'
|
|
45
|
-
],
|
|
46
|
-
[
|
|
47
|
-
'Apollo 11',
|
|
48
|
-
'16 July 1969',
|
|
49
|
-
'NASA',
|
|
50
|
-
chalk.black.bgGreen('Successful'),
|
|
51
|
-
'First manned landing on the Moon. LM landed at 20:17 UTC on 20 July 1969'
|
|
52
|
-
]
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
const tableBorder = _.mapValues(getBorderCharacters('honeywell'), (char) => {
|
|
56
|
-
return chalk.gray(char);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
table(data, {
|
|
60
|
-
border: tableBorder,
|
|
61
|
-
columns: {
|
|
62
|
-
4: {
|
|
63
|
-
width: 50
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
table
|
|
3
|
-
} from './../../../src';
|
|
4
|
-
import expectTable from './expectTable';
|
|
5
|
-
|
|
6
|
-
describe('README.md usage/', () => {
|
|
7
|
-
it('usage/padding_cell_content', () => {
|
|
8
|
-
const data = [
|
|
9
|
-
['0A', 'AABBCC', '0C'],
|
|
10
|
-
['1A', '1B', '1C'],
|
|
11
|
-
['2A', '2B', '2C']
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
const config = {
|
|
15
|
-
columns: {
|
|
16
|
-
0: {
|
|
17
|
-
paddingLeft: 3
|
|
18
|
-
},
|
|
19
|
-
1: {
|
|
20
|
-
paddingRight: 3,
|
|
21
|
-
width: 2
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const output = table(data, config);
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
29
|
-
expectTable(output, `
|
|
30
|
-
╔══════╤══════╤════╗
|
|
31
|
-
║ 0A │ AA │ 0C ║
|
|
32
|
-
║ │ BB │ ║
|
|
33
|
-
║ │ CC │ ║
|
|
34
|
-
╟──────┼──────┼────╢
|
|
35
|
-
║ 1A │ 1B │ 1C ║
|
|
36
|
-
╟──────┼──────┼────╢
|
|
37
|
-
║ 2A │ 2B │ 2C ║
|
|
38
|
-
╚══════╧══════╧════╝
|
|
39
|
-
`);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import {
|
|
3
|
-
table,
|
|
4
|
-
getBorderCharacters
|
|
5
|
-
} from './../../../src';
|
|
6
|
-
import expectTable from './expectTable';
|
|
7
|
-
|
|
8
|
-
describe('README.md usage/predefined_border_templates', () => {
|
|
9
|
-
let data;
|
|
10
|
-
|
|
11
|
-
before(() => {
|
|
12
|
-
data = [
|
|
13
|
-
['0A', '0B', '0C'],
|
|
14
|
-
['1A', '1B', '1C'],
|
|
15
|
-
['2A', '2B', '2C']
|
|
16
|
-
];
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('honeywell', () => {
|
|
20
|
-
const output = table(data, {
|
|
21
|
-
border: getBorderCharacters('honeywell')
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
25
|
-
expectTable(output, `
|
|
26
|
-
╔════╤════╤════╗
|
|
27
|
-
║ 0A │ 0B │ 0C ║
|
|
28
|
-
╟────┼────┼────╢
|
|
29
|
-
║ 1A │ 1B │ 1C ║
|
|
30
|
-
╟────┼────┼────╢
|
|
31
|
-
║ 2A │ 2B │ 2C ║
|
|
32
|
-
╚════╧════╧════╝
|
|
33
|
-
`);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('norc', () => {
|
|
37
|
-
const output = table(data, {
|
|
38
|
-
border: getBorderCharacters('norc')
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
42
|
-
expectTable(output, `
|
|
43
|
-
┌────┬────┬────┐
|
|
44
|
-
│ 0A │ 0B │ 0C │
|
|
45
|
-
├────┼────┼────┤
|
|
46
|
-
│ 1A │ 1B │ 1C │
|
|
47
|
-
├────┼────┼────┤
|
|
48
|
-
│ 2A │ 2B │ 2C │
|
|
49
|
-
└────┴────┴────┘
|
|
50
|
-
`);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('ramac', () => {
|
|
54
|
-
const output = table(data, {
|
|
55
|
-
border: getBorderCharacters('ramac')
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
59
|
-
expectTable(output, `
|
|
60
|
-
+----+----+----+
|
|
61
|
-
| 0A | 0B | 0C |
|
|
62
|
-
|----|----|----|
|
|
63
|
-
| 1A | 1B | 1C |
|
|
64
|
-
|----|----|----|
|
|
65
|
-
| 2A | 2B | 2C |
|
|
66
|
-
+----+----+----+
|
|
67
|
-
`);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('void', () => {
|
|
71
|
-
const output = table(data, {
|
|
72
|
-
border: getBorderCharacters('void')
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
expectTable(_.trim(output) + '\n', '0A 0B 0C \n\n 1A 1B 1C \n\n 2A 2B 2C');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('borderless', () => {
|
|
79
|
-
const output = table(data, {
|
|
80
|
-
border: getBorderCharacters('void'),
|
|
81
|
-
columnDefault: {
|
|
82
|
-
paddingLeft: 0,
|
|
83
|
-
paddingRight: 1
|
|
84
|
-
},
|
|
85
|
-
drawHorizontalLine: () => {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
expectTable(_.trim(output) + '\n', '0A 0B 0C \n1A 1B 1C \n2A 2B 2C');
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -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,34 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
table
|
|
3
|
-
} from './../../../src';
|
|
4
|
-
import expectTable from './expectTable';
|
|
5
|
-
|
|
6
|
-
describe('README.md usage/', () => {
|
|
7
|
-
it('text_truncating', () => {
|
|
8
|
-
const data = [
|
|
9
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
const config = {
|
|
13
|
-
columns: {
|
|
14
|
-
0: {
|
|
15
|
-
truncate: 100,
|
|
16
|
-
width: 20
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const output = table(data, config);
|
|
22
|
-
|
|
23
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
24
|
-
expectTable(output, `
|
|
25
|
-
╔══════════════════════╗
|
|
26
|
-
║ Lorem ipsum dolor si ║
|
|
27
|
-
║ t amet, consectetur ║
|
|
28
|
-
║ adipiscing elit. Pha ║
|
|
29
|
-
║ sellus pulvinar nibh ║
|
|
30
|
-
║ sed mauris conva... ║
|
|
31
|
-
╚══════════════════════╝
|
|
32
|
-
`);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
table
|
|
3
|
-
} from './../../../src';
|
|
4
|
-
import expectTable from './expectTable';
|
|
5
|
-
|
|
6
|
-
describe('README.md usage/', () => {
|
|
7
|
-
it('text_wrapping (no wrap word)', () => {
|
|
8
|
-
const data = [
|
|
9
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
const config = {
|
|
13
|
-
columns: {
|
|
14
|
-
0: {
|
|
15
|
-
width: 20
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const output = table(data, config);
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
23
|
-
expectTable(output, `
|
|
24
|
-
╔══════════════════════╗
|
|
25
|
-
║ Lorem ipsum dolor si ║
|
|
26
|
-
║ t amet, consectetur ║
|
|
27
|
-
║ adipiscing elit. Pha ║
|
|
28
|
-
║ sellus pulvinar nibh ║
|
|
29
|
-
║ sed mauris convallis ║
|
|
30
|
-
║ dapibus. Nunc venena ║
|
|
31
|
-
║ tis tempus nulla sit ║
|
|
32
|
-
║ amet viverra. ║
|
|
33
|
-
╚══════════════════════╝
|
|
34
|
-
`);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('text_wrapping (wrap word)', () => {
|
|
38
|
-
const data = [
|
|
39
|
-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
const config = {
|
|
43
|
-
columns: {
|
|
44
|
-
0: {
|
|
45
|
-
width: 20,
|
|
46
|
-
wrapWord: true
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const output = table(data, config);
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
54
|
-
expectTable(output, `
|
|
55
|
-
╔══════════════════════╗
|
|
56
|
-
║ Lorem ipsum dolor ║
|
|
57
|
-
║ sit amet, ║
|
|
58
|
-
║ consectetur ║
|
|
59
|
-
║ adipiscing elit. ║
|
|
60
|
-
║ Phasellus pulvinar ║
|
|
61
|
-
║ nibh sed mauris ║
|
|
62
|
-
║ convallis dapibus. ║
|
|
63
|
-
║ Nunc venenatis ║
|
|
64
|
-
║ tempus nulla sit ║
|
|
65
|
-
║ amet viverra. ║
|
|
66
|
-
╚══════════════════════╝
|
|
67
|
-
`);
|
|
68
|
-
});
|
|
69
|
-
});
|
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
|
-
});
|