utils/text/toTitleCase.js

/**
 * Changes the first letter of each word to upper case
 *
 * @module utils/text/toTitleCase
 * @param {string} string - text string to convert to title case (e.g. `this is a string``)
 * @return {string} - string converted to title case (e.g. `This Is A String`)
 */
const toTitleCase = string => string
	.split( ' ' )
	.map( word => word.charAt( 0 ).toUpperCase() + word.slice( 1 ) )
	.join( ' ' );

export default toTitleCase;