Add compactWhitespace snippet

This commit is contained in:
Angelos Chalaris
2018-12-12 19:11:33 +02:00
parent d439420f39
commit 4f661ee158
4 changed files with 1534 additions and 1500 deletions

View File

@ -0,0 +1,14 @@
### compactWhitespace
Returns a string with whitespaces compacted.
Use `String.prototype.replace()` with a regular expression to replace all occurences of 2 or more whitespace characters with a single space.
```js
const compactWhitespace = str => str.replace(/\s{2,}/g,' ');
```
```js
compactWhitespace('Lorem Ipsum'); // 'Lorem Ipsum'
compactWhitespace('Lorem \n Ipsum'); // 'Lorem Ipsum'
```