Nice walkthrough, thanks for writing it up. I had to work out the opposite yesterday for nearly identical reasons. I wanted to get the key from dataset and make it kebab-cased.
I didn't consider adding a delimiter parameter or doing the reverse as you have. So I've tweaked my code after reading this.
const camelCaseToDelimitedString = (string, delimiter = '-') =>
const delimitedStringToCamelCase = (string, delimiter = '-') =>
string.replace(new RegExp(delimiter + '([a-z])', 'g'), (m, c) => c.toUpperCase());
console.log(delimitedStringToCamelCase('hello, world', ', '));
Credit where credit is due, I based my conversion off of this gist: gist.github.com/nblackburn/875e6ff...
Yeah RegExp is a great approach. I omitted that. I think I should add it. Thanks for sharing this.
No problem, Regex is so hard to read, go with whatever works for you. I was lucky enough to find a fairly decently tested Regex match and tweak it to suit my needs.
Thanks again, your post encouraged me to improve my scripts.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.