ts-dedent is a TypeScript package designed to intelligently remove common leading indentation and trim leading/trailing empty lines from multi-line strings, primarily when used with ES6 template literals. It aims to make highly indented code blocks within strings, such as SQL queries, HTML, or code samples, readable in source code without affecting their runtime representation. The current stable version is 2.2.0, with releases occurring irregularly, typically driven by dependency updates or minor bug fixes rather than continuous feature development. Key differentiators include its TypeScript-first approach, smart handling of indentation (only removing common leading whitespace), and robust support for template literal placeholders, building on concepts from other dedent libraries while providing specific TypeScript advantages.
npm install ts-dedentVerified import paths — ran on the pinned version, not inferred.
Demonstrates `ts-dedent` usage as a template tag and a function, showing how it intelligently removes common indentation and handles placeholders in multi-line strings.
Review existing template literals, especially those where the first character of a line might not be whitespace, to ensure desired indentation is preserved or adjusted.
Always use `import dedent from 'ts-dedent';` for ESM or `const dedent = require('ts-dedent').default;` for CommonJS.Upgrade to v2.2.0 or newer for the best ESM compatibility and features, including indentation of multiline string values within template literals.
Test output with multi-line string placeholders after upgrading to v2.2.0 to ensure the new indentation behavior aligns with expectations.
Change the import statement to `import dedent from 'ts-dedent';`.
Modify the require statement to `const dedent = require('ts-dedent').default;`.Review affected template literals. If a line should have its indentation removed, ensure it starts with whitespace, or adjust your expected output.
No dependency data recorded yet.