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

    Function dedent

    Removes the common indentation from a block of text or a template literal.

    • Removes the common indentation from a block of text.

      Strips the longest leading whitespace sequence shared by all non-blank lines, so text laid out to match the indentation of the surrounding code reads as if written flush left:

      • Line terminators (\r\n, \r, \n) are normalised to \n
      • Blank lines are emitted empty and take no part in the shared sequence
      • Leading and trailing blank lines are dropped
      • Everything else is preserved, trailing whitespace on content lines included

      Text whose lines share no leading whitespace keeps its indentation, aside from these normalisations.

      Note

      Margins are compared as character sequences rather than as visual widths, so a tab never matches a run of spaces, even where the two render to the same width.

      Parameters

      • string: string

        The indented string to realign

      Returns string

      A copy of string with the line terminators normalised, the outer blank lines dropped and the shared leading whitespace removed from every line

    • Removes the common indentation from a template literal.

      Assembles the template exactly as the literal itself would, converting interpolated values to strings and splicing them into the literal sections, then strips the shared margin from the result under the same rules as the plain text form. Since values are spliced in before the margin is computed, multi-line values take part in the computation like any other text and a value whose continuation lines are flush left suppresses the dedent; a tagged call and a plain call on the same literal therefore return the same result.

      Parameters

      • template: TemplateStringsArray

        The literal sections of the template

      • ...values: readonly unknown[]

        The values interpolated between the literal sections

      Returns string

      The assembled template with the line terminators normalised, the outer blank lines dropped and the shared leading whitespace removed from every line

      text and markdown for tags that dedent while declaring the content type