From c2356aa879f5e6fe97bb58d6917e26e58bef8b82 Mon Sep 17 00:00:00 2001 From: King Date: Thu, 21 Dec 2017 08:09:40 -0500 Subject: [PATCH] ran npm run builder --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 17fa7f335..963d7ef61 100644 --- a/README.md +++ b/README.md @@ -130,9 +130,9 @@ * [`fromCamelCase`](#fromcamelcase) * [`reverseString`](#reversestring) * [`sortCharactersInString`](#sortcharactersinstring) -* [`stringToArrayOfWords`](#stringtoarrayofwords) * [`toCamelCase`](#tocamelcase) * [`truncateString`](#truncatestring) +* [`words`](#words) ### Utility * [`coalesce`](#coalesce) @@ -1812,9 +1812,6 @@ const sortCharactersInString = str => [⬆ back to top](#table-of-contents) -undefined -[⬆ back to top](#table-of-contents) - ### toCamelCase Converts a string to camelcase. @@ -1845,6 +1842,21 @@ const truncateString = (str, num) => // truncateString('boomerang', 7) -> 'boom...' ``` +[⬆ back to top](#table-of-contents) + +### words + +Converts a given string into an array of words. + +Use `String.split()` with a supplied pattern (defaults to non alpha as a regex) to convert to an array of strings. Use `Array.filter()` to remove any empty strings. +Omit the second argument to use the default regex. + +```js +const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean); +// words("I love javaScript!!") -> ["I", "love", "javaScript"] +// words("python, javaScript & coffee") -> ["python", "javaScript", "coffee"] +``` + [⬆ back to top](#table-of-contents) ## Utility