I am trying to convert both the case of a sentence and the case of a camel into a spinal register.
I can change the case of a camel by adding a space in front of each capital letter, but when I apply it to sentences with capital letters after spaces, I get an extra spacing.
Here is my function:
function spinalCase(str) {
var noCamel = str.replace(/([A-Z])/g, ' $1');
var newStr = noCamel.replace(/\s|_/g, "-");
return newStr.toLowerCase();
}
spinalCase("makeThisSpinal");
spinalCase("Make This Spinal");
source
share