Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-dedentor

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-dedentor

[babel-plugin-dedent](https://github.com/MartinKolarik/babel-plugin-dedent) with more configuration.

  • 0.1.5
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

babel-dedentor

babel-plugin-dedent with more configuration.

Install

yarn add --save-dev babel-dedentor

In your babel.config.json:

{
  "plugins": [
    [
      "babel-dedentor",
      {
        // Showing default configuration, all of the following fields are optional
        "tagName": "dedent",
        // Retain the function call, useful for dedenting SQL statements and `chalk` strings.
        "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({
      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")

// Leading/trailing line break is removed.
expect(
  dedent`
	Line #1
	Line #2
	Line #3
	`
).to.equal("Line #1\nLine #2\nLine #3")

// No more than one leading/trailing line break is removed.
expect(
  dedent`

	Line #1
	Line #2
	Line #3

	`
).to.equal("\nLine #1\nLine #2\nLine #3\n")

// Only the "base" indentation is removed.
expect(
  dedent`
	Line #1
		Line #2
			Line #3
	`
).to.equal("Line #1\n\tLine #2\n\t\tLine #3")

// The last line is ignored if it doesn't contain anything else than whitespace.
expect(
  (function () {
    return dedent`
			Line #1
			Line #2
			Line #3
		`
  })()
).to.equal("Line #1\nLine #2\nLine #3")

// Escaped characters are ignored.
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.

Keywords

FAQs

Package last updated on 20 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc