In typesetting, single words on the last line of a paragraph are commonly known
as widows, and are
considered bad style.
widont eliminates the issue of widows by using a
non-breaking space to force the last two words of a string onto the same line.
If the last word contains hyphens they will be converted to the non-breaking
var widont =// => 'I dream of a world without\u00a0widows'// => 'I like words with hyphens that stick\u2011together'// => 'I get HTML entities instead'// => 'I get exclamation!!marks'
widont'TypeScript says hello', 'html'// => 'TypeScript says hello'
Replaces any number of whitespace before the last word of
string with a
non-breaking space, unless the last word contains hyphens in which case they
will be replaced (by non-breaking hyphens) instead. Trims trailing whitespace
at the end of
string if present. Returns non-string inputs as-is.
replacements argument specifies what characters to use as
replacements. It can either be a string that maps to a set of predefined
ascii), or an object with the keys
hyphen (both must be provided):
space: '_'hyphen: '~'
TypeError will be thrown for unknown or incomplete