wrap-ansi
Advanced tools
Comparing version 4.0.0 to 5.0.0
21
index.js
@@ -71,4 +71,4 @@ 'use strict'; | ||
const exec = (string, columns, options = {}) => { | ||
if (string.trim() === '') { | ||
return options.trim === false ? string : string.trim(); | ||
if (options.trim !== false && string.trim() === '') { | ||
return ''; | ||
} | ||
@@ -84,7 +84,10 @@ | ||
for (const [index, word] of string.split(' ').entries()) { | ||
rows[rows.length - 1] = options.trim === false ? rows[rows.length - 1] : rows[rows.length - 1].trim(); | ||
if (options.trim !== false) { | ||
rows[rows.length - 1] = rows[rows.length - 1].trimLeft(); | ||
} | ||
let rowLength = stringWidth(rows[rows.length - 1]); | ||
if (rowLength || word === '') { | ||
if (rowLength === columns && options.wordWrap === false) { | ||
if (index !== 0) { | ||
if (rowLength === columns && (options.wordWrap === false || options.trim === false)) { | ||
// If we start with a new word but the current row length equals the length of the columns, add a new row | ||
@@ -101,6 +104,10 @@ rows.push(''); | ||
// never allowed to extend past 'columns' | ||
if (lengths[index] > columns && options.hard) { | ||
if (rowLength) { | ||
if (options.hard && lengths[index] > columns) { | ||
const remainingColumns = (columns - rowLength); | ||
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns); | ||
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns); | ||
if (breaksStartingNextLine < breaksStartingThisLine) { | ||
rows.push(''); | ||
} | ||
wrapWord(rows, word, columns); | ||
@@ -107,0 +114,0 @@ continue; |
{ | ||
"name": "wrap-ansi", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Wordwrap a string with ANSI escape codes", | ||
@@ -50,14 +50,13 @@ "license": "MIT", | ||
"ansi-styles": "^3.2.0", | ||
"string-width": "^2.1.1", | ||
"strip-ansi": "^4.0.0" | ||
"string-width": "^3.0.0", | ||
"strip-ansi": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"chalk": "^2.0.1", | ||
"coveralls": "^3.0.0", | ||
"ava": "^1.2.1", | ||
"chalk": "^2.4.2", | ||
"coveralls": "^3.0.3", | ||
"has-ansi": "^3.0.0", | ||
"nyc": "^13.0.1", | ||
"strip-ansi": "^4.0.0", | ||
"xo": "^0.22.0" | ||
"nyc": "^13.3.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
8527
6
129
+ Addedansi-regex@4.1.1(transitive)
+ Addedemoji-regex@7.0.3(transitive)
+ Addedstring-width@3.1.0(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
- Removedansi-regex@3.0.1(transitive)
- Removedstring-width@2.1.1(transitive)
- Removedstrip-ansi@4.0.0(transitive)
Updatedstring-width@^3.0.0
Updatedstrip-ansi@^5.0.0