Skip to content

Instantly share code, notes, and snippets.

@Luisgustavom1
Created July 31, 2022 23:04
Show Gist options
  • Save Luisgustavom1/251365d5c9cf54da097c8db33e85d0e2 to your computer and use it in GitHub Desktop.
Save Luisgustavom1/251365d5c9cf54da097c8db33e85d0e2 to your computer and use it in GitHub Desktop.
Type-challenges - 612 Medium kebabcase
// 00612 - Medium kebabcase
type KebabCase<T extends string> =
T extends `${infer F}${infer R}`
? R extends Uncapitalize<R>
? `${Uncapitalize<F>}${KebabCase<R>}`
: `${Uncapitalize<F>}-${KebabCase<R>}`
: T
export type KebabCaseResult = KebabCase<'FooBarBaz'> //foo-bar-baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment