Created
January 4, 2021 09:25
-
-
Save niksmac/9c3e1849515877e5766a784173e2f45c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function titleCase(str) { | |
let splitStr = str.toLowerCase().split(' ') | |
for (let i = 0; i < splitStr.length; i++) { | |
splitStr[i] = | |
splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1) | |
} | |
return splitStr | |
.join(' ') | |
.replace(/[\u0300-\u036f]/g, '') | |
.replace(/\s+/g, '') | |
.replace(/[^\w-]+/g, '') | |
.replace(/--+/g, '') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment