I am implementing a NodeJS script which auto-generates JavaScript code.
I need to write "xxx\n"
somewhere in the auto-generated JavaScript file.
But I want the \n
part to be OS-compatible.
I've figured I should use require("os").EOL
, for example:
let EOL = require("os").EOL;
let str = `xxx${EOL}`;
...
// write str into the file
But that writes a real newline into the file.
How can I convert that EOL
into an actual string, like "\n"
or "\r\n"
?
P.S.:
For performance considerations, I wish to avoid plugging require("os").EOL
into the auto-generated file (i.e., I want the newline to be "hard-coded" in there).