Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line template string with no newline characters?

I have this single line of code:

 console.log(`now running each hook with name '${chalk.yellow(aBeforeOrAfterEach.desc)}', for test case with name '${chalk.magenta(test.desc)}'.`);

the problem is I have to put it on multiple lines in my IDE, for it to fit (I go with 100 columns). When I put a template string on multiple lines, the template string interprets it as newline characters, which is not what I want.

So my question is - how can I have multiple lines of template string code without having it be logged with new line characters?

like image 340
Alexander Mills Avatar asked Oct 17 '25 09:10

Alexander Mills


1 Answers

use a backslash - \ - at the end of every line to avoid an insertion of \n

 console.log(`\
 now running each hook with name \
'${'foo'}', for test case with name '${'bar'}' \
.`);

Another option should be to use .split("\n").join('') which will replace all newlines with a empty string

like image 127
Kristianmitk Avatar answered Oct 19 '25 22:10

Kristianmitk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!