Type Challenges Judge

KebabCase

提出詳細

type Split<S extends string> = S extends `${infer S1}${infer R}` ? S1 | Split<R> : S type Alpha = Split<"ABCDEFGHIJKLMNOPQRSTUVWXYZ"> type KebabCase<S, R extends string = ""> = S extends "-" ? "-" : S extends `${infer S1}${infer Rest}` ? S1 extends Uppercase<S1> ? S1 extends Alpha ? KebabCase<Rest, `${R}-${Lowercase<S1>}`> : KebabCase<Rest, `${R}${S1}`> : KebabCase<Rest, `${R}${S1}`> : R extends `-${infer Rest}` ? Rest : R
提出日時2024-10-05 08:08:59
問題KebabCase
ユーザーookkoouu
ステータス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<'😎'>, '😎'>>, ]