I am using the following toKebabCase() function:
function toKebabCase(key) {
return key.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map((word) => word.toLowerCase())
.join('-');
}
console.log(toKebabCase('namespaceGray100Light'));
It doesn't behave exactly as I would like, though. Right now, if I pass 'namespaceGray100Light' as an argument, the function returns 'namespace-gray100-light'. How would this regex need to be modified in order to return 'namespace-gray-100-light'.
To clarify, I am looking to introduce a hyphen when a digit follows an alpha character and not just when a digit precedes an alpha character.
TY.