Socket
Socket
Sign inDemoInstall

selective-whitespace

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    selective-whitespace

Condense all string whitespace + options to preserve specific whitespace characters.


Version published
Weekly downloads
7.3K
decreased by-28.36%
Maintainers
1
Install size
12.0 kB
Created
Weekly downloads
 

Readme

Source

selective-whitespace Build Status

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');

// Condense all whitespace (including \t\n\r)
selectiveWhitespace('  FOO      BAR    BAZ ');
//=> 'FOO BAR BAZ'

// Condense all whitespace (keep newlines)
selectiveWhitespace('FOO\n   BAR\n   BAZ\n ', {keep: '\n'});
//=> 'FOO\n BAR\n BAZ\n'

// Condense all whitespace (keep tabs)
selectiveWhitespace('\tFOO     \tBAR      \tBAZ', {keep: '\t'});
//=> '\tFOO \tBAR \tBAZ'

// Condense all whitespace (keep tabs and newlines)
selectiveWhitespace('\n\tFOO     \n\tBAR      \n\tBAZ', {keep: '\t,\n'});
//=> '\n\tFOO \n\tBAR \n\tBAZ'

// Strip all whitespace characters
selectiveWhitespace('\t\nFOO     \t\nBAR      \t\nBAZ', {stripAll:true});
//=> '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

Keywords

FAQs

Last updated on 03 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc