0.3.0 • Published 3 years ago
@beckkramer/letterpress v0.3.0
letterpress
A tiny typography utility library
Methods
tidyLines
This function prevents Runts: when a single word wrapping to a new line by itself. This is done by inserting the HTML entity for a non-breaking space (
) in place of the last space.
If there's room for all the words on a given line, there will be no visible effect. Screen readers will treat this character as they would any other space.
Before:
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua.
After:
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore
magna aliqua.
Useage:
const originalText = "An example sentence."
const formattedText = Letterpress.tidyLines(originalText)
// formattedText:
"An example sentence."