feat(ellipsis): trim after truncating

This commit is contained in:
Samuel Berthe
2024-08-19 00:14:36 +02:00
parent fd136b8a23
commit 741cdfdb03
2 changed files with 2 additions and 1 deletions

View File

@@ -175,7 +175,7 @@ func Ellipsis(str string, length int) string {
if len(str) < 3 || length < 3 {
return "..."
}
return str[0:length-3] + "..."
return strings.TrimSpace(str[0:length-3]) + "..."
}
return str

View File

@@ -499,4 +499,5 @@ func TestEllipsis(t *testing.T) {
is.Equal("...", Ellipsis("12345", 3))
is.Equal("...", Ellipsis("12345", 2))
is.Equal("...", Ellipsis("12345", -1))
is.Equal("hello...", Ellipsis(" hello world ", 9))
}