The string to tidy
If true, retains the line structure, tidying each line on its own; if false, folds the string
to a single line; defaults to false
A copy of string with every run of whitespace replaced by a single space and the outer whitespace
dropped, taken as a whole or, if multiline, line by line, with the line terminators normalised and the blank
lines dropped
Tidies the whitespace of a string.
Replaces every run of whitespace with a single
U+0020SPACE and drops the runs at either end, so that content padded for alignment, or laid out across several lines, reads as the evenly spaced text a label, a message or an attribute value expects; everything else is preserved.Whitespace is the set ECMAScript recognises: the ASCII blanks and line terminators, the no-break space, the Unicode space separators and the byte order mark.
Single-line tidying —
tidy(string)Folds the line terminators along with the rest, so that however the content was laid out the result is one line, ready for a slot that admits no line breaks.
Multiline tidying —
tidy(string, true)Retains the line structure, for content whose lines carry meaning, tidying each line on its own and reporting only the ones left with content:
\r\n,\r,\n) are normalised to\nZero-width characters, the
U+200BZERO WIDTH SPACE among them, carry no whitespace property and are left as they are, so a string that reads as tidied may still hold invisible content.