ts-dedent
TypeScript package which smartly trims and strips indentation from multi-line strings
This package has a good security score with no known vulnerabilities.
Community Reviews
Dead simple template literal indentation - works perfectly first try
The package handles edge cases gracefully: mixed tabs/spaces, empty lines, and varying indentation levels all work as expected. Error handling is a non-issue because there's virtually nothing that can go wrong - it's just a tagged template function. When debugging, the output is predictable and transparent, making it easy to verify the formatting matches your expectations.
Documentation is minimal but sufficient since the API surface is tiny. The README shows the core use case clearly, and that's genuinely all you need. Community support isn't really necessary - I've never needed to look up issues or ask questions because the behavior is intuitive and consistent.
Best for: Formatting multi-line strings in tests, SQL queries, or generated content where you want clean output without manual spacing gymnastics.
Avoid if: You need complex string transformation logic or custom indentation rules beyond simple dedenting.
Simple, zero-dependency utility with minimal security surface area
In daily use, it's most valuable for composing SQL queries, error messages, or any multi-line strings where you want clean formatting without manual spacing gymnastics. The API is dead simple - just wrap your template literal with `dedent`. It handles edge cases like mixed indentation reasonably well, though you need to be mindful that it doesn't perform any escaping or sanitization.
The main security consideration is understanding what it doesn't do: there's no input validation, no SQL/HTML escaping, no protection against injection attacks. It's purely cosmetic formatting. If you're using it to build queries or commands, you still need proper parameterization elsewhere. The package hasn't been updated since 2021, but given its simplicity and completeness, this isn't necessarily a red flag.
Best for: Formatting template literals for SQL queries, error messages, or documentation where you control the input and handle sanitization separately.
Avoid if: You need input validation, escaping, or sanitization - this only handles whitespace formatting.
Lightweight string utility with minimal attack surface, no security concerns
In practice, I use this primarily for test fixtures, SQL query formatting, and generating multi-line strings in code. The API is dead simple: wrap your template literal with `dedent` and it intelligently removes leading indentation. No configuration needed, no edge cases I've encountered. Input validation isn't really applicable here—it accepts strings and returns strings, with no parsing or interpretation that could be exploited.
The main consideration is that this is purely a developer convenience tool. It doesn't sanitize or validate content, so if you're building SQL queries or HTML, you still need proper parameterization or escaping. The library makes no claims about security transforms, which is actually refreshing—it has a clear, limited scope.
Best for: Formatting test fixtures, SQL queries, or multi-line strings where indentation clarity matters but security transforms aren't needed.
Avoid if: You need actual input sanitization, escaping, or validation—this only handles whitespace formatting.
Sign in to write a review
Sign In