
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Multiline strings in JavaScript
No more string concatenation or array join!
Note that ES6 will have template string which can be multiline, but time...
It works by wrapping the text in a block comment, anonymous function, and a function call. The anonymous function is passed into the function call and the contents of the comment extracted.
Even though it's slower than string concat, that shouldn't realistically matter as you can still do 2 million of those a second. Convenience over micro performance always.
Download manually or with a package-manager.
npm install --save multiline
bower install --save multiline
component install sindresorhus/multiline
Everything after the first newline and before the last will be returned as seen below:
var str = multiline(function(){/*
<!doctype html>
<html>
<body>
<h1>Hello world!</h1>
</body>
</html>
*/});
console.log(str);
// <!doctype html>
// <html>
// <body>
// <h1>Hello world!</h1>
// </body>
// </html>
I've also done an experiment where you don't need the anonymous function. It's too fragile and slow to be practical though.
It generates a callstack and extracts the contents of the comment in the function call.
var str = multiline(/*
<!doctype html>
<html>
<body>
<h1>Hello world!</h1>
</body>
</html>
*/);
MIT © Sindre Sorhus
FAQs
Multiline strings in JavaScript
The npm package multiline receives a total of 37,672 weekly downloads. As such, multiline popularity was classified as popular.
We found that multiline demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.