KebabCase
提出詳細
type UtoL = { 'A': 'a' 'B': 'b' 'C': 'c' 'D': 'd' 'E': 'e' 'F': 'f' 'G': 'g' 'H': 'h' 'I': 'i' 'J': 'j' 'K': 'k' 'L': 'l' 'M': 'm' 'N': 'n' 'O': 'o' 'P': 'p' 'Q': 'q' 'R': 'r' 'S': 's' 'T': 't' 'U': 'u' 'V': 'v' 'W': 'w' 'X': 'x' 'Y': 'y' 'Z': 'z' } type Kebab<S, Outer> = S extends keyof UtoL ? Outer extends true ? UtoL[S] : `-${UtoL[S]}` : S type KebabCase<S, Outer = true> = S extends `${infer First}${infer Rest}` ? `${Kebab<First, Outer>}${KebabCase<Rest, false>}` : S
提出日時 | 2023-09-11 06:48:05 |
---|---|
問題 | KebabCase |
ユーザー | snaka |
ステータス | 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<'😎'>, '😎'>>, ]