Skip to content

Instantly share code, notes, and snippets.

@niksmac
Created January 4, 2021 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksmac/9c3e1849515877e5766a784173e2f45c to your computer and use it in GitHub Desktop.
Save niksmac/9c3e1849515877e5766a784173e2f45c to your computer and use it in GitHub Desktop.
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