Registry / serialization / ts-dedent

ts-dedent

JSON →
library2.2.0jsnpmunverified

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-dedent
INSTALL
IMPORT
SIG · TS-DEDENT
T
ts-dedent
serializationjavascriptv2.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dedent
import dedent from 'ts-dedent';
import { dedent } from 'ts-dedent';
The `dedent` function is exported as the default export of the 'ts-dedent' package. Do not use named import syntax.
dedent
const dedent = require('ts-dedent').default;
const dedent = require('ts-dedent');
For CommonJS, access the default export via `.default`.
dedent
import dedent from 'ts-dedent';
import dedent from 'dedent';
Ensure you are importing from 'ts-dedent' (this package), not 'dedent' (a different, unrelated package). The README example is misleading.

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.

import dedent from 'ts-dedent'; // Example 1: Basic dedentation console.log(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. `); // Example 2: Dedentation with nested indents and placeholders const user = 'Alice'; const items = ['apple', 'banana', 'cherry']; console.log(dedent` Hello, ${user}! Here is your shopping list: * ${items[0]} * ${items[1]} * ${items[2]} Thank you. `); // Example 3: Using dedent as a function const multilineString = dedent(` This also works perfectly fine as a regular function call. `); console.log(multilineString);
Debug
Known issues
breakingVersion 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.
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.
affects: >=2.0.0
gotchaThe README examples incorrectly show `import dedent from 'dedent';`. This refers to a *different* npm package. For `ts-dedent`, you *must* import from `'ts-dedent'`.
fix
Always use `import dedent from 'ts-dedent';` for ESM or `const dedent = require('ts-dedent').default;` for CommonJS.
affects: >=1.0.0
deprecatedOlder 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.
fix
Upgrade to v2.2.0 or newer for the best ESM compatibility and features, including indentation of multiline string values within template literals.
affects: <2.2.0
gotchaStarting 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.
fix
Test output with multi-line string placeholders after upgrading to v2.2.0 to ensure the new indentation behavior aligns with expectations.
affects: >=2.2.0
Errors
Common errors & fixes
TypeError: (0 , ts_dedent_1.default) is not a function
Attempting to use `dedent` as a named import (e.g., `import { dedent } from 'ts-dedent';`) when it's exported as a default.
fix
Change the import statement to `import dedent from 'ts-dedent';`.
TypeError: require(...) is not a function
Attempting to use CommonJS `require('ts-dedent')` directly without accessing the default export.
fix
Modify the require statement to `const dedent = require('ts-dedent').default;`.
My string has extra unwanted indentation after upgrading!
Upgrading to v2.0.0 changed how `ts-dedent` handles lines not starting with whitespace, causing previous assumptions about indentation removal to be incorrect.
fix
Review affected template literals. If a line should have its indentation removed, ensure it starts with whitespace, or adjust your expected output.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
ts-dedent — npm install ts-dedent · libregistry