Skip to content

Commit 514ee8d

Browse files
committed
fix: trailing dots
1 parent 602a056 commit 514ee8d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ function iPipeTo(
3333
function trim(str) {
3434
const maxWidth = cliWidth({ defaultWidth: 80, output: stdout }) - 9;
3535

36-
let attempts = 0
37-
while (stringWidth(str) > maxWidth) {
38-
// trim until shorter than maxWidth
39-
str = str.substr(0, maxWidth - ++attempts)
36+
if (str.length > maxWidth) {
37+
let attempts = 0
38+
while (stringWidth(str) > maxWidth) {
39+
// trim until shorter than maxWidth
40+
str = str.substr(0, maxWidth - ++attempts)
41+
}
42+
str += "..."
4043
}
41-
str += "..."
44+
4245
return str
4346
}
4447

0 commit comments

Comments
 (0)