Neoanthropic Preternatural Murmurings
Have ideas to improve npm?Join in the discussion! »

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

2.1.0 • 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 a string, and the first/last newline, to allow it to be more readable in code.

multiline also indents multiline values in template variables.

Installation

npm install multiline-ts

or

yarn add 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

With template variables

import multiline from 'multiline-ts';
 
const value = '1\n2\n3';
 
const string = multiline`
  Indented value:
    ${value}
`;

Is equivalent to:

const 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
 
`;

Is equivalent to:

const 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').default;

As a function

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

import multiline from 'multiline-ts';
 
const string = multiline(`
  Multiline string
    with varying
      indentation
`);

Is equivalent to:

const string = `Multiline string
  with varying
    indentation`;

Install

npm i multiline-ts

DownloadsWeekly Downloads

26

Version

2.1.0

License

MIT

Unpacked Size

19 kB

Total Files

12

Last publish

Collaborators

  • avatar