Replace extraneous newlines with a single newline, or pass a specified number of newlines to use.
npm install condense-newlinesReplace extraneous newlines with a single newline, or pass a specified number of newlines to use.
Install with npm:
``sh`
$ npm install condense-newlines --save
`js`
var condense = require('condense-newlines');
console.log(condense('\n\na\n\n\nb\nc\r\n\r\nd\n\n\n'));
//=> '\na\nb\nc\nd\n';
Specify the separator to use
`js`
console.log(condense('\n\na\n\n\nb\nc\r\n\r\nd\n\n\n', {sep: '\n\n'}));
//=> '\n\na\n\nb\n\nc\n\nd\n\n';
The minimum number of consecutive newlines to condense.
Default
: 2
`js`
console.log(condense('\n\na\n\n\nb\nc\r\n\r\nd\n\n\n', {min: 2}));
//=> '\n\na\n\nb\n\nc\n\nd\n\n';
Don't treat whitespace-only lines as newlines.
`js
console.log(condense('\n\na\n\n \nb\nc\r\n\r\nd\n\n\n', {
keepWhitespace: true, sep: '\n\n'
}));
//=> '\n\na\n\n \nb\n\nc\n\nd\n\n';
`
You might also be interested in these projects:
* arr-union: Combines a list of arrays, returning a single array with unique values, using strict equality… more | homepage
* array-unique: Return an array free of duplicate values. Fastest ES5 implementation. | homepage
* arrayify-compact: Casts the given value to a flatten array, and removes falsey items (similar to lodash… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
`sh`
$ npm install verb && npm run docs
Or, if verb is installed globally:
`sh`
$ verb
Install dev dependencies:
`sh``
$ npm install -d && npm test
Jon Schlinkert
* github/jonschlinkert
* twitter/jonschlinkert
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
*
_This file was generated by verb, v0.9.0, on April 23, 2016._