Skip to content

Instantly share code, notes, and snippets.

@dmitrymatveev
Created May 30, 2019 23:12
Show Gist options
  • Save dmitrymatveev/75886c5b966f784709388088706a67a2 to your computer and use it in GitHub Desktop.
Save dmitrymatveev/75886c5b966f784709388088706a67a2 to your computer and use it in GitHub Desktop.
/**
* Removes new lines and tabs and preceding whitespace in a multi-line
* template strings.
*
* E.g.:
* console.log(lineTag`line: ${1}
* line: ${2}
* line: ${3}`); // line: 1 line: 2 line: 3
*
* @param {string[]} strings
* @param {...any} args
*/
function lineTag(strings, ...args) {
return strings
.map((str, i) => str + (args.length > i ? args[i] : ''))
.map(str => str.replace(/(?:\n)\s{2,}/g, ''))
.join('')
.replace(/[\n\t]+/g, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment