⚠️ dedent is maintained again, so this repo is not necessary anymore and will be considered deprecated.
It's basicly dedent, but with support for tabs and still maintained.
An ES6 string tag that strips indentation from multi-line strings.
import dedent from "dedent-tabs";
function usageExample() {
const first = 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.`;
const second = 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.
`;
const third = dedent(`
Wait! I lied. Dedent can also be used as a function.
`);
return first + "\n\n" + second + "\n\n" + third;
}
> console.log(usageExample());
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.
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.
Wait! I lied. Dedent can also be used as a function.
When using the template string tag syntax, for example:
dedent`
Hi there I am
a multi line
string
`
dedent
will not support all the escape sequences that a standard ES6 template string supports and will return them literally.
For example:
console.log(dedent`
\xA9
`)
// Logs "\xA9"
The currently supported escape sequences are:
The reason these escape characters are not fully supported is due to having to bypass the native escape character handling (using the raw property) in order to be able to handle newlines correctly.
There are plans to correct this in the future (see Issue #109).
All escape characters are supported when calling dedent-tabs as a function.
MIT
npm ci
- for a clean environmentnpm version patch|minor|major
- Bump version https://docs.npmjs.com/cli/v6/commands/npm-versionnpm run lint
- to ensure a consistent code stylenpm run test
- to make sure everything is working- Bump version
npm run build
- to create the bundle to releasegit commit -m "update bundle"
- to make sure the latest bundle is in thedist
directorynpm publish