{"id":13601691,"url":"https://github.com/sindresorhus/multiline","last_synced_at":"2026-10-19T13:42:43.961Z","repository":{"id":14733432,"uuid":"17454260","full_name":"sindresorhus/multiline","owner":"sindresorhus","description":"Multiline strings in JavaScript","archived":true,"fork":false,"pushed_at":"2021-01-23T17:42:12.000Z","size":35,"stargazers_count":1402,"open_issues_count":0,"forks_count":64,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-10-17T04:44:40.925Z","etag":null,"topics":["deprecated"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-03-05T20:31:03.000Z","updated_at":"2026-10-16T14:48:25.000Z","dependencies_parsed_at":"2022-09-05T17:00:26.609Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/multiline","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/sindresorhus/multiline","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmultiline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmultiline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmultiline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmultiline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/multiline/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fmultiline/sbom","scorecard":{"id":826601,"data":{"date":"2025-08-11","repo":{"name":"github.com/sindresorhus/multiline","commit":"81c2025e097a17042eb3665b65e94c504ba22f73"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 4/30 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T16:45:01.316Z","repository_id":14733432,"created_at":"2025-08-23T16:45:01.317Z","updated_at":"2025-08-23T16:45:01.317Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38357844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-19T02:00:06.414Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deprecated"],"created_at":"2024-08-01T18:01:06.502Z","updated_at":"2026-10-19T13:42:43.508Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","String","String [🔝](#readme)","Web 前端","📦 Legacy \u0026 Inactive Projects","Packages","字符串","Number"],"sub_categories":["Runner","Miscellaneous","运行器","运行器e2e测试"],"readme":"# multiline [![Build Status](https://travis-ci.org/sindresorhus/multiline.svg?branch=master)](https://travis-ci.org/sindresorhus/multiline)\n\n\u003e 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'\u003c!doctype html\u003e' +\n'\u003chtml\u003e' +\n'\t\u003cbody\u003e' +\n'\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e' +\n'\t\u003c/body\u003e' +\n'\u003c/html\u003e' +\n'';\n```\n\n#### After\n\n```js\nconst str = multiline(()=\u003e{/*\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003cbody\u003e\n\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\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(()=\u003e{/*\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003cbody\u003e\n\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\n*/});\n```\n\nWhich outputs:\n\n```\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003cbody\u003e\n\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\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(()=\u003e{/*\n\t\t\t\u003c!doctype html\u003e\n\t\t\t\u003chtml\u003e\n\t\t\t\t\u003cbody\u003e\n\t\t\t\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\t\t\t\u003c/body\u003e\n\t\t\t\u003c/html\u003e\n\t*/});\n```\n\nWhich outputs:\n\n```\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003cbody\u003e\n\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\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(()=\u003e{/*\n  I love %s\n*/}), str);\n\n//=\u003e '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\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003cbody\u003e\n\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\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 \u003e=17\n- Safari \u003e=4\n- Opera \u003e=9\n- Internet Explorer \u003e=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\u003c!doctype html\u003e\n\u003chtml\u003e\n\t\u003cbody\u003e\n\t\t\u003ch1\u003e❤ unicorns\u003c/h1\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\n*/console.log});\n```\n\n\n## License\n\nMIT © [Sindre Sorhus](https://sindresorhus.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmultiline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fmultiline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fmultiline/lists"}