Use dedent as a template tag or function
mainYou can use dedent in two ways:
- As a template tag: Use backticks (
`) to strip indentation from multi-line strings while keeping the code readable. - As a function: Pass a string directly to
dedent()to strip its indentation.
By default, dedent also trims leading and trailing lines from the resulting string.
import dedent from "dedent";
// As a template tag
const first = dedent`A string that gets so long you need to break it over
multiple lines.`;
// As a function
const third = dedent(`
Wait! I lied. Dedent can also be used as a function.
`);