# multiline-ts

> Readable multiline template strings

Latest version **4.0.1** (published 2024-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install multiline-ts
pnpm add multiline-ts
yarn add multiline-ts
bun add multiline-ts
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2024-08-09 |
| First published | 2020-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.18.0 |
| Dependencies | 0 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 5 |
| Author | Peter West |
| Maintainers | peterjwest |
| Keywords | string, multline, dedent, deindent, es6 |

## Links

- npm: https://www.npmjs.com/package/multiline-ts
- Repository: https://github.com/peterjwest/multiline-ts
- Homepage: https://github.com/peterjwest/multiline-ts#readme
- Issues: https://github.com/peterjwest/multiline-ts/issues
- npm.io page: https://npm.io/package/multiline-ts

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 4.0.1 (latest) — 2024-08-09
- 4.0.0 — 2024-07-24
- 3.1.0 — 2023-08-12
- 3.0.0 — 2023-03-26
- 2.2.0 — 2021-06-01
- 2.1.0 — 2020-08-15
- 2.0.0 — 2020-06-27
- 1.1.1 — 2020-06-01
- 1.1.0 — 2020-06-01
- 1.0.0 — 2020-05-31
- 0.1.2 — 2020-05-31
- 0.1.1 — 2020-05-31
- 0.1.0 — 2020-05-31

## README

# multiline-ts [![npm version][npm-badge]][npm-url] [![build status][circle-badge]][circle-url] [![coverage status][coverage-badge]][coverage-url]

Readable multi-line template strings for Javascript or Typescript.

multiline is a template tag function which removes leading indentation from each line of a string, and the first/last newline, to allow it to be more readable in code.

multiline also indents multi-line strings in template variables.

## Installation

```bash
npm install multiline-ts
```

## Usage

<!-- snippet: ts,js -->
```js
import multiline from 'multiline-ts';

const string = multiline`
  Multiline string
    with varying
      indentation
`;
```

Is equivalent to:

<!-- snippet: ts,js -->
```js
const string = `Multiline string
  with varying
    indentation`;
```

Which creates the string:

```plaintext
Multiline string
  with varying
    indentation
```

### In indented code

<!-- snippet: ts,js -->
```js
import multiline from 'multiline-ts';
const condition1 = true;
const condition2 = true;

if (condition1) {
  if (condition2) {
    const string = multiline`
      Multiline string
        with varying
          indentation
    `;
  }
}
```

Creates the same string:

```plaintext
Multiline string
  with varying
    indentation
```

### With template variables

<!-- snippet: ts,js -->
```js
import multiline from 'multiline-ts';

const value = '1\n2\n3';

const string = multiline`
  Indented value:
    ${value}
`;
```

Creates the string:

```plaintext
Indented value:
  1
  2
  3
```

### With with extra newlines

Extra newlines are respected:

<!-- snippet: ts,js -->
```js
import multiline from 'multiline-ts';

const string = multiline`

    Here is
  Another string
      For you

`;
```

Creates the string:

```plaintext

  Here is
Another string
    For you

```

### With CommonJS / require()

If you want to use this with CommonJS imports use the following syntax:

<!-- snippet: cjs -->
```js
const multiline = require('multiline-ts');
const string = multiline(`
  Multiline string
    with varying
      indentation
`);
```

### As a function

You can also call multiline as a normal function, however this will not be able to intelligently indent multi-line template variables.

<!-- snippet: ts,js -->
```js
import multiline from 'multiline-ts';

const string = multiline(`
  Multiline string
    with varying
      indentation
`);
```

Creates the string:

```plaintext
Multiline string
  with varying
    indentation
```

[npm-badge]: https://badge.fury.io/js/multiline-ts.svg
[npm-url]: https://www.npmjs.com/package/multiline-ts

[circle-badge]: https://circleci.com/gh/peterjwest/multiline-ts.svg?style=shield
[circle-url]: https://circleci.com/gh/peterjwest/multiline-ts

[coverage-badge]: https://coveralls.io/repos/peterjwest/multiline-ts/badge.svg?branch=main&service=github
[coverage-url]: https://coveralls.io/github/peterjwest/multiline-ts?branch=main

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