selective-whitespace
Condense all whitespace in a string, with options to preserve specific whitespace characters.
Install
$ npm install --save selective-whitespace
Usage
var selectiveWhitespace = ; // Condense all whitespace (including \t\n\r);//=> 'FOO BAR BAZ' // Condense all whitespace (keep newlines);//=> 'FOO\n BAR\n BAZ\n' // Condense all whitespace (keep tabs);//=> '\tFOO \tBAR \tBAZ' // Condense all whitespace (keep tabs and newlines);//=> '\n\tFOO \n\tBAR \n\tBAZ' // Strip all whitespace characters;//=> 'FOOBARBAZ'
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