Trim
提出詳細
type TrimTarget = " " | "\n" | "\t" type Trim<T extends string> = T extends `${TrimTarget}${infer Tail}` ? Trim<Tail> : T extends `${infer Head}${TrimTarget}` ? Trim<Head> : T
提出日時 | 2023-05-03 04:53:13 |
---|---|
問題 | Trim |
ユーザー | Dowanna |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Trim<'str'>, 'str'>>, Expect<Equal<Trim<' str'>, 'str'>>, Expect<Equal<Trim<' str'>, 'str'>>, Expect<Equal<Trim<'str '>, 'str'>>, Expect<Equal<Trim<' str '>, 'str'>>, Expect<Equal<Trim<' \n\t foo bar \t'>, 'foo bar'>>, Expect<Equal<Trim<''>, ''>>, Expect<Equal<Trim<' \n\t '>, ''>>, ]