Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

selective-whitespace

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selective-whitespace

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

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-22.15%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 03 May 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc