Other one-liner answers in this thread are wrong while those won't replace all new lines sequences with 2 new lines but will do that only once. Those will run once over the string. Which means if there will be 6 new lines, i twill replace 3 to 2 and next 3 to 2 again. So result would be 4 new lines. Then you would need to run this code again, which would replace 3 new lines with 2 and leftover of 1 new line would be untouched, so after 2nd run you would have 3 new lines. If you would run for the 3rd time only then you would reduce from 6 new lines to just 2.
So the correct one-liner answer is this:
yourString.replace(/^\s*[\r\n]|^\s+| +(?= )| +$|\s+$(?![^])/gm, '\n\n');
Full sample:
const a = `
a
b
`;
const result = a.replace(/^\s*[\r\n]|^\s+| +(?= )| +$|\s+$(?![^])/gm, '\n\n');
console.log(result);
Result will be as you would expect:

Why other answers are wrong? Check this out:

See \n for all "new line"

Replaced some, but not all

Replaced some, but not all again