# tidy-template

> Indentation fixer for [nested] multiline JavaScript template literals

Latest version **1.0.7** (published 2020-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install tidy-template
pnpm add tidy-template
yarn add tidy-template
bun add tidy-template
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2020-06-05 |
| First published | 2018-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jonathan Hironaga |
| Maintainers | edwinchoi, jin-at-capitect, jonathan-at-capitect |

## Links

- npm: https://www.npmjs.com/package/tidy-template
- Repository: https://github.com/capitect/tidy-template
- Homepage: https://github.com/capitect/tidy-template#readme
- Issues: https://github.com/capitect/tidy-template/issues
- npm.io page: https://npm.io/package/tidy-template

## Recent versions

- 1.0.7 (latest) — 2020-06-05
- 1.0.6 — 2019-12-03
- 1.0.5 — 2019-12-03
- 1.0.4 — 2018-07-20
- 1.0.3 — 2018-03-17
- 1.0.2 — 2018-03-17
- 1.0.1 — 2018-03-17
- 1.0.0 — 2018-03-17

## README

# tidy-template
Indentation fixer for [nested] multiline JavaScript template literals

## Installation
```
npm install tidy-template
```

## Usage
**Node v6.0.0+ is required.**

```javascript
const tidy = require('tidy-template');
```

The first line, last line, and common indentation are removed.
```javascript
tidy`
  1
  2
`;
// '1\n2'
```

Relative indentation is preserved.
```javascript
tidy`
  1
    2
`;
// '1\n  2'
```

Relative indentation of interpolated multiline strings is preserved.
```javascript
tidy`
  0
    ${'1\n  2'}
`;
// '0\n  1\n    2'
```

The content and last line can be indented as much or as little as you like.
```javascript
        tidy`
          1
            2
        `; 
// '1\n  2'

tidy`
1
  2
`; 
// '1\n  2'
```

Tabs can be used instead of spaces.
```javascript
tidy`
\t1
\t\t2
`;
// '1\n\t2'
```

Empty and whitespace-only lines are ignored when calculating common indentation,
but are included when removing it.
```javascript
tidy`

\t
\t\t1
\t\t\t2
\t\t\t\t
`;
// '\n\n1\n\t2\n\t\t'
```

## Errors
TidyTemplate throws errors to help ensure correct usage and results.

1. The template literal backticks must be on separate lines from the content.
This eliminates ambiguity around indentation and trailing newlines.  

   Don't do this:
   ```javascript
   tidy`1
          2`;
   // Error
   ```

   Or this:
   ```javascript
   tidy`
     1
       2`;
   // Error
   ```
   
   Or this:
   ```javascript
   tidy`1
          2
   `;
   // Error
   ```

2. TidyTemplate must be used as a tag, without parentheses. This allows the
indentation of interpolated values to be adjusted.

   Don't do this either:
   ```javascript
   tidy(`
     1
       2
   `);
   // Error
   ```

---
_Source: https://npm.io/package/tidy-template · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
