-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path106-trimleft.ts
32 lines (29 loc) · 936 Bytes
/
106-trimleft.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* 106 - Trim Left
*
* Implement `TrimLeft<T>` which takes an exact string type and returns a new string with the whitespace beginning removed.
*
* For example
*
* ```ts
* type trimed = TrimLeft<' Hello World '> // expected to be 'Hello World '
* ```
*/
/* _____________ Your Code Here _____________ */
type TrimLeft<S extends string> = S extends `${infer A}${infer B}`
? A extends (' ' | '\n' | '\t')
? TrimLeft<B>
: S
: S;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type R = TrimLeft<' \n\t foo bar '>;
type cases = [
Expect<Equal<TrimLeft<'str'>, 'str'>>,
Expect<Equal<TrimLeft<' str'>, 'str'>>,
Expect<Equal<TrimLeft<' str'>, 'str'>>,
Expect<Equal<TrimLeft<' str '>, 'str '>>,
Expect<Equal<TrimLeft<' \n\t foo bar '>, 'foo bar '>>,
Expect<Equal<TrimLeft<''>, ''>>,
Expect<Equal<TrimLeft<' \n\t'>, ''>>,
]