KebabCase
提出詳細
type IsAlphabet<S extends string> = S extends Uppercase<S> ? S extends Lowercase<S> ? false : true : true; type KebabCaseInner<S extends string> = S extends `${infer First}${infer Rest}` ? IsAlphabet<First> extends true ? First extends Uppercase<First> ? `-${Lowercase<First>}${KebabCaseInner<Rest>}` : `${First}${KebabCaseInner<Rest>}` : `${First}${KebabCaseInner<Rest>}` : ''; type KebabCase<S extends String> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${KebabCaseInner<Rest>}` : '';
提出日時 | 2023-08-11 12:46:47 |
---|---|
問題 | 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<'😎'>, '😎'>>, ]