diff --git a/README.md b/README.md index e1fe52de4..d3d13e68e 100644 --- a/README.md +++ b/README.md @@ -406,6 +406,7 @@ _30s.average(1, 2, 3); * [`byteSize`](#bytesize) * [`capitalize`](#capitalize) * [`capitalizeEveryWord`](#capitalizeeveryword) +* [`compactWhitespace`](#compactwhitespace) * [`CSVToArray`](#csvtoarray) * [`CSVToJSON`](#csvtojson-) * [`decapitalize`](#decapitalize) @@ -664,7 +665,6 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr Examples ```js - const sum = pipeAsyncFunctions( x => x + 1, x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)), @@ -2313,7 +2313,6 @@ Use `Array.prototype.filter()` to find array elements that return truthy values The `func` is invoked with three arguments (`value, index, array`). ```js - const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { @@ -7728,6 +7727,28 @@ capitalizeEveryWord('hello world!'); // 'Hello World!'
[⬆ Back to top](#contents) +### 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, ' '); +``` + +
+Examples + +```js +compactWhitespace('Lorem Ipsum'); // 'Lorem Ipsum' +compactWhitespace('Lorem \n Ipsum'); // 'Lorem Ipsum' +``` + +
+ +
[⬆ Back to top](#contents) + ### CSVToArray Converts a comma-separated values (CSV) string to a 2D array. diff --git a/docs/about.html b/docs/about.html index e7506e1bf..4cd8c918e 100644 --- a/docs/about.html +++ b/docs/about.html @@ -415,6 +415,7 @@