Trim
提出詳細
type Trimable = " " | "\n" | "\t" type TrimLeft<S extends string> = S extends `${Trimable}${infer Tail}` ? TrimLeft<Tail>:S; type TrimRight<S extends string> = S extends `${infer Tail}${Trimable}` ? TrimRight<Tail>:S; type Trim<S extends string> = TrimLeft<TrimRight<S>>;
提出日時 | 2022-06-27 12:01:34 |
---|---|
問題 | Trim |
ユーザー | waki285 |
ステータス | 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 '>, ''>>, ]