@metreeca/core - v0.9.22
    Preparing search index...

    Function tidy

    • Tidies the whitespace of a string.

      Replaces every run of whitespace with a single U+0020 SPACE 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:

      • Line terminators (\r\n, \r, \n) are normalised to \n
      • Every line is tidied in isolation, losing its own runs and margins
      • Blank lines are dropped, wherever they occur
      Note

      Zero-width characters, the U+200B ZERO 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.

      Parameters

      • string: string

        The string to tidy

      • multiline: boolean = false

        If true, retains the line structure, tidying each line on its own; if false, folds the string to a single line; defaults to false

      Returns string

      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