Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multiline

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiline

Multiline strings in JavaScript

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

multiline Build Status

Multiline strings in JavaScript

No more string concatenation or array join!

Note that ES6 will have template string which can be multiline, but time...

How

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.

Install

Download manually or with a package-manager.

npm
npm install --save multiline
Bower
bower install --save multiline
Component
component install sindresorhus/multiline

Example

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>

Experiment

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>
*/);

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 05 Mar 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc