multiline-template
Multiline tagged templates using a pipe |
to signal line start. No more crazy indent hacks.
Install
npm install --save multiline-template
Usage
Using Tagged Template Literals, you use the pipe |
to signal where you want to line to actually start in the resulting string.
;// orconst multiline = ; const msg = multiline` |first |second |third |fourth`; console;
first
second
third
fourth
It also indents interpolated values to the provided indention level
; const part = multiline` |second |third`; const msg = multiline` |first | |fourth`; console;
first
second
third
fourth
The line will always start where you say, no matter how much indention comes before the pipe.
; { { // there is actually a lot of excess indention // before the pipes, but it is ignored! const part = multiline` |second |third `; const msg = multiline` |first | |fourth `; console; };};
first
second
third
fourth
Credit
This was heavily inspired by Scala's multiline string pipe markers, though there are some differences e.g. how nesting works.
:shipit: