multiline-ts
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

multiline-ts npm version build status coverage status

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

npm install multiline-ts

Usage

import multiline from 'multiline-ts';

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

Is equivalent to:

const string = `Multiline string
  with varying
    indentation`;

Which creates the string:

Multiline string
  with varying
    indentation

In indented code

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:

Multiline string
  with varying
    indentation

With template variables

import multiline from 'multiline-ts';

const value = '1\n2\n3';

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

Creates the string:

Indented value:
  1
  2
  3

With with extra newlines

Extra newlines are respected:

import multiline from 'multiline-ts';

const string = multiline`

    Here is
  Another string
      For you

`;

Creates the string:


  Here is
Another string
    For you

With CommonJS / require()

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

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.

import multiline from 'multiline-ts';

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

Creates the string:

Multiline string
  with varying
    indentation

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.0.1500latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.1500
4.0.02
3.1.03
3.0.00
2.2.023
2.1.00
2.0.00
1.1.11
1.1.00
1.0.00
0.1.20
0.1.10
0.1.00

Package Sidebar

Install

npm i multiline-ts

Weekly Downloads

445

Version

4.0.1

License

MIT

Unpacked Size

9.31 kB

Total Files

9

Last publish

Collaborators

  • peterjwest