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:
\r\n, \r, \n) are normalised to \nText whose lines share no leading whitespace keeps its indentation, aside from these normalisations.
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.
The indented string to realign
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.
Realigns the literal sections under the same rules as the plain text form, then inserts the interpolated values, converted to strings as the template literal itself would. A value sourced at runtime thus never alters the layout of the literal around it, and a template can match the indentation of the surrounding code whatever it renders:
A tagged call and a plain call on the same literal differ whenever a value spans several lines or leaves its line blank. A plain call receives only the assembled string, so it computes the shared margin over the lines of the value as well, and treats a line left blank by an empty or blank value as blank rather than as content.
The literal sections of the template
The values interpolated between the literal sections
The assembled template with the line terminators of the literal normalised, the shared leading whitespace removed from every literal line, the values inserted verbatim and the outer blank lines dropped
Removes the common indentation from a block of text or a template literal.