dedent es-toolkit
Removes the common leading whitespace from every line of a multi-line string.
Use it to write multi-line strings that follow your code's indentation, without the indentation ending up in the actual string.
Usage
dedent`text`
Use dedent as a tagged template literal to write multi-line strings inside indented code. It finds the smallest indentation shared by the non-empty lines and removes it from every line, so relative indentation differences between lines are preserved. If the first or last line contains only whitespace, it is removed.
Lines that contain only whitespace become empty lines, and Windows line endings (\r\n) are normalized to \n.
Parameters
The template literal to dedent.
The values to interpolate into the template literal.
Returns
The string with the common leading whitespace removed.
dedent(str)
Use dedent as a regular function when you want to remove the common leading whitespace from a string already stored in a variable.
Parameters
The string to dedent.
Returns
The string with the common leading whitespace removed.
dedent(tagFn)
To combine dedent with another tag function, pass the tag function as an argument, like dedent(tagFn). The new tag function receives template strings with the common leading whitespace already removed.
Parameters
The tag function to compose.
Returns
A new tag function that removes the common leading whitespace from the template strings before passing them to tagFn.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.