The same name is written in different styles in different places: backgroundColor in JavaScript, background-color in CSS and URLs, background_color in a database or a JSON API. Code that moves data between them converts names all the time, and the hard part is not the joining but the splitting: where do the words of XMLHttpRequest or html5Parser begin?
Write four functions in case.js: toWords, which finds the words, and toCamelCase, toSnakeCase and toKebabCase, which join them.
toWords returns the words of text in lower case. Any character that is not an ASCII letter or digit separates words (spaces, _, -, ., /…). Separators at the edges or in runs produce no empty words.
A lower-case letter or a digit followed by a capital starts a new word: "fooBar" gives foo, bar; "html5Parser" gives html5, parser.
In a run of capitals followed by a lower-case letter, the last capital starts a new word: "XMLHttpRequest" gives xml, http, request. A run of capitals with no lower-case letter after it is one word: "userID" gives user, id.
Digits stay with the letters before them ("version2" is one word), and a capital followed by lower-case letters is not split ("Hello" is one word).
toCamelCase writes the first word in lower case and every later word with a capital first letter, with nothing between them.
toSnakeCase joins the words with "_", and toKebabCase with "-".
All four accept any style as input, including their own, SCREAMING_SNAKE_CASE and PascalCase, and return an empty result for an empty string.
When every word starts with a letter and has at least two characters, converting through another style gives the same result as converting directly. Other names can lose a word boundary in camelCase, and that is expected: toCamelCase("foo_2") is "foo2", which reads back as one word, and toCamelCase("a_b_c") is "aBC", which reads back as a, bc.