dedent
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Dedent is an ES6 string tag utility that efficiently removes indentation from multi-line strings. It's an effective way to keep your code clean and readable, especially when dealing with long text strings that must break over several lines. Moreover, dedent also trims leading and trailing lines and properly handles indented lists, providing a smooth developer experience. It also allows usage as a function. Lastly, dedent supports special character escaping features, addressing the needs of projects of various complexities.
A fundamental yet efficient way to use the dedent module involves importing it into your JavaScript file. After this, you can use it as a tagged template literal or as a function. Here are examples for both.
import dedent from "dedent";
function usageExample() {
const first = dedent`A string that gets so long you need to break it over
multiple lines. Luckily dedent is here to keep it
readable without lots of spaces ending up in the string
itself.`;
const second = dedent`
Leading and trailing lines will be trimmed, so you can write something like
this and have it work as you expect:
* how convenient it is
* that I can use an indented list
- and still have it do the right thing
That's all.
`;
const third = dedent(`
Wait! I lied. Dedent can also be used as a function.
`);
return first + "\n\n" + second + "\n\n" + third;
}
console.log(usageExample());
If you want to customize dedent's function, you can use its withOptions
method. Consider:
import dedent from 'dedent';
const dedenter = dedent.withOptions({ /* ... */ });
dedenter`input`;
dedenter(`input`);
For comprehensive details on using the dedent module, the best source are the official project's docs, available on GitHub at https://github.com/dmnd/dedent. The documentation details numerous options and use cases with clear code examples, making it easier for developers to effectively use the module in their projects.