Remove automatic suffix to Truncate function #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
Truncate
function automatically applies a...
suffix when the supplied string exceeds the specified length. While this is documented appropriately, I think this is poor default behaviour.It means that you can't truncate a long string and guarantee that the resulting string is the correct length. For instance,
#{abcdef | Truncate 3}
results in a 6 character long stringabc...
.The only way to fix this is to then perform a replace... so
#{abcdef | Truncate 3 | Replace "..." ""}
which seems counter intuitive.This PR changes the truncate function to remove the default
...
suffix, but adds a second parameter to allow for a custom suffix to be specified if required.e.g.
#{abcdef 3 "123"} results in
abc123`.This is a breaking change to the Truncate function, so I'm not sure of the process for this. If we want to maintain the current behaviour but add support for no suffix, we could change it so the 2nd parameter can be
""
to set no suffix, but my opinion is that no suffix by default would be desirable behaviour.tl;dr: if I truncate a string, I expect the result to be equal to or less than the truncate length, not longer.