condense-newlines
![Build Status](https://camo.githubusercontent.com/0c9fe2679767216a4b8f8c2d9af80d1de9a790e5028f9478debc1f27aa3a58ed/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f6e7363686c696e6b6572742f636f6e64656e73652d6e65776c696e65732e7376673f7374796c653d666c6174)
Replace extraneous newlines with a single newline, or pass a specified number of newlines to use.
Install
Install with npm:
$ npm install condense-newlines --save
Usage
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';
Options
options.sep
Specify the separator to use
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';
options.min
The minimum number of consecutive newlines to condense.
Default
: 2
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';
options.keepWhitespace
Don't treat whitespace-only lines as newlines.
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';
Related projects
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
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on April 23, 2016.