table 3.7.9 → 3.8.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/dist/alignString.js +47 -68
- package/dist/alignTableData.js +20 -24
- package/dist/calculateCellHeight.js +18 -28
- package/dist/calculateCellWidthIndex.js +9 -11
- package/dist/calculateMaximumColumnWidthIndex.js +18 -28
- package/dist/calculateRowHeightIndex.js +22 -45
- package/dist/createStream.js +75 -95
- package/dist/drawBorder.js +33 -47
- package/dist/drawRow.js +4 -5
- package/dist/drawTable.js +27 -32
- package/dist/getBorderCharacters.js +98 -99
- package/dist/index.js +1 -2
- package/dist/makeConfig.js +43 -63
- package/dist/makeStreamConfig.js +40 -59
- package/dist/mapDataUsingRowHeightIndex.js +28 -55
- package/dist/padTableData.js +11 -19
- package/dist/schemas/config.json +3 -1
- package/dist/schemas/streamConfig.json +2 -0
- package/dist/stringifyTableData.js +9 -11
- package/dist/table.js +8 -13
- package/dist/truncateTableData.js +12 -18
- package/dist/validateConfig.js +753 -50
- package/dist/validateStreamConfig.js +739 -50
- package/dist/validateTableData.js +28 -36
- package/dist/wrapString.js +13 -16
- package/dist/wrapWord.js +24 -29
- package/package.json +35 -12
- package/test/README/usage/basic.js +25 -0
- package/test/README/usage/cell_content_alignment.js +45 -0
- package/test/README/usage/column_width.js +33 -0
- package/test/README/usage/custom_border.js +50 -0
- package/test/README/usage/draw_horizontal_line.js +41 -0
- package/test/README/usage/expectTable.js +13 -0
- package/test/README/usage/moon_mission.js +67 -0
- package/test/README/usage/padding_cell_content.js +39 -0
- package/test/README/usage/predefined_border_templates.js +91 -0
- package/test/README/usage/streaming.js +56 -0
- package/test/README/usage/text_truncating.js +32 -0
- package/test/README/usage/text_wrapping.js +67 -0
- package/test/alignString.js +102 -0
- package/test/calculateCellHeight.js +44 -0
- package/test/calculateCellWidthIndex.js +20 -0
- package/test/calculateMaximumColumnWidthIndex.js +59 -0
- package/test/calculateRowHeightIndex.js +78 -0
- package/test/config.js +43 -0
- package/test/configSamples.js +153 -0
- package/test/createStream.js +41 -0
- package/test/drawBorder.js +71 -0
- package/test/makeConfig.js +75 -0
- package/test/mapDataUsingRowHeightIndex.js +119 -0
- package/test/streamConfig.js +43 -0
- package/test/streamConfigSamples.js +151 -0
- package/test/validateTableData.js +65 -0
- package/test/wrapString.js +45 -0
- package/test/wrapWord.js +32 -0
- 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
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _lodash = require('lodash');
|
|
8
8
|
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var _isArray2 = require('lodash/isArray');
|
|
12
|
-
|
|
13
|
-
var _isArray3 = _interopRequireDefault(_isArray2);
|
|
9
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
14
10
|
|
|
15
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
12
|
|
|
@@ -26,42 +22,38 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
26
22
|
* @param {column[]} rows
|
|
27
23
|
* @returns {undefined}
|
|
28
24
|
*/
|
|
25
|
+
exports.default = rows => {
|
|
26
|
+
if (!_lodash2.default.isArray(rows)) {
|
|
27
|
+
throw new Error('Table data must be an array.');
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if (rows.length === 0) {
|
|
31
|
+
throw new Error('Table must define at least one row.');
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (rows[0].length === 0) {
|
|
35
|
+
throw new Error('Table must define at least one column.');
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
throw new Error('Table must define at least one row.');
|
|
39
|
-
}
|
|
38
|
+
const columnNumber = rows[0].length;
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
_lodash2.default.forEach(rows, cells => {
|
|
41
|
+
if (!_lodash2.default.isArray(cells)) {
|
|
42
|
+
throw new Error('Table row data must be an array.');
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!(0, _isArray3.default)(cells)) {
|
|
49
|
-
throw new Error('Table row data must be an array.');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (cells.length !== columnNumber) {
|
|
53
|
-
throw new Error('Table must have a consistent number of cells.');
|
|
54
|
-
}
|
|
45
|
+
if (cells.length !== columnNumber) {
|
|
46
|
+
throw new Error('Table must have a consistent number of cells.');
|
|
47
|
+
}
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
49
|
+
// @todo Make an exception for newline characters.
|
|
50
|
+
// @see https://github.com/gajus/table/issues/9
|
|
51
|
+
_lodash2.default.forEach(cells, cell => {
|
|
52
|
+
if (/[\x01-\x1A]/.test(cell)) {
|
|
53
|
+
throw new Error('Table data must not contain control characters.');
|
|
54
|
+
}
|
|
63
55
|
});
|
|
56
|
+
});
|
|
64
57
|
};
|
|
65
58
|
|
|
66
|
-
module.exports = exports['default'];
|
|
67
|
-
//# sourceMappingURL=validateTableData.js.map
|
|
59
|
+
module.exports = exports['default'];
|
package/dist/wrapString.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _lodash = require('lodash');
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
10
10
|
|
|
11
11
|
var _sliceAnsi = require('slice-ansi');
|
|
12
12
|
|
|
@@ -29,23 +29,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
29
29
|
* @param {number} size
|
|
30
30
|
* @returns {Array}
|
|
31
31
|
*/
|
|
32
|
+
exports.default = (subject, size) => {
|
|
33
|
+
let subjectSlice;
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
var chunks = void 0,
|
|
35
|
-
subjectSlice = void 0;
|
|
35
|
+
subjectSlice = subject;
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const chunks = [];
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
do {
|
|
40
|
+
chunks.push((0, _sliceAnsi2.default)(subjectSlice, 0, size));
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
subjectSlice = _lodash2.default.trim((0, _sliceAnsi2.default)(subjectSlice, size));
|
|
43
|
+
} while ((0, _stringWidth2.default)(subjectSlice));
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
} while ((0, _stringWidth2.default)(subjectSlice));
|
|
46
|
-
|
|
47
|
-
return chunks;
|
|
45
|
+
return chunks;
|
|
48
46
|
};
|
|
49
47
|
|
|
50
|
-
module.exports = exports['default'];
|
|
51
|
-
//# sourceMappingURL=wrapString.js.map
|
|
48
|
+
module.exports = exports['default'];
|
package/dist/wrapWord.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _lodash = require('lodash');
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
10
10
|
|
|
11
11
|
var _sliceAnsi = require('slice-ansi');
|
|
12
12
|
|
|
@@ -23,41 +23,36 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
23
|
* @param {number} size
|
|
24
24
|
* @returns {Array}
|
|
25
25
|
*/
|
|
26
|
+
exports.default = (input, size) => {
|
|
27
|
+
let subject;
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
var chunk = void 0,
|
|
29
|
-
chunks = void 0,
|
|
30
|
-
re = void 0,
|
|
31
|
-
subject = void 0;
|
|
29
|
+
subject = input;
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
const chunks = [];
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
// https://regex101.com/r/gY5kZ1/1
|
|
34
|
+
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
do {
|
|
37
|
+
let chunk;
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
chunk = subject.match(re);
|
|
39
|
+
chunk = subject.match(re);
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
if (chunk) {
|
|
42
|
+
chunk = chunk[0];
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
chunk = chunk[0];
|
|
44
|
+
subject = (0, _sliceAnsi2.default)(subject, (0, _stringWidth2.default)(chunk));
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
chunk = _lodash2.default.trim(chunk);
|
|
47
|
+
} else {
|
|
48
|
+
chunk = (0, _sliceAnsi2.default)(subject, 0, size);
|
|
49
|
+
subject = (0, _sliceAnsi2.default)(subject, size);
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
chunk = (0, _sliceAnsi2.default)(subject, 0, size);
|
|
53
|
-
subject = (0, _sliceAnsi2.default)(subject, size);
|
|
54
|
-
}
|
|
52
|
+
chunks.push(chunk);
|
|
53
|
+
} while ((0, _stringWidth2.default)(subject));
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
} while ((0, _stringWidth2.default)(subject));
|
|
58
|
-
|
|
59
|
-
return chunks;
|
|
55
|
+
return chunks;
|
|
60
56
|
};
|
|
61
57
|
|
|
62
|
-
module.exports = exports['default'];
|
|
63
|
-
//# sourceMappingURL=wrapWord.js.map
|
|
58
|
+
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -5,18 +5,30 @@
|
|
|
5
5
|
"url": "http://gajus.com"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"ajv": "^4.7.0",
|
|
9
|
+
"ajv-keywords": "^1.0.0",
|
|
8
10
|
"chalk": "^1.1.1",
|
|
9
11
|
"lodash": "^4.0.0",
|
|
10
12
|
"slice-ansi": "0.0.4",
|
|
11
|
-
"string-width": "^
|
|
12
|
-
"tv4": "^1.2.7"
|
|
13
|
+
"string-width": "^2.0.0"
|
|
13
14
|
},
|
|
14
15
|
"description": "Formats data into a string table.",
|
|
15
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",
|
|
16
25
|
"chai": "^3.4.1",
|
|
26
|
+
"eslint": "^3.5.0",
|
|
27
|
+
"eslint-config-canonical": "^1.8.6",
|
|
17
28
|
"gitdown": "^2.4.0",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
29
|
+
"husky": "^0.11.7",
|
|
30
|
+
"mocha": "^3.0.2",
|
|
31
|
+
"nyc": "^8.3.1",
|
|
20
32
|
"sinon": "^1.17.2"
|
|
21
33
|
},
|
|
22
34
|
"keywords": [
|
|
@@ -29,18 +41,29 @@
|
|
|
29
41
|
"license": "BSD-3-Clause",
|
|
30
42
|
"main": "./dist/index.js",
|
|
31
43
|
"name": "table",
|
|
44
|
+
"nyc": {
|
|
45
|
+
"include": [
|
|
46
|
+
"src/*.js"
|
|
47
|
+
],
|
|
48
|
+
"instrument": false,
|
|
49
|
+
"lines": 70,
|
|
50
|
+
"require": [
|
|
51
|
+
"babel-register"
|
|
52
|
+
],
|
|
53
|
+
"sourceMap": false
|
|
54
|
+
},
|
|
32
55
|
"repository": {
|
|
33
56
|
"type": "git",
|
|
34
57
|
"url": "https://github.com/gajus/table"
|
|
35
58
|
},
|
|
36
59
|
"scripts": {
|
|
37
|
-
"build": "
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"test": "npm run
|
|
60
|
+
"build": "rm -fr ./dist && babel --copy-files ./src --out-dir ./dist && npm run make-validators",
|
|
61
|
+
"lint": "npm run build && eslint ./src ./tests",
|
|
62
|
+
"make-readme": "gitdown ./.README/README.md --output-file ./README.md",
|
|
63
|
+
"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
|
+
"precommit": "npm run lint && npm run test",
|
|
65
|
+
"prepublish": "NODE_ENV=production npm run build",
|
|
66
|
+
"test": "npm run build && nyc --check-coverage mocha"
|
|
44
67
|
},
|
|
45
|
-
"version": "3.
|
|
68
|
+
"version": "3.8.3"
|
|
46
69
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
});
|