diff --git a/README.md b/README.md index 1e1fe010a..c947a258d 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,11 @@ var capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperCas ### Capitalize first letter Use `slice(0,1)` and `toUpperCase()` to capitalize first letter, `slice(1)` to get the rest of the string. +Omit the `lowerRest` parameter to keep the rest of the string intact, or set it to `true` to convert to lower case. ```js -const capitalize = str => str.slice(0, 1).toUpperCase() + str.slice(1); +const capitalize = (str, lowerRest = false) => + str.slice(0, 1).toUpperCase() + (lowerRest? str.slice(1).toLowerCase() : str.slice(1)); ``` ### Count occurrences of a value in array diff --git a/snippets/capitalize-first-letter.md b/snippets/capitalize-first-letter.md index 773cc1343..f6b933998 100644 --- a/snippets/capitalize-first-letter.md +++ b/snippets/capitalize-first-letter.md @@ -1,7 +1,9 @@ ### Capitalize first letter Use `slice(0,1)` and `toUpperCase()` to capitalize first letter, `slice(1)` to get the rest of the string. +Omit the `lowerRest` parameter to keep the rest of the string intact, or set it to `true` to convert to lower case. ```js -const capitalize = str => str.slice(0, 1).toUpperCase() + str.slice(1); +const capitalize = (str, lowerRest = false) => + str.slice(0, 1).toUpperCase() + (lowerRest? str.slice(1).toLowerCase() : str.slice(1)); ```