Go Back

Describe

for-bar-baz -> forBarBaz

Test Cases

code snippetCopytypescript
import { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<CamelCase<'foo-bar-baz'>, 'fooBarBaz'>>, Expect<Equal<CamelCase<'foo-Bar-Baz'>, 'foo-Bar-Baz'>>, Expect<Equal<CamelCase<'foo-Bar-baz'>, 'foo-BarBaz'>>, Expect<Equal<CamelCase<'foo-bar'>, 'fooBar'>>, Expect<Equal<CamelCase<'foo_bar'>, 'foo_bar'>>, Expect<Equal<CamelCase<'foo--bar----baz'>, 'foo-Bar---Baz'>>, Expect<Equal<CamelCase<'a-b-c'>, 'aBC'>>, Expect<Equal<CamelCase<'a-b-c-'>, 'aBC-'>>, Expect<Equal<CamelCase<'ABC'>, 'ABC'>>, Expect<Equal<CamelCase<'-'>, '-'>>, Expect<Equal<CamelCase<''>, ''>>, Expect<Equal<CamelCase<'😎'>, '😎'>>, ]

Solution

code snippetCopytypescript
type CamelCase<S> = S extends `${infer F}-${infer E}` ? E extends `${Capitalize<E>}` ? `${F}-${CamelCase<E>}` : `${F}${CamelCase<Capitalize<E>>}` : S