verb
Version:
A project without documentation is like a project that doesn't exist. Verb solves this by making it dead simple to generate docs, using simple markdown templates, with zero configuration required.
19 lines (17 loc) • 390 B
JavaScript
const _ = require('lodash');
/**
* Replace extraneous newlines with a single newline.
*
* @title compact
* @param {String} str
*
* @return {String}
* @api public
*/
module.exports = function (str, sep) {
sep = sep || '\n';
str = (str || '\n\n').replace(/[\r\n?|\n]+/gm, '\n');
return _.compact(str.split(sep).map(function(line) {
return line.trim();
})).join(sep);
};