Skip to content

Commit

Permalink
Merge pull request #155 from cli-table/dependabot/npm_and_yarn/pretti…
Browse files Browse the repository at this point in the history
…er-2.0.2

Bump prettier from 1.18.2 to 2.0.2
  • Loading branch information
Turbo87 authored Mar 30, 2020
2 parents 099297f + 62772ed commit 5d9ac38
Show file tree
Hide file tree
Showing 17 changed files with 473 additions and 357 deletions.
16 changes: 8 additions & 8 deletions examples/basic-usage-examples.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Table = require('../src/table');
const colors = require('colors/safe');

module.exports = function(runTest) {
module.exports = function (runTest) {
function it(name, fn) {
let result = fn();
runTest(name, result[0], result[1], result[2]);
}

it('Basic Usage', function() {
it('Basic Usage', function () {
function makeTable() {
// By default, headers will be red, and borders will be grey
let table = new Table({ head: ['a', 'b'] });
Expand All @@ -28,7 +28,7 @@ module.exports = function(runTest) {
return [makeTable, expected, 'basic-usage-with-colors'];
});

it('Basic Usage - disable colors - (used often in the examples and tests)', function() {
it('Basic Usage - disable colors - (used often in the examples and tests)', function () {
function makeTable() {
// For most of these examples, and most of the unit tests we disable colors.
// It makes unit tests easier to write/understand, and allows these pages to
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('Create vertical tables by adding objects a that specify key-value pairs', function() {
it('Create vertical tables by adding objects a that specify key-value pairs', function () {
function makeTable() {
let table = new Table({
style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] },
Expand All @@ -85,7 +85,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('Cross tables are similar to vertical tables, but include an empty string for the first header', function() {
it('Cross tables are similar to vertical tables, but include an empty string for the first header', function () {
function makeTable() {
let table = new Table({
head: ['', 'Header 1', 'Header 2'],
Expand Down Expand Up @@ -113,7 +113,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('Stylize the table with custom border characters', function() {
it('Stylize the table with custom border characters', function () {
function makeTable() {
let table = new Table({
chars: {
Expand Down Expand Up @@ -152,7 +152,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines', function() {
it('Use ansi colors (i.e. colors.js) to style text within the cells at will, even across multiple lines', function () {
function makeTable() {
let table = new Table({ style: { border: [], header: [] } });

Expand All @@ -173,7 +173,7 @@ module.exports = function(runTest) {
return [makeTable, expected, 'multi-line-colors'];
});

it('Set `wordWrap` to true to make lines of text wrap instead of being truncated', function() {
it('Set `wordWrap` to true to make lines of text wrap instead of being truncated', function () {
function makeTable() {
let table = new Table({
style: { border: [], header: [] },
Expand Down
36 changes: 20 additions & 16 deletions examples/col-and-row-span-examples.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Table = require('../src/table');
const colors = require('colors/safe');

module.exports = function(runTest) {
module.exports = function (runTest) {
function it(name, fn) {
let result = fn();
runTest(name, result[0], result[1], result[2]);
}

it('use colSpan to span columns - (colSpan above normal cell)', function() {
it('use colSpan to span columns - (colSpan above normal cell)', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -29,7 +29,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('use colSpan to span columns - (colSpan below normal cell)', function() {
it('use colSpan to span columns - (colSpan below normal cell)', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -51,7 +51,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('use rowSpan to span rows - (rowSpan on the left side)', function() {
it('use rowSpan to span rows - (rowSpan on the left side)', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -74,7 +74,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('use rowSpan to span rows - (rowSpan on the right side)', function() {
it('use rowSpan to span rows - (rowSpan on the right side)', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -97,12 +97,16 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('mix rowSpan and colSpan together for complex table layouts', function() {
it('mix rowSpan and colSpan together for complex table layouts', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

table.push(
[{ content: 'hello', colSpan: 2 }, { rowSpan: 2, colSpan: 2, content: 'sup' }, { rowSpan: 3, content: 'hi' }],
[
{ content: 'hello', colSpan: 2 },
{ rowSpan: 2, colSpan: 2, content: 'sup' },
{ rowSpan: 3, content: 'hi' },
],
[{ content: 'howdy', colSpan: 2 }],
['o', 'k', '', '']
);
Expand All @@ -123,7 +127,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('multi-line content will flow across rows in rowSpan cells', function() {
it('multi-line content will flow across rows in rowSpan cells', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -146,7 +150,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('multi-line content will flow across rows in rowSpan cells - (complex layout)', function() {
it('multi-line content will flow across rows in rowSpan cells - (complex layout)', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand Down Expand Up @@ -176,7 +180,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('rowSpan cells can have a staggered layout', function() {
it('rowSpan cells can have a staggered layout', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -190,7 +194,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('the layout manager automatically create empty cells to fill in the table', function() {
it('the layout manager automatically create empty cells to fill in the table', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -214,7 +218,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('use table `rowHeights` option to fix row height. The truncation symbol will be shown on the last line.', function() {
it('use table `rowHeights` option to fix row height. The truncation symbol will be shown on the last line.', function () {
function makeTable() {
let table = new Table({
rowHeights: [2],
Expand All @@ -231,7 +235,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('if `colWidths` is not specified, the layout manager will automatically widen rows to fit the content', function() {
it('if `colWidths` is not specified, the layout manager will automatically widen rows to fit the content', function () {
function makeTable() {
let table = new Table({ style: { head: [], border: [] } });

Expand All @@ -245,7 +249,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('you can specify a column width for only the first row, other rows will be automatically widened to fit content', function() {
it('you can specify a column width for only the first row, other rows will be automatically widened to fit content', function () {
function makeTable() {
let table = new Table({
colWidths: [4],
Expand All @@ -262,7 +266,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('a column with a null column width will be automatically widened to fit content', function() {
it('a column with a null column width will be automatically widened to fit content', function () {
function makeTable() {
let table = new Table({
colWidths: [null, 4],
Expand All @@ -279,7 +283,7 @@ module.exports = function(runTest) {
return [makeTable, expected];
});

it('feel free to use colors in your content strings, column widths will be calculated correctly', function() {
it('feel free to use colors in your content strings, column widths will be calculated correctly', function () {
function makeTable() {
let table = new Table({
colWidths: [5],
Expand Down
10 changes: 3 additions & 7 deletions lib/print-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ function mdExample(fn, file, cb) {
*/
function runTest(name, fn) {
function testExample(name, fn, expected) {
it(name, function() {
it(name, function () {
expect(fn().toString()).toEqual(expected.join('\n'));
});
}

describe(name, function() {
describe(name, function () {
fn(testExample, identity);
});
}
Expand All @@ -89,11 +89,7 @@ function runPrintingExample(fn, logName, logTable, logCode, logSeparator, logScr
* @param screenshot - If present, there is an image containing a screenshot of the output
*/
function printExample(name, makeTable, expected, screenshot) {
let code = makeTable
.toString()
.split('\n')
.slice(1, -2)
.join('\n');
let code = makeTable.toString().split('\n').slice(1, -2).join('\n');

logName(name);
if (screenshot && logScreenShot) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"jest": "^24.0.0",
"jest-runner-eslint": "^0.7.0",
"lerna-changelog": "^1.0.1",
"prettier": "1.18.2"
"prettier": "2.0.2"
},
"optionalDependencies": {
"colors": "^1.1.2"
Expand Down
4 changes: 2 additions & 2 deletions src/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Cell {
let optionsChars = this.options.chars || {};
let tableChars = tableOptions.chars;
let chars = (this.chars = {});
CHAR_NAMES.forEach(function(name) {
CHAR_NAMES.forEach(function (name) {
setOption(optionsChars, tableChars, name, chars);
});

Expand Down Expand Up @@ -138,7 +138,7 @@ class Cell {
let content = [];
if (this.cells) {
//TODO: cells should always exist - some tests don't fill it in though
this.widths.forEach(function(width, index) {
this.widths.forEach(function (width, index) {
content.push(this._topLeftChar(index));
content.push(utils.repeat(this.chars[this.y == 0 ? 'top' : 'mid'], width));
}, this);
Expand Down
26 changes: 13 additions & 13 deletions src/layout-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const objectAssign = require('object-assign');
const Cell = require('./cell');
const { ColSpanCell, RowSpanCell } = Cell;

(function() {
(function () {
function layoutTable(table) {
table.forEach(function(row, rowIndex) {
row.forEach(function(cell, columnIndex) {
table.forEach(function (row, rowIndex) {
row.forEach(function (cell, columnIndex) {
cell.y = rowIndex;
cell.x = columnIndex;
for (let y = rowIndex; y >= 0; y--) {
Expand All @@ -24,8 +24,8 @@ const { ColSpanCell, RowSpanCell } = Cell;

function maxWidth(table) {
let mw = 0;
table.forEach(function(row) {
row.forEach(function(cell) {
table.forEach(function (row) {
row.forEach(function (cell) {
mw = Math.max(mw, cell.x + (cell.colSpan || 1));
});
});
Expand Down Expand Up @@ -76,8 +76,8 @@ const { ColSpanCell, RowSpanCell } = Cell;
}

function addRowSpanCells(table) {
table.forEach(function(row, rowIndex) {
row.forEach(function(cell) {
table.forEach(function (row, rowIndex) {
row.forEach(function (cell) {
for (let i = 1; i < cell.rowSpan; i++) {
let rowSpanCell = new RowSpanCell(cell);
rowSpanCell.x = cell.x;
Expand Down Expand Up @@ -140,7 +140,7 @@ const { ColSpanCell, RowSpanCell } = Cell;
}

function generateCells(rows) {
return rows.map(function(row) {
return rows.map(function (row) {
if (!Array.isArray(row)) {
let key = Object.keys(row)[0];
row = row[key];
Expand All @@ -151,7 +151,7 @@ const { ColSpanCell, RowSpanCell } = Cell;
row = [key, row];
}
}
return row.map(function(cell) {
return row.map(function (cell) {
return new Cell(cell);
});
});
Expand All @@ -178,11 +178,11 @@ const { ColSpanCell, RowSpanCell } = Cell;
})();

function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
return function(vals, table) {
return function (vals, table) {
let result = [];
let spanners = [];
table.forEach(function(row) {
row.forEach(function(cell) {
table.forEach(function (row) {
row.forEach(function (cell) {
if ((cell[colSpan] || 1) > 1) {
spanners.push(cell);
} else {
Expand All @@ -191,7 +191,7 @@ function makeComputeWidths(colSpan, desiredWidth, x, forcedMin) {
});
});

vals.forEach(function(val, index) {
vals.forEach(function (val, index) {
if (typeof val === 'number') {
result[index] = val;
}
Expand Down
10 changes: 5 additions & 5 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ class Table extends Array {

let cells = tableLayout.makeTableLayout(array);

cells.forEach(function(row) {
row.forEach(function(cell) {
cells.forEach(function (row) {
row.forEach(function (cell) {
cell.mergeTableOptions(this.options, cells);
}, this);
}, this);

tableLayout.computeWidths(this.options.colWidths, cells);
tableLayout.computeHeights(this.options.rowHeights, cells);

cells.forEach(function(row) {
row.forEach(function(cell) {
cells.forEach(function (row) {
row.forEach(function (cell) {
cell.init(this.options);
}, this);
}, this);
Expand Down Expand Up @@ -67,7 +67,7 @@ class Table extends Array {

function doDraw(row, lineNum, result) {
let line = [];
row.forEach(function(cell) {
row.forEach(function (cell) {
line.push(cell.draw(lineNum));
});
let str = line.join('');
Expand Down
Loading

0 comments on commit 5d9ac38

Please sign in to comment.