This commit is contained in:
Angelos Chalaris
2017-12-12 15:42:03 +02:00
parent c074a196e6
commit d7856f0b40
2 changed files with 6 additions and 2 deletions

View File

@ -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));
```