
Company News
Jerod Santo Joins Socket as Head of Media
Allow myself to introduce... myself.
TypeScript package which smartly trims and strips indentation from multi-line strings
TypeScript package which smartly trims and strips indentation from multi-line strings.
import { dedent } from 'ts-dedent';
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.`);
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.
`);
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.
console.log(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.
`);
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.
console.log(dedent`
Also works fine
${1}. With any kind of
${2}. Placeholders
`);
Also works fine
1. With any kind of
2. Placeholders
console.log(dedent(`
Wait! I lied. Dedent can also be used as a function.
`);
Wait! I lied. Dedent can also be used as a function.
dedent runs the following steps on the string, in order:
dedent counts its leading spaces and tabs. The "common
indentation" is the smallest of those counts — i.e. the line with the
fewest leading whitespace characters. Blank lines are ignored, and a line
that starts with a non-whitespace character counts as 0 (so if any content
line has no indentation, nothing is stripped).${...} values are inserted. If a value is
itself a multi-line string, every line after its first is re-indented to
match the placeholder's position, so nested/multi-line values stay aligned.So to answer the common question directly: it removes the indentation of the line with the fewest leading whitespace characters — not the first indented line — and applies that same removal to every line.
A few details worth knowing:
// Lines indented by 4, 2, and 6 spaces. The minimum is 2, so 2 spaces are
// removed from every line:
console.log(dedent`
four
two
six
`);
four
two
six
MIT
See history for more details.
Similar to ts-dedent, the dedent package is also aimed at removing excess indentation from multi-line strings. It works in a similar manner but does not specifically target TypeScript, making ts-dedent potentially more suitable for projects that are using TypeScript.
The strip-indent package removes leading whitespace from each line in a string. It differs from ts-dedent in that it does not consider the relative indentation levels between lines, but simply strips the common leading whitespace from all lines.
FAQs
TypeScript package which smartly trims and strips indentation from multi-line strings
The npm package ts-dedent receives a total of 11,324,106 weekly downloads. As such, ts-dedent popularity was classified as popular.
We found that ts-dedent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Company News
Allow myself to introduce... myself.

Research
/Security News
A Twitch browser extension on Chrome and Firefox forwards users’ live OAuth session tokens through proxies controlled by a Russian bot service.

Security News
Anthropic found biased reasoning and recklessness drove Claude Mythos 5 to publish malware on PyPI and compromise a security vendor.