Open
Description
Is your feature request related to a problem? Please describe.
Sometimes it's useful to truncate strings and other things.
Words (max length 10 chars, truncation chars = "..."):
"Hello world" => "Hello..." // whole words only
"Hello" => no change
Chars (max length 10 chars, truncation chars = "..."):
"Hello world" => "Hello w..." // max length accounts for chars used for truncation
"Hello" => no change
Describe the solution you'd like
New functionality such as truncateWords
and/or truncateGraphemes
under text
.
Describe alternatives you've considered
- What do "words" and "chars" mean (cf:
Intl.Segmenter
withgranularity
of "words"/"graphemes") - What options should be available? At a minimum, what text/items to use as truncation placeholder, as well as max length (which may not be in the same unit as the base granularity, i.e. when truncating words, you probably care more about the char/grapheme length than the word length)
- Are other granularities useful for text? E.g. sentences, lines?
- For perf reasons, the general unit of measurement for the text functions could be Unicode code points, with the segmenter only being used at the boundary. Alternatively, the "Unicode width" could be used as a heuristic, though it's only a very rough indication of physical width in non-TTY environments, especially in non-monospaced fonts.
Metadata
Metadata
Assignees
Labels
No labels