Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/table
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e55ef35ac3afbe42f789f666bc98cf05a97ae941
Choose a base ref
...
head repository: gajus/table
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bd4d09e0de99bda1f88fa648fca42d0547eb808e
Choose a head ref
  • 20 commits
  • 41 files changed
  • 6 contributors

Commits on Nov 23, 2016

  1. Copy the full SHA
    b787484 View commit details

Commits on Apr 17, 2017

  1. feat: update ajv to 5.0.0 (#34)

    Evgeny Poberezkin authored and gajus committed Apr 17, 2017
    Copy the full SHA
    4247a96 View commit details

Commits on Jun 2, 2017

  1. refactor: converting lodash map to es6 (#43)

    converting lodash map to es6
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    d309f79 View commit details
  2. refactor: converting lodash map to es6 (#42)

    converting lodash map to es6
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    97c010e View commit details
  3. refactor: converting lodash assign to es6 (#41)

    converting lodash assign to es6
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    f2e72ba View commit details
  4. refactor: converting lodash to es6 (#40)

    converting lodash to es6
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    597b4a2 View commit details
  5. refactor: es6 have Object.assign (#38)

    converting lodash assign to es6 Object.assign
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    0fe35c4 View commit details
  6. refactor: removing lodash dependency (#36)

    its better to remove the lodash, its an heavy module, better to use lodash modules individually or es6
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    b3dcadb View commit details
  7. refactor: removing lodash dependency (#37)

    its better to use es6 instead of lodash
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    b297d7e View commit details
  8. refactor: converting lodash to es6 (#39)

    converting lodash to es6
    Esref Durna authored and gajus committed Jun 2, 2017
    Copy the full SHA
    a419632 View commit details
  9. fix: remove lodash

    gajus committed Jun 2, 2017
    Copy the full SHA
    41cacb6 View commit details

Commits on Sep 26, 2017

  1. Copy the full SHA
    8d367c8 View commit details
  2. style:

    gajus committed Sep 26, 2017
    Copy the full SHA
    94cb88b View commit details
  3. 4.0.2

    gajus committed Sep 26, 2017
    Copy the full SHA
    badda76 View commit details

Commits on Dec 22, 2017

  1. Copy the full SHA
    5f6e334 View commit details

Commits on Jan 23, 2018

  1. chore: update mocha to version & indicate supported node versions in …

    …package.json (#58)
    
    * Update mocha to version 5.0
    
    * Indicate which Node.js version are supported in package.json
    realityking authored and gajus committed Jan 23, 2018
    Copy the full SHA
    5ae209b View commit details
  2. refactor: replace lodash with native ES5/ES6 methods where possible (#59

    )
    
    * Use String.prototype.repeat instead of lodash's _.repeat
    
    * Use Array.prototype.fill instead of lodash's _.fill
    
    * Use String.prototype.trim instead of lodash's _.trim
    
    * Use native Math functions instead of lodash
    
    * Use Number.isInteger instead of lodas's _.isInteger
    
    * Use Object.assign instead of lodas's _.assign
    
    * Use native iteration methods instead of lodash's
    realityking authored and gajus committed Jan 23, 2018
    Copy the full SHA
    0dad920 View commit details

Commits on Feb 14, 2018

  1. docs: update README.md (#61)

    MrCheater authored and gajus committed Feb 14, 2018
    Copy the full SHA
    fb821f9 View commit details

Commits on Feb 15, 2018

  1. feat: update ajv to version 6. (#60)

    realityking authored and gajus committed Feb 15, 2018
    Copy the full SHA
    eec96ab View commit details

Commits on Feb 24, 2018

  1. 4.0.3

    gajus committed Feb 24, 2018
    Copy the full SHA
    bd4d09e View commit details
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
src
tests
test
coverage
.*
*.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -454,7 +454,7 @@ output = table(data, {
paddingLeft: 0,
paddingRight: 1
},
drawJoin: () => {
drawHorizontalLine: () => {
return false
}
});
47 changes: 25 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -5,30 +5,33 @@
"url": "http://gajus.com"
},
"dependencies": {
"ajv": "^4.7.0",
"ajv-keywords": "^1.0.0",
"chalk": "^1.1.1",
"lodash": "^4.0.0",
"slice-ansi": "0.0.4",
"string-width": "^2.0.0"
"ajv": "^6.0.1",
"ajv-keywords": "^3.0.0",
"chalk": "^2.1.0",
"lodash": "^4.17.4",
"slice-ansi": "1.0.0",
"string-width": "^2.1.1"
},
"description": "Formats data into a string table.",
"devDependencies": {
"ajv-cli": "^1.1.0",
"babel": "^6.5.2",
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-plugin-istanbul": "^2.0.3",
"babel-preset-es2015-node4": "^2.1.0",
"babel-register": "^6.14.0",
"chai": "^3.4.1",
"eslint": "^3.5.0",
"eslint-config-canonical": "^1.8.6",
"gitdown": "^2.4.0",
"husky": "^0.11.7",
"mocha": "^3.0.2",
"nyc": "^8.3.1",
"sinon": "^1.17.2"
"ajv-cli": "^3.0.0",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-istanbul": "^4.1.5",
"babel-preset-es2015-node4": "^2.1.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"eslint": "^4.7.2",
"eslint-config-canonical": "^9.3.1",
"gitdown": "^2.5.1",
"husky": "^0.14.3",
"mocha": "^5.0.0",
"nyc": "^11.2.1",
"sinon": "^4.0.0"
},
"engines": {
"node": ">=4.0.0"
},
"keywords": [
"ascii",
@@ -64,5 +67,5 @@
"prepublish": "NODE_ENV=production npm run build",
"test": "npm run build && nyc --check-coverage mocha"
},
"version": "4.0.1"
"version": "4.0.3"
}
20 changes: 10 additions & 10 deletions src/alignString.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const alignments = [
* @returns {string}
*/
const alignLeft = (subject, width) => {
return subject + _.repeat(' ', width);
return subject + ' '.repeat(width);
};

/**
@@ -22,7 +22,7 @@ const alignLeft = (subject, width) => {
* @returns {string}
*/
const alignRight = (subject, width) => {
return _.repeat(' ', width) + subject;
return ' '.repeat(width) + subject;
};

/**
@@ -36,11 +36,11 @@ const alignCenter = (subject, width) => {
halfWidth = width / 2;

if (halfWidth % 2 === 0) {
return _.repeat(' ', halfWidth) + subject + _.repeat(' ', halfWidth);
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth);
} else {
halfWidth = _.floor(halfWidth);
halfWidth = Math.floor(halfWidth);

return _.repeat(' ', halfWidth) + subject + _.repeat(' ', halfWidth + 1);
return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1);
}
};

@@ -55,31 +55,31 @@ const alignCenter = (subject, width) => {
*/
export default (subject, containerWidth, alignment) => {
if (!_.isString(subject)) {
throw new Error('Subject parameter value must be a string.');
throw new TypeError('Subject parameter value must be a string.');
}

if (!_.isNumber(containerWidth)) {
throw new Error('Container width parameter value must be a number.');
throw new TypeError('Container width parameter value must be a number.');
}

const subjectWidth = stringWidth(subject);

if (subjectWidth > containerWidth) {
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);

throw new Error('Subject parameter value width cannot be greater than the container width.');
}

if (!_.isString(alignment)) {
throw new Error('Alignment parameter value must be a string.');
throw new TypeError('Alignment parameter value must be a string.');
}

if (alignments.indexOf(alignment) === -1) {
throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
}

if (subjectWidth === 0) {
return _.repeat(' ', containerWidth);
return ' '.repeat(containerWidth);
}

const availableWidth = containerWidth - subjectWidth;
5 changes: 2 additions & 3 deletions src/alignTableData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import stringWidth from 'string-width';
import alignString from './alignString';

@@ -8,8 +7,8 @@ import alignString from './alignString';
* @returns {table~row[]}
*/
export default (rows, config) => {
return _.map(rows, (cells) => {
return _.map(cells, (value, index1) => {
return rows.map((cells) => {
return cells.map((value, index1) => {
const column = config.columns[index1];

if (stringWidth(value) === column.width) {
8 changes: 4 additions & 4 deletions src/calculateCellHeight.js
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ import wrapWord from './wrapWord';
*/
export default (value, columnWidth, useWrapWord = false) => {
if (!_.isString(value)) {
throw new Error('Value must be a string.');
throw new TypeError('Value must be a string.');
}

if (!_.isInteger(columnWidth)) {
throw new Error('Column width must be an integer.');
if (!Number.isInteger(columnWidth)) {
throw new TypeError('Column width must be an integer.');
}

if (columnWidth < 1) {
@@ -25,5 +25,5 @@ export default (value, columnWidth, useWrapWord = false) => {
return wrapWord(value, columnWidth).length;
}

return _.ceil(stringWidth(value) / columnWidth);
return Math.ceil(stringWidth(value) / columnWidth);
};
3 changes: 1 addition & 2 deletions src/calculateCellWidthIndex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import stringWidth from 'string-width';

/**
@@ -8,7 +7,7 @@ import stringWidth from 'string-width';
* @returns {number[]}
*/
export default (cells) => {
return _.map(cells, (value) => {
return cells.map((value) => {
return stringWidth(value);
});
};
7 changes: 3 additions & 4 deletions src/calculateMaximumColumnWidthIndex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import calculateCellWidthIndex from './calculateCellWidthIndex';

/**
@@ -12,12 +11,12 @@ export default (rows) => {
throw new Error('Dataset must have at least one row.');
}

const columns = _.fill(Array(rows[0].length), 0);
const columns = Array(rows[0].length).fill(0);

_.forEach(rows, (row) => {
rows.forEach((row) => {
const columnWidthIndex = calculateCellWidthIndex(row);

_.forEach(columnWidthIndex, (valueWidth, index0) => {
columnWidthIndex.forEach((valueWidth, index0) => {
if (columns[index0] < valueWidth) {
columns[index0] = valueWidth;
}
10 changes: 5 additions & 5 deletions src/calculateRowHeightIndex.js
Original file line number Diff line number Diff line change
@@ -13,16 +13,16 @@ export default (rows, config) => {

const rowSpanIndex = [];

_.forEach(rows, (cells) => {
const cellHeightIndex = _.fill(Array(tableWidth), 1);
rows.forEach((cells) => {
const cellHeightIndex = Array(tableWidth).fill(1);

_.forEach(cells, (value, index1) => {
cells.forEach((value, index1) => {
if (!_.isNumber(config.columns[index1].width)) {
throw new Error('column[index].width must be a number.');
throw new TypeError('column[index].width must be a number.');
}

if (!_.isBoolean(config.columns[index1].wrapWord)) {
throw new Error('column[index].wrapWord must be a boolean.');
throw new TypeError('column[index].wrapWord must be a boolean.');
}

cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
6 changes: 3 additions & 3 deletions src/createStream.js
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ const prepareData = (data, config) => {
const create = (row, columnWidthIndex, config) => {
const rows = prepareData([row], config);

const body = _.map(rows, (literalRow) => {
const body = rows.map((literalRow) => {
return drawRow(literalRow, config.border);
}).join('');

@@ -69,13 +69,13 @@ const create = (row, columnWidthIndex, config) => {
const append = (row, columnWidthIndex, config) => {
const rows = prepareData([row], config);

const body = _.map(rows, (literalRow) => {
const body = rows.map((literalRow) => {
return drawRow(literalRow, config.border);
}).join('');

let output;

output = '\r\x1b[K';
output = '\r\u001B[K';

output += drawBorderJoin(columnWidthIndex, config.border);
output += body;
8 changes: 3 additions & 5 deletions src/drawBorder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from 'lodash';

/**
* @typedef drawBorder~parts
* @property {string} left
@@ -14,9 +12,9 @@ import _ from 'lodash';
* @returns {string}
*/
const drawBorder = (columnSizeIndex, parts) => {
const columns = _
.map(columnSizeIndex, (size) => {
return _.repeat(parts.body, size);
const columns = columnSizeIndex
.map((size) => {
return parts.body.repeat(size);
})
.join(parts.join);

15 changes: 7 additions & 8 deletions src/drawTable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash';
import {
drawBorderTop,
drawBorderJoin,
drawBorderBottom
drawBorderTop,
drawBorderJoin,
drawBorderBottom
} from './drawBorder';
import drawRow from './drawRow';

@@ -15,9 +14,9 @@ import drawRow from './drawRow';
* @returns {string}
*/
export default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine) => {
let output,
realRowIndex,
rowHeight;
let output;
let realRowIndex;
let rowHeight;

const rowCount = rows.length;

@@ -29,7 +28,7 @@ export default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine)
output += drawBorderTop(columnSizeIndex, border);
}

_.forEach(rows, (row, index0) => {
rows.forEach((row, index0) => {
output += drawRow(row, border);

if (!rowHeight) {
6 changes: 3 additions & 3 deletions src/makeConfig.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex
* @returns {Object}
*/
const makeBorder = (border = {}) => {
return _.assign({}, getBorderCharacters('honeywell'), border);
return Object.assign({}, getBorderCharacters('honeywell'), border);
};

/**
@@ -30,7 +30,7 @@ const makeColumns = (rows, columns = {}, columnDefault = {}) => {
columns[index] = {};
}

columns[index] = _.assign({
columns[index] = Object.assign({
alignment: 'left',
paddingLeft: 1,
paddingRight: 1,
@@ -60,7 +60,7 @@ export default (rows, userConfig = {}) => {
config.columns = makeColumns(rows, config.columns, config.columnDefault);

if (!config.drawHorizontalLine) {
/**
/**
* @returns {boolean}
*/
config.drawHorizontalLine = () => {
4 changes: 2 additions & 2 deletions src/makeStreamConfig.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import validateConfig from './validateConfig';
* @returns {Object}
*/
const makeBorder = (border = {}) => {
return _.assign({}, getBorderCharacters('honeywell'), border);
return Object.assign({}, getBorderCharacters('honeywell'), border);
};

/**
@@ -27,7 +27,7 @@ const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
columns[index] = {};
}

columns[index] = _.assign({
columns[index] = Object.assign({
alignment: 'left',
paddingLeft: 1,
paddingRight: 1,
8 changes: 4 additions & 4 deletions src/mapDataUsingRowHeightIndex.js
Original file line number Diff line number Diff line change
@@ -11,16 +11,16 @@ import wrapWord from './wrapWord';
export default (unmappedRows, rowHeightIndex, config) => {
const tableWidth = unmappedRows[0].length;

const mappedRows = _.map(unmappedRows, (cells, index0) => {
const mappedRows = unmappedRows.map((cells, index0) => {
const rowHeight = _.times(rowHeightIndex[index0], () => {
return _.fill(Array(tableWidth), '');
return Array(tableWidth).fill('');
});

// rowHeight
// [{row index within rowSaw; index2}]
// [{cell index within a virtual row; index1}]

_.forEach(cells, (value, index1) => {
cells.forEach((value, index1) => {
let chunkedValue;

if (config.columns[index1].wrapWord) {
@@ -29,7 +29,7 @@ export default (unmappedRows, rowHeightIndex, config) => {
chunkedValue = wrapString(value, config.columns[index1].width);
}

_.forEach(chunkedValue, (part, index2) => {
chunkedValue.forEach((part, index2) => {
rowHeight[index2][index1] = part;
});
});
Loading