diff options
author | Rebecca Turner <me@re-becca.org> | 2016-01-07 02:48:15 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2016-01-07 04:21:07 +0300 |
commit | 74d92a08d72ce3603244de4bb3e3706d2b928cef (patch) | |
tree | c3593048c4fa4ee27ef6afc5632464558bc5cbb4 /node_modules/columnify | |
parent | 6b0031e28c0b10fb2622fdadde41f5cd294348e8 (diff) |
columnify@1.5.4
Some bug fixes around large inputs
Credit: @timoxley
Diffstat (limited to 'node_modules/columnify')
-rw-r--r-- | node_modules/columnify/columnify.js | 11 | ||||
-rw-r--r-- | node_modules/columnify/index.js | 4 | ||||
-rw-r--r-- | node_modules/columnify/package.json | 118 | ||||
-rw-r--r-- | node_modules/columnify/utils.js | 55 |
4 files changed, 122 insertions, 66 deletions
diff --git a/node_modules/columnify/columnify.js b/node_modules/columnify/columnify.js index 42b2089a3..334d5509a 100644 --- a/node_modules/columnify/columnify.js +++ b/node_modules/columnify/columnify.js @@ -145,6 +145,8 @@ module.exports = function (items) { column.width = items.map(function (item) { return item[columnName]; }).reduce(function (min, cur) { + // if already at maxWidth don't bother testing + if (min >= column.maxWidth) return min; return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, wcwidth(cur)))); }, 0); }); @@ -181,9 +183,11 @@ module.exports = function (items) { var column = columns[columnName]; column.width = items.map(function (item) { return item[columnName].reduce(function (min, cur) { + if (min >= column.maxWidth) return min; return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, wcwidth(cur)))); }, 0); }).reduce(function (min, cur) { + if (min >= column.maxWidth) return min; return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, cur))); }, 0); }); @@ -217,7 +221,7 @@ function createRows(items, columns, columnNames, paddingChr) { }); // combine matching lines of each rows - var _loop = function (i) { + var _loop = function _loop(i) { row[i] = row[i] || []; columnNames.forEach(function (columnName) { var column = columns[columnName]; @@ -240,12 +244,15 @@ function createRows(items, columns, columnNames, paddingChr) { */ function mixin() { - if (Object.assign) return Object.assign.apply(Object, arguments); + var _Object; + + if (Object.assign) return (_Object = Object).assign.apply(_Object, arguments); return ObjectAssign.apply(undefined, arguments); } function ObjectAssign(target, firstSource) { "use strict"; + if (target === undefined || target === null) throw new TypeError("Cannot convert first argument to object"); var to = Object(target); diff --git a/node_modules/columnify/index.js b/node_modules/columnify/index.js index 227b41efc..221269b3e 100644 --- a/node_modules/columnify/index.js +++ b/node_modules/columnify/index.js @@ -135,6 +135,8 @@ module.exports = function(items, options = {}) { column.width = items .map(item => item[columnName]) .reduce((min, cur) => { + // if already at maxWidth don't bother testing + if (min >= column.maxWidth) return min return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, wcwidth(cur)))) }, 0) }) @@ -171,9 +173,11 @@ module.exports = function(items, options = {}) { let column = columns[columnName] column.width = items.map(item => { return item[columnName].reduce((min, cur) => { + if (min >= column.maxWidth) return min return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, wcwidth(cur)))) }, 0) }).reduce((min, cur) => { + if (min >= column.maxWidth) return min return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, cur))) }, 0) }) diff --git a/node_modules/columnify/package.json b/node_modules/columnify/package.json index c4345001f..a661b6e35 100644 --- a/node_modules/columnify/package.json +++ b/node_modules/columnify/package.json @@ -1,68 +1,100 @@ { - "name": "columnify", - "version": "1.5.2", - "description": "Render data in text columns. Supports in-column text-wrap.", - "main": "columnify.js", - "scripts": { - "pretest": "npm prune", - "test": "make prepublish && tape test/*.js | tap-spec", - "bench": "npm test && node bench", - "prepublish": "make prepublish" + "_args": [ + [ + "columnify@1.5.4", + "/Users/rebecca/code/npm" + ] + ], + "_from": "columnify@1.5.4", + "_id": "columnify@1.5.4", + "_inCache": true, + "_installable": true, + "_location": "/columnify", + "_nodeVersion": "4.2.3", + "_npmUser": { + "email": "secoif@gmail.com", + "name": "timoxley" + }, + "_npmVersion": "2.14.7", + "_phantomChildren": {}, + "_requested": { + "name": "columnify", + "raw": "columnify@1.5.4", + "rawSpec": "1.5.4", + "scope": null, + "spec": "1.5.4", + "type": "version" }, + "_requiredBy": [ + "/" + ], + "_resolved": "https://registry.npmjs.org/columnify/-/columnify-1.5.4.tgz", + "_shasum": "4737ddf1c7b69a8a7c340570782e947eec8e78bb", + "_shrinkwrap": null, + "_spec": "columnify@1.5.4", + "_where": "/Users/rebecca/code/npm", "author": { "name": "Tim Oxley" }, - "license": "MIT", - "devDependencies": { - "babel": "^5.8.21", - "chalk": "^1.1.0", - "tap-spec": "^4.0.2", - "tape": "^4.0.3" - }, - "repository": { - "type": "git", - "url": "git://github.com/timoxley/columnify.git" + "babel": { + "presets": [ + "es2015" + ] }, - "keywords": [ - "column", - "text", - "ansi", - "console", - "terminal", - "wrap", - "table" - ], "bugs": { "url": "https://github.com/timoxley/columnify/issues" }, - "homepage": "https://github.com/timoxley/columnify", "dependencies": { "strip-ansi": "^3.0.0", "wcwidth": "^1.0.0" }, + "description": "Render data in text columns. Supports in-column text-wrap.", + "devDependencies": { + "babel": "^6.3.26", + "babel-cli": "^6.3.17", + "babel-preset-es2015": "^6.3.13", + "chalk": "^1.1.1", + "tap-spec": "^4.1.1", + "tape": "^4.4.0" + }, "directories": { "test": "test" }, - "gitHead": "e7417b78091844ff2f3ba62551a4817c7ae217bd", - "_id": "columnify@1.5.2", - "_shasum": "6937930d47c22a9bfa20732a7fd619d47eaba65a", - "_from": "columnify@>=1.5.2 <1.6.0", - "_npmVersion": "2.9.0", - "_nodeVersion": "2.0.1", - "_npmUser": { - "name": "timoxley", - "email": "secoif@gmail.com" + "dist": { + "shasum": "4737ddf1c7b69a8a7c340570782e947eec8e78bb", + "tarball": "http://registry.npmjs.org/columnify/-/columnify-1.5.4.tgz" }, + "gitHead": "b5373b3d6344bf59e1ab63c912c188c34bce5889", + "homepage": "https://github.com/timoxley/columnify", + "keywords": [ + "ansi", + "column", + "console", + "table", + "terminal", + "text", + "wrap" + ], + "license": "MIT", + "main": "columnify.js", "maintainers": [ { "name": "timoxley", "email": "secoif@gmail.com" } ], - "dist": { - "shasum": "6937930d47c22a9bfa20732a7fd619d47eaba65a", - "tarball": "http://registry.npmjs.org/columnify/-/columnify-1.5.2.tgz" + "name": "columnify", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/timoxley/columnify.git" + }, + "scripts": { + "bench": "npm test && node bench", + "prepublish": "make prepublish", + "pretest": "npm prune", + "test": "make prepublish && tape test/*.js | tap-spec" }, - "_resolved": "https://registry.npmjs.org/columnify/-/columnify-1.5.2.tgz", - "readme": "ERROR: No README data found!" + "version": "1.5.4" } diff --git a/node_modules/columnify/utils.js b/node_modules/columnify/utils.js index 30682af3b..df3e6cc44 100644 --- a/node_modules/columnify/utils.js +++ b/node_modules/columnify/utils.js @@ -108,33 +108,46 @@ function splitIntoLines(str, max) { * @return String */ -function splitLongWords(str, max, truncationChar, result) { +function splitLongWords(str, max, truncationChar) { str = str.trim() - result = result || [] - if (!str) return result.join(' ') || '' + var result = [] var words = str.split(' ') - var word = words.shift() || str - if (wcwidth(word) > max) { - // slice is based on length no wcwidth - var i = 0 - var wwidth = 0 - var limit = max - wcwidth(truncationChar) - while (i < word.length) { - var w = wcwidth(word.charAt(i)) - if(w + wwidth > limit) - break - wwidth += w - ++i + var remainder = '' + + var truncationWidth = wcwidth(truncationChar) + + while (remainder || words.length) { + if (remainder) { + var word = remainder + remainder = '' + } else { + var word = words.shift() } - var remainder = word.slice(i) // get remainder - words.unshift(remainder) // save remainder for next loop + if (wcwidth(word) > max) { + // slice is based on length no wcwidth + var i = 0 + var wwidth = 0 + var limit = max - truncationWidth + while (i < word.length) { + var w = wcwidth(word.charAt(i)) + if (w + wwidth > limit) { + break + } + wwidth += w + ++i + } + + remainder = word.slice(i) // get remainder + // save remainder for next loop - word = word.slice(0, i) // grab truncated word - word += truncationChar // add trailing … or whatever + word = word.slice(0, i) // grab truncated word + word += truncationChar // add trailing … or whatever + } + result.push(word) } - result.push(word) - return splitLongWords(words.join(' '), max, truncationChar, result) + + return result.join(' ') } |