I have this code where I want to change a camel case sentence to a human readable one.
It works nicely apart from when there are () - see example below. Can anyone advise on how to fix this so it would be Amazing (Stuff)
const camelToHumanReadable = (camelCase) => {
const result = camelCase
.replace(/([A-Z]+)/g, ' $1')
.replace(/([A-Z][a-z])/g, ' $1')
.replace(/ +(?= )/g, '')
.replace(/(- )/, '-')
.trim();
return result.charAt(0).toUpperCase() + result.slice(1);
};
console.log(camelToHumanReadable('ItIsBeautiful')) // correct
console.log(camelToHumanReadable('Test-DashHere')) // correct
console.log(camelToHumanReadable('IAmFromTheUSA')) // correct
console.log(camelToHumanReadable('Test1')) // this should be Test 1
console.log(camelToHumanReadable('Amazing(Stuff)')) // this should be Amazing (Stuff)