Capitalize Words
提出詳細
type IsAlpha<S extends string> = Uppercase<S> extends Lowercase<S> ? false // if uppercase and lowercase version is same, it is not an alphabet. : true type CapitalizeWords<S extends string, InWord=false, Acc extends string=""> = S extends `${infer S1}${infer S2}` ? InWord extends true ? IsAlpha<S1> extends true ? CapitalizeWords<S2,true,`${Acc}${S1}`> : CapitalizeWords<S2,false,`${Acc}${S1}`> : IsAlpha<S1> extends true ? CapitalizeWords<S2,true,`${Acc}${Uppercase<S1>}`> : CapitalizeWords<S2,false,`${Acc}${S1}`> : Acc
提出日時 | 2023-09-20 03:06:21 |
---|---|
問題 | Capitalize Words |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<CapitalizeWords<'foobar'>, 'Foobar'>>, Expect<Equal<CapitalizeWords<'FOOBAR'>, 'FOOBAR'>>, Expect<Equal<CapitalizeWords<'foo bar'>, 'Foo Bar'>>, Expect<Equal<CapitalizeWords<'foo bar hello world'>, 'Foo Bar Hello World'>>, Expect<Equal<CapitalizeWords<'foo bar.hello,world'>, 'Foo Bar.Hello,World'>>, Expect<Equal<CapitalizeWords<''>, ''>>, ]