camelCaseToTitleCase() Helper Method
The camelCaseToTitleCase() Helper Method module provides a helper function that converts a passed string formatted in camelCase and returns that string formatted in Title Case.
Import
To import the camelCaseToTitleCase() Helper Method:
javascript
import { camelCaseToTitleCase } from '@obewds/vueventus'
Argument
Returns: String
Args | Type | Status | Description |
---|---|---|---|
string | String | Required | A camel case string to be converted to title case |
Use Examples
javascript
console.log( camelCaseToTitleCase('testCamelCase') )
// returns (string): 'Test Camel Case'
console.log( camelCaseToTitleCase('testCamelCase22') )
// returns (string): 'Test Camel Case22'
console.log( camelCaseToTitleCase('PascalCaseString') )
// returns (string): 'Pascal Case String'
console.log( camelCaseToTitleCase('spaced camelCase') )
// returns (string): 'Spaced Camel Case'
Module Code
ts
// ./src/helpers/camelCaseToTitleCase.ts
export default function( string: string ): string {
let temp = string.replace( /([A-Z])/g, " $1").replace(/\s+/g, " ")
let tempArray = temp.split(' ')
let casedArray = tempArray.map(str => {
return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase()
})
return (casedArray.join(' ')).trim()
}