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
; 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
; const value = '1\n2\n3'; const string = multiline` Indented value: `;
Is equivalent to:
const string = `Indented value: 1 2 3`;
With with extra newlines
Extra newlines are respected:
; const string = multiline` Here is Another string For you `;
Is equivalent to:
const string = ` Here isAnother string For you`;
With CommonJS / require()
If you want to use this with CommonJS imports use the following syntax:
const multiline = default;
As a function
You can also call multiline as a normal function, however this will not be able to indent template variables.
; const string = ;
Is equivalent to:
const string = `Multiline string with varying indentation`;