blob: dab1dc33417e12f538a51542ac0d0e4ef1b43862 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/**
* Converts a string to title case.
* Title case capitalizes the first character of each word in the string,
* and sets the remaining characters to lowercase.
*
* @param {string} str - The input string to be converted to title case.
* @returns {string} - The string in title case.
*/
const toTitleCase = (str) => {
return str.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
})
}
export default toTitleCase
|