Type Challenges Judge

KebabCase

提出詳細

type Alphabet = "A" | "B" | "C" type KebabCase<S extends string, Dash extends boolean = false> = S extends `${infer A}${infer B}` ? Dash extends true ? `${A extends Alphabet ? "-" : ""}${Lowercase<A>}${KebabCase<B, true>}` :`${Lowercase<A>}${KebabCase<B, true>}`: S;
提出日時2022-06-27 23:29:28
問題KebabCase
ユーザーwaki285
ステータス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<'😎'>, '😎'>>, ]