Join an array of strings with newlines
npm install join-newlinesJoin an array of strings with newlines.
_If I should maintain this repo, please ⭐️_
_DM me on Twitter if you have questions or suggestions._
---
``sh`
yarn add join-newlines
`sh`
npm install join-newlines
`sh`
pnpm add join-newlines
The provided array of strings is joined with newlines. Any undefined values are filterd out.
Additionally, you can pass true as a second argument to append a newline to the end of the string.
`ts
import join from "join-newlines";
join([
"This is the first line.",
"Then I want this on a second line.",
"I also want this on a third line."
]);
// "This is the first line.\nThen I want this on a second line.\nI also want this on a third line."
join([
"This is the first line.",
"Then I want this on a second line.",
undefined,
"I also want this on a third line."
]);
// "This is the first line.\nThen I want this on a second line.\nI also want this on a third line."
join([
"This is the first line.",
"Then I want this on a second line.",
"I also want a newline at the end."
], true); // Add true to append a newline to the end as well.
// "This is the first line.\nThen I want this on a second line.\nI also want a newline at the end.\n"
`
- autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.