Case conversion turns a string from one naming style into another — camelCase, PascalCase, snake_case, or kebab-case — by first splitting it into its underlying words, then re-casing and re-joining them for the target style. Build caseConverters, an object with four methods, where each one accepts a string in any style and returns it in its own. The point of the exercise is the splitting step: your tokenizer has to find word boundaries that hide in separators (foo_bar), in capitalization (fooBar), and in acronym runs (XMLHttpRequest). Do not call lodash — write the tokenizer and the four formatters yourself.
// caseConverters is an object with four methods; each takes a string
// in ANY style and returns it re-cased for the target style.
caseConverters.camelCase(str); // first word lower, rest Capitalized -> "fooBar"
caseConverters.pascalCase(str); // every word Capitalized -> "FooBar"
caseConverters.snakeCase(str); // lowercase words joined with "_" -> "foo_bar"
caseConverters.kebabCase(str); // lowercase words joined with "-" -> "foo-bar"
// Any input style converts to any target style.
caseConverters.camelCase('foo_bar'); // 'fooBar' (from snake_case)
caseConverters.camelCase('foo-bar'); // 'fooBar' (from kebab-case)
caseConverters.camelCase('Foo Bar'); // 'fooBar' (from spaced words)
caseConverters.snakeCase('fooBar'); // 'foo_bar' (from camelCase)
caseConverters.kebabCase('FooBar'); // 'foo-bar' (from PascalCase)
caseConverters.pascalCase('foo bar'); // 'FooBar'
// Acronym runs, digits, and edge cases.
caseConverters.camelCase('XMLHttpRequest'); // 'xmlHttpRequest'
caseConverters.kebabCase('XMLHttpRequest'); // 'xml-http-request'
caseConverters.snakeCase('foo2Bar'); // 'foo2_bar'
caseConverters.snakeCase('foo_bar'); // 'foo_bar' (idempotent)
caseConverters.camelCase(''); // ''
snake_case, kebab-case, camelCase, PascalCase, or a mix. Route them all through one shared tokenizer, then format.fooBar is two words even though there is no separator. Insert a boundary there before you split.XMLHttpRequest is three words — xml, http, request — matching lodash. The last capital of a run belongs to the next word, so do not split every capital.foo2Bar as foo2 and bar, giving foo2_bar. There is no boundary between a letter and a following digit — pick this policy and test it.--foo--bar--) must not leave stray hyphens or underscores, and an empty or separator-only string returns ''.camelCase / snakeCase / kebabCase and add pascalCase from scratch.