Skip to content

Commit 741cdfd

Browse files
committed
feat(ellipsis): trim after truncating
1 parent fd136b8 commit 741cdfd

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func Ellipsis(str string, length int) string {
175175
if len(str) < 3 || length < 3 {
176176
return "..."
177177
}
178-
return str[0:length-3] + "..."
178+
return strings.TrimSpace(str[0:length-3]) + "..."
179179
}
180180

181181
return str

string_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,5 @@ func TestEllipsis(t *testing.T) {
499499
is.Equal("...", Ellipsis("12345", 3))
500500
is.Equal("...", Ellipsis("12345", 2))
501501
is.Equal("...", Ellipsis("12345", -1))
502+
is.Equal("hello...", Ellipsis(" hello world ", 9))
502503
}

0 commit comments

Comments
 (0)