I'd like to write a JavaScript function to slugify a string, with one more requirement: handle Camel Case. For example, thisIsCamelCase
would become this-is-camel-case
.
How do I modify a function like this to do so?
EDIT
Added full, answered example.
You just need to add one line of code to what you posted
This brings the remaining code to be
Edit :: I also deleted the useless new RegExp logic too. Edit :: Added 'g' to find all caps, not just the first one.