babel-dedentor
babel-plugin-dedent with more configuration.
Install
yarn add --save-dev babel-dedentor
In your babel.config.json
:
{
"plugins": [
[
"babel-dedentor",
{
"tagName": "dedent",
"keepFunctionCall": false,
"trimLeft": true,
"trimRight": true
}
]
]
}
Prefer type safe Babel configuration? Try the following:
import { useDedentPlugin } from "babel-dedentor"
export default {
plugins: [
useDedentPlugin(["dedent", "html"]),
useDedentPlugin({
name: "dedent2",
tagName: "dedent",
keepFunctionCall: false,
trimLeft: true,
trimRight: true,
}),
],
}
Usage
Indentation will be removed from all strings tagged with dedent
tag (or any tag specified in your configuration).
expect(dedent`Line #1
Line #2
Line #3`).to.equal("Line #1\nLine #2\nLine #3")
expect(
dedent`
Line #1
Line #2
Line #3
`
).to.equal("Line #1\nLine #2\nLine #3")
expect(
dedent`
Line #1
Line #2
Line #3
`
).to.equal("\nLine #1\nLine #2\nLine #3\n")
expect(
dedent`
Line #1
Line #2
Line #3
`
).to.equal("Line #1\n\tLine #2\n\t\tLine #3")
expect(
(function () {
return dedent`
Line #1
Line #2
Line #3
`
})()
).to.equal("Line #1\nLine #2\nLine #3")
expect(
dedent`
\tLine #1
\tLine #2
\tLine #3
`
).to.equal("\tLine #1\n\tLine #2\n\tLine #3")
License
Copyright (c) 2020 ~proteria.
Copyright (c) 2015 - 2020 Martin Kolárik.
Released under the MIT license.