{"id":12168,"library":"ts-dedent","title":"TypeScript Dedent","description":"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.","status":"maintenance","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/tamino-martinius/node-ts-dedent","tags":["javascript","dedent","deindent","indentation","multi-line string","multiline strings","template literals","template strings","ts","typescript"],"install":[{"cmd":"npm install ts-dedent","lang":"bash","label":"npm"},{"cmd":"yarn add ts-dedent","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-dedent","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `dedent` function is exported as the default export of the 'ts-dedent' package. Do not use named import syntax.","wrong":"import { dedent } from 'ts-dedent';","symbol":"dedent","correct":"import dedent from 'ts-dedent';"},{"note":"For CommonJS, access the default export via `.default`.","wrong":"const dedent = require('ts-dedent');","symbol":"dedent","correct":"const dedent = require('ts-dedent').default;"},{"note":"Ensure you are importing from 'ts-dedent' (this package), not 'dedent' (a different, unrelated package). The README example is misleading.","wrong":"import dedent from 'dedent';","symbol":"dedent","correct":"import dedent from 'ts-dedent';"}],"quickstart":{"code":"import dedent from 'ts-dedent';\n\n// Example 1: Basic dedentation\nconsole.log(dedent`\n  A string that gets so long you need to break it over\n  multiple lines. Luckily dedent is here to keep it\n  readable without lots of spaces ending up in the string\n  itself.\n`);\n\n// Example 2: Dedentation with nested indents and placeholders\nconst user = 'Alice';\nconst items = ['apple', 'banana', 'cherry'];\nconsole.log(dedent`\n  Hello, ${user}!\n  Here is your shopping list:\n\n    * ${items[0]}\n    * ${items[1]}\n    * ${items[2]}\n\n  Thank you.\n`);\n\n// Example 3: Using dedent as a function\nconst multilineString = dedent(`\n  This also works perfectly\n  fine as a regular function call.\n`);\nconsole.log(multilineString);","lang":"typescript","description":"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."},"warnings":[{"fix":"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.","message":"Version 2.0.0 introduced a breaking change regarding indentation removal logic. Previously, indentation was always removed. Now, if a line does not start with whitespace, its indentation will not be removed.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always use `import dedent from 'ts-dedent';` for ESM or `const dedent = require('ts-dedent').default;` for CommonJS.","message":"The README examples incorrectly show `import dedent from 'dedent';`. This refers to a *different* npm package. For `ts-dedent`, you *must* import from `'ts-dedent'`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to v2.2.0 or newer for the best ESM compatibility and features, including indentation of multiline string values within template literals.","message":"Older versions (prior to 2.2.0) had less robust ESM support. While CJS was always supported, the introduction of a dedicated ESM module in v2.2.0 improved compatibility.","severity":"deprecated","affected_versions":"<2.2.0"},{"fix":"Test output with multi-line string placeholders after upgrading to v2.2.0 to ensure the new indentation behavior aligns with expectations.","message":"Starting with v2.2.0, `ts-dedent` adds indentation to values that contain multiline strings. This might subtly change output if your placeholders previously contained un-indented multi-line strings.","severity":"gotcha","affected_versions":">=2.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to `import dedent from 'ts-dedent';`.","cause":"Attempting to use `dedent` as a named import (e.g., `import { dedent } from 'ts-dedent';`) when it's exported as a default.","error":"TypeError: (0 , ts_dedent_1.default) is not a function"},{"fix":"Modify the require statement to `const dedent = require('ts-dedent').default;`.","cause":"Attempting to use CommonJS `require('ts-dedent')` directly without accessing the default export.","error":"TypeError: require(...) is not a function"},{"fix":"Review affected template literals. If a line should have its indentation removed, ensure it starts with whitespace, or adjust your expected output.","cause":"Upgrading to v2.0.0 changed how `ts-dedent` handles lines not starting with whitespace, causing previous assumptions about indentation removal to be incorrect.","error":"My string has extra unwanted indentation after upgrading!"}],"ecosystem":"npm"}