There is more then one text pattern for line breaks depending on the operating system you want the content to work with. However for the most part you can get away with just using one or the other, many well designed applications are familiar with the different patterns and will detect what the situation is and parse accordingly. However it still makes sense to be al least somewhat aware of what these patterns are, and which might be the best choice for a given situation.
When it comes to windows style line breaks you will want to start off with a carriage return follow by a new line. For posix style js line breaks forget the carriage return ans just inject a new line.
So the carriage return and new line escape notation can be used to create an object that would contain bolt major patterns of interest like this:
The utf-16 code unit escape notation will work also.
So these kinds of solutions will work well in general, but in a nodejs environment there are some properties that are typically used. So lets look at just one more example at least when it comes to this sort of thing.
Now that I covered the basics of line breaks in general it might now be a good idea to start looking into some examples that have to do with just nodejs.
In node there is the End Of Line property of the os module. This property will hold a carriage return plus new line value for windows systems, and just a new line value for posix. In other words the value of the End Of line property will change depending on the underlaying operating system used.
If you want consistent values regardless of the operating system you might want to stick to escape notation.
Another options that comes to mind is the decode url component method.
Having a way to find out if there is a line bake in a string is something that will come up from time to time when working out a script. In nodejs often the result of calling a command in a Linux environment will spit out results where each line is terminated with a line break, if I want to spit that output into an array I will need to know how to do that. In a Linux system the line break will typically be a single new line char, however in windows it might be a carriage return followed by a new line.
Knowing how to find out if there is a line break is important however knowing how to go about creating a line break in a string is also something that I need to do also. If I want to create a script that will do s replace all for some text from one kind of line break to another, it will require that I I not just know how to find line breaks, but also how to go about injecting one of the options that I would want to replace them. This if often a feature in most text editors, however if I where to write my own text editor a feature such as this is one thing that I would want to have in such an application.