KebabCase
提出詳細
type KebabCase<T extends string, U extends string = ''> = T extends `${infer H}${infer R}` ? H extends Lowercase<H> ? KebabCase<R, `${U}${H}`> : U extends '' ? KebabCase<R, `${U}${Lowercase<H>}`> : KebabCase<R, `${U}-${Lowercase<H>}`> : U
提出日時 | 2023-05-08 09:49:40 |
---|---|
問題 | KebabCase |
ユーザー | Dowanna |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<KebabCase<'FooBarBaz'>, 'foo-bar-baz'>>, Expect<Equal<KebabCase<'fooBarBaz'>, 'foo-bar-baz'>>, Expect<Equal<KebabCase<'foo-bar'>, 'foo-bar'>>, Expect<Equal<KebabCase<'foo_bar'>, 'foo_bar'>>, Expect<Equal<KebabCase<'Foo-Bar'>, 'foo--bar'>>, Expect<Equal<KebabCase<'ABC'>, 'a-b-c'>>, Expect<Equal<KebabCase<'-'>, '-'>>, Expect<Equal<KebabCase<''>, ''>>, Expect<Equal<KebabCase<'😎'>, '😎'>>, ]