Socket
Socket
Sign inDemoInstall

ts-dedent

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-dedent

TypeScript package which smartly trims and strips indentation from multi-line strings


Version published
Weekly downloads
5.4M
decreased by-19.58%
Maintainers
1
Install size
27.0 kB
Created
Weekly downloads
 

Package description

What is ts-dedent?

The ts-dedent package is a utility designed to remove indentation from multi-line template strings in TypeScript and JavaScript. This is particularly useful when working with code that needs to be displayed to the user or when dealing with strings that should not have additional leading whitespace that is typically introduced by code formatting in source files.

What are ts-dedent's main functionalities?

Dedentation of template strings

This feature allows you to normalize the indentation of multi-line strings to enhance readability and maintain consistent formatting. The dedent function automatically adjusts the indentation based on the least indented line in the template string.

import dedent from 'ts-dedent';

const text = dedent`
    This is a text
      with inconsistent
        indentation.`;
console.log(text); // Outputs:
// This is a text
//   with inconsistent
//     indentation.

Other packages similar to ts-dedent

Changelog

Source

v2.2.0

Add indentation to values with multiline strings & added ESM module

  • Updated all dependencies to their latest version
  • Updated CI settings (added node 16, multiple os platforms)
  • Moved from Travis CI to Github Actions

Readme

Source

TypeScript Dedent

codecov

TypeScript package which smartly trims and strips indentation from multi-line strings.

Usage Examples

import dedent from '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.

License

MIT

Based on

Changelog

See history for more details.

  • 2.2.0 2021-08-01 Add indentation to values with multiline strings & added ESM module
  • 2.1.1 2021-03-31 Update dependencies
  • 2.1.0 2021-03-24 Bugfixes
  • 2.0.0 2020-09-28 Bugfixes
  • 1.2.0 2020-09-28 Update dependencies and a couple of minor improvments
  • 1.1.0 2019-07-26 Update dependencies and fixed links in readme
  • 1.0.0 2018-06-14 Initial release

Keywords

FAQs

Last updated on 01 Aug 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc