Removing line breaks looks like a one-regex job. text.replace(/\n/g, '') and you're done. Then real text shows up, and it turns out line endings are a small historical mess.

There are three different characters that can end a line: LF, CRLF, and CR. Text copied from Word, a spreadsheet, or a GitHub issue uses whichever one its origin platform chose, and a single paste can contain several at once. Remove only \n and the \r characters are still there. Remove everything and paragraph boundaries collapse into a wall of text.

I built a line break remover as part of TextFixHub, a collection of free browser-based text utilities.

You can try it here:

TextFixHub Line Break Remover