Comparing version 1.5.3 to 1.5.4
@@ -148,2 +148,4 @@ "use strict"; | ||
}).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)))); | ||
@@ -185,5 +187,7 @@ }, 0); | ||
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))); | ||
@@ -190,0 +194,0 @@ }, 0); |
@@ -138,2 +138,4 @@ "use strict" | ||
.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)))) | ||
@@ -175,5 +177,7 @@ }, 0) | ||
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))) | ||
@@ -180,0 +184,0 @@ }, 0) |
{ | ||
"name": "columnify", | ||
"version": "1.5.3", | ||
"version": "1.5.4", | ||
"description": "Render data in text columns. Supports in-column text-wrap.", | ||
@@ -5,0 +5,0 @@ "main": "columnify.js", |
55
utils.js
@@ -111,29 +111,42 @@ "use strict" | ||
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 | ||
} | ||
word = word.slice(0, i) // grab truncated word | ||
word += truncationChar // add trailing … or whatever | ||
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 | ||
} | ||
result.push(word) | ||
} | ||
result.push(word) | ||
return splitLongWords(words.join(' '), max, truncationChar, result) | ||
return result.join(' ') | ||
} | ||
@@ -140,0 +153,0 @@ |
11
width.js
var stripAnsi = require('strip-ansi') | ||
var wcwidth = require('wcwidth') | ||
var stepSize = 10000 | ||
module.exports = function(str) { | ||
// step through data in increments as the stripAnsi | ||
// regex is sensitive to large strings. | ||
var width = 0 | ||
for (var i = 0; i < str.length; i += stepSize + 1) { | ||
width += wcwidth(stripAnsi( | ||
str.slice(i, i + stepSize) | ||
)) | ||
} | ||
return width | ||
return wcwidth(stripAnsi(str)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38392
8
689