Wondering what’s next for npm?Check out our public roadmap! »

dedent-tabs

0.9.0 • Public • Published

Dedent-Tabs

npm npm bundle size monthly downloads

Build Status CI Code Coverage Codacy Badge Dependabot Status Dependency Status Dependency Status

It's basicly dedent, but with support for tabs and still maintained.

An ES6 string tag that strips indentation from multi-line strings.

Usage

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.

Escape characters in template strings

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.

License

MIT

Release new version

  1. npm ci - for a clean environment
  2. npm version patch|minor|major - Bump version https://docs.npmjs.com/cli/v6/commands/npm-version
  3. npm run lint - to ensure a consistent code style
  4. npm run test - to make sure everything is working
  5. Bump version
  6. npm run build - to create the bundle to release
  7. git commit -m "update bundle" - to make sure the latest bundle is in the dist directory
  8. npm publish

Install

npm i dedent-tabs

DownloadsWeekly Downloads

18,470

Version

0.9.0

License

MIT

Unpacked Size

8.12 kB

Total Files

4

Last publish

Collaborators

  • avatar