1.1.0 • Published 6 years ago
multiline-template v1.1.0
multiline-template
Multiline tagged templates using a pipe | to signal line start. No more crazy indent hacks.
Install
npm install --save multiline-templateUsage
Using Tagged Template Literals, you use the pipe | to signal where you want to line to actually start in the resulting string.
import multiline from 'multiline-template';
// or
const multiline = require('multiline-template');
const msg = multiline`
|first
|second
|third
|fourth
`;
console.log(msg);first
second
third
fourthIt also indents interpolated values to the provided indention level
import multiline from 'multiline-template';
const part = multiline`
|second
|third
`;
const msg = multiline`
|first
| ${part}
|fourth
`;
console.log(msg);first
second
third
fourthThe line will always start where you say, no matter how much indention comes before the pipe.
import multiline from 'multiline-template';
(function () {
(function () {
// there is actually a lot of excess indention
// before the pipes, but it is ignored!
const part = multiline`
|second
|third
`;
const msg = multiline`
|first
| ${part}
|fourth
`;
console.log(msg);
})();
})();first
second
third
fourthCredit
This was heavily inspired by Scala's multiline string pipe markers, though there are some differences e.g. how nesting works.
:shipit: