Type Challenges Judge

KebabCase

提出詳細

type KebabCaseInner<S extends string> = S extends `${infer S1}${infer S2}` ? S1 extends Lowercase<S1> // 大文字でない場合 ? `${S1}${KebabCaseInner<S2>}` // 大文字の場合 : `-${Lowercase<S1>}${KebabCaseInner<S2>}` : ''; type KebabCase<S extends String> = S extends `${infer S1}${infer S2}` ? `${Lowercase<S1>}${KebabCaseInner<S2>}` : S;
提出日時2023-08-11 12:59:15
問題KebabCase
ユーザーtekihei2317
ステータス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<'😎'>, '😎'>>, ]