Skip to content

dedentLines

dedentLines(text): string[]

Defined in: packages/core/src/string/dedent.ts:19

Removes the longest whitespace prefix shared by every non-blank line.

The inverse of prefixLines: text indented to sit inside a block of code reads as an accident once it is lifted out of it. Blank lines are ignored when measuring, since a trailing line of zero length would otherwise force the common prefix to the empty string; they are emitted as empty rather than kept as runs of spaces.

Tabs and spaces are compared as characters, not expanded to columns — mixing them within one block is what makes an expansion necessary, and guessing a tab width there would silently pick one indentation over another.

O(n) in the total length of the text.

string | string[]

The text to dedent, as a string or as lines.

string[]

The dedented lines.