Skip to content

Commit

Permalink
feat(ellipsis): trim after truncating
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Aug 18, 2024
1 parent fd136b8 commit 741cdfd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 741cdfd

Please sign in to comment.