You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Illustrate a tagged template literal function that makes multiline string literals require explicit linebreaks instead of assuming them.
functionmultiline(strings,...values){returnFunction(`return "${strings.raw.join("").replace(/\n/g,"")}"`)();}// TODO: fix this so it adds in the interpolated values// (but does not strip linebreaks in those values!)// TODO: also, don't use the `Function(..)` option; just find// actual "\n" occurrences in the raw strings and make them// into linebreaks// WIP:// function multiline(strings,...values) {// var strs = strings.raw.map(function mapper(v){// return v.replace(/\n/g,"")// .replace(/(^|[^\\]|(?:\\\\)+)((?:\\n)+)/g,function(match,p1,p2){// return `${p1}${p2.replace(/\\n/g,"\n")}`;// });// });// return strs.join("");// }``````jsconsole.log( `helloworld` );// hello// // world
console.log(multiline`hello world`);// hello world
console.log(multiline`hello\n\n world`);// hello//// world
The text was updated successfully, but these errors were encountered:
Illustrate a tagged template literal function that makes multiline string literals require explicit linebreaks instead of assuming them.
The text was updated successfully, but these errors were encountered: