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<'😎'>, '😎'>>, ]