{"name":"multiline","version":"0.1.0","description":"Multiline strings in JavaScript","license":"MIT","main":"multiline.js","repository":{"type":"git","url":"git://github.com/sindresorhus/multiline"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"files":["multiline.js"],"keywords":["multiline","multi-line","multiple","line","comment","string","str","text","comment"],"devDependencies":{"mocha":"*","callsite":"^1.0.0"},"bugs":{"url":"https://github.com/sindresorhus/multiline/issues"},"homepage":"https://github.com/sindresorhus/multiline","_id":"multiline@0.1.0","dist":{"shasum":"aaf5c8da152eb2ef38089552cae938d894873571","tarball":"http://registry-npm.ywwl.com/multiline/download/multiline-0.1.0.tgz","integrity":"sha512-1XSJrulr00Q0MdTpTkgPsRoh5YatxjXNCc7PhU/MO76pEWrwiiIF2RaNNIQs4Rv+E3GzJwmbNUELxrPI05QiGQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDyhFCSjXN8Xal9XvPPIH1tcYdjujRdPAwK3khBt6WVswIhANhDP9ZsBLL/+jA6mmmbqx8QFMSe7gwPG8DdaMMdvJa+"}],"size":1577,"noattachment":false,"key":"/multiline/-/multiline-0.1.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"readme":"# multiline [![Build Status](https://travis-ci.org/sindresorhus/multiline.svg?branch=master)](https://travis-ci.org/sindresorhus/multiline)\n\n> Multiline strings in JavaScript\n\nNo more string concatenation or array join!\n\n*Use ES2015 [template literals](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) instead whenever possible.*\n\n#### Before\n\n```js\nconst str = '' +\n'<!doctype html>' +\n'<html>' +\n'\t<body>' +\n'\t\t<h1>❤ unicorns</h1>' +\n'\t</body>' +\n'</html>' +\n'';\n```\n\n#### After\n\n```js\nconst str = multiline(()=>{/*\n<!doctype html>\n<html>\n\t<body>\n\t\t<h1>❤ unicorns</h1>\n\t</body>\n</html>\n*/});\n```\n\n\n## How\n\nIt 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.\n\nEven though it's [slower than string concat](http://jsperf.com/multiline), that shouldn't realistically matter as you can still do 2 million of those a second. Convenience over micro performance always.\n\n\n## Install\n\n```\n$ npm install multiline\n```\n\n\n## Usage\n\nEverything after the first newline and before the last will be returned as seen below:\n\n```js\nconst str = multiline(()=>{/*\n<!doctype html>\n<html>\n\t<body>\n\t\t<h1>❤ unicorns</h1>\n\t</body>\n</html>\n*/});\n```\n\nWhich outputs:\n\n```\n<!doctype html>\n<html>\n\t<body>\n\t\t<h1>❤ unicorns</h1>\n\t</body>\n</html>\n```\n\n### Strip indent\n\nYou can use `multiline.stripIndent()` to be able to indent your multiline string without preserving the redundant leading whitespace.\n\n```js\n\tconst str = multiline.stripIndent(()=>{/*\n\t\t\t<!doctype html>\n\t\t\t<html>\n\t\t\t\t<body>\n\t\t\t\t\t<h1>❤ unicorns</h1>\n\t\t\t\t</body>\n\t\t\t</html>\n\t*/});\n```\n\nWhich outputs:\n\n```\n<!doctype html>\n<html>\n\t<body>\n\t\t<h1>❤ unicorns</h1>\n\t</body>\n</html>\n```\n\n\n### String substitution\n\n`console.log()` supports [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data):\n\n```js\nconst str = 'unicorns';\n\nconsole.log(multiline(()=>{/*\n  I love %s\n*/}), str);\n\n//=> 'I love unicorns'\n```\n\n\n## Use cases\n\n- [CLI help output](https://github.com/sindresorhus/pageres/blob/cb85922dec2b962c7b45484023c9ba43a9abf6bd/cli.js#L14-L33)\n- [Test fixtures](https://twitter.com/TooTallNate/status/465392558000984064)\n- [Queries](https://github.com/freethejazz/twitter-to-neo4j/blob/a41b6c2e8480d4b9943640a8aa4b6976f07083bf/cypher/queries.js#L15-L22) - *here an example in Cypher, the query language for Neo4j*\n- [CLI welcome message](https://github.com/yeoman/generator-jquery/blob/4b532843663e4b5ce7d433d351e0a78dcf2b1e20/app/index.js#L28-L40) - *here in a Yeoman generator*\n\nHave one? [Let me know.](https://github.com/sindresorhus/multiline/issues/new)\n\n\n## Experiment\n\nI've also done an [experiment](experiment.js) where you don't need the anonymous function. It's too fragile and slow to be practical though.\n\nIt generates a callstack and extracts the contents of the comment in the function call.\n\n```js\nconst str = multiline(/*\n<!doctype html>\n<html>\n\t<body>\n\t\t<h1>❤ unicorns</h1>\n\t</body>\n</html>\n*/);\n```\n\n\n## FAQ\n\n### But JS already has multiline strings with `\\`?\n\n```js\nconst str = 'foo\\\nbar';\n```\n\nThis is not a multiline string. It's line-continuation. It doesn't preserve newlines, which is the main reason for wanting multiline strings.\n\nYou would need to do the following:\n\n```js\nconst str = 'foo\\n\\\nbar';\n```\n\nBut then you could just as well concatenate:\n\n```js\nconst str = 'foo\\n' +\n'bar';\n```\n\n\n## Browser\n\nWhile it does work fine in the browser, it's mainly intended for use in Node.js. Use at your own risk.\n\n```\n$ npm install multiline\n```\n\nWith Webpack, Browserify, or something similar.\n\n\n### Compatibility\n\n- Latest Chrome\n- Firefox >=17\n- Safari >=4\n- Opera >=9\n- Internet Explorer >=6\n\n### Minification\n\nEven though minifiers strip comments by default there are ways to preserve them:\n\n- Uglify: Use `/*@preserve` instead of `/*` and enable the `comments` option\n- Closure Compiler: Use `/*@preserve` instead of `/*`\n- YUI Compressor: Use `/*!` instead of `/*`\n\nYou also need to add `console.log` after the comment so it's not removed as dead-code.\n\nThe final result would be:\n\n```js\nconst str = multiline(function(){/*!@preserve\n<!doctype html>\n<html>\n\t<body>\n\t\t<h1>❤ unicorns</h1>\n\t</body>\n</html>\n*/console.log});\n```\n\n\n## License\n\nMIT © [Sindre Sorhus](https://sindresorhus.com)\n","publish_time":1394051470837,"_cnpm_publish_time":1394051470837,"dist-tags":{"latest":"2.0.0"}}