selective-whitespace
Condense all whitespace in a string, with options to preserve specific whitespace characters.
Install
$ npm install --save selective-whitespace
Usage
var selectiveWhitespace = require('selective-whitespace');
selectiveWhitespace(' FOO BAR BAZ ');
selectiveWhitespace('FOO\n BAR\n BAZ\n ', {keep: '\n'});
selectiveWhitespace('\tFOO \tBAR \tBAZ', {keep: '\t'});
selectiveWhitespace('\n\tFOO \n\tBAR \n\tBAZ', {keep: '\t,\n'});
selectiveWhitespace('\t\nFOO \t\nBAR \t\nBAZ', {stripAll:true});
API
selectiveWhitespace(str, [options]);
str
Required
Type: string
The string you want to condense.
options
Type: object
Set or override the default options.
keep
Type: string
options: \n\t\r
Comma or pipe-delimited list of values to preserve. You can preserve newlines \n
, tabs \t
or return characters \r
.
stripAll
Type: Boolean
Default: false
stripAll
mode will remove all whitespace characters from the string.
License
MIT © Michael Wuergler