-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathtrim.d.ts
More file actions
29 lines (22 loc) · 593 Bytes
/
trim.d.ts
File metadata and controls
29 lines (22 loc) · 593 Bytes
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
import type {Whitespace} from './internal/index.d.ts';
/**
Remove spaces from the left side.
*/
type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}` ? TrimLeft<R> : V;
/**
Remove spaces from the right side.
*/
type TrimRight<V extends string> = V extends `${infer R}${Whitespace}` ? TrimRight<R> : V;
/**
Remove leading and trailing spaces from a string.
@example
```
import type {Trim} from 'type-fest';
type Example = Trim<' foo '>;
//=> 'foo'
```
@category String
@category Template literal
*/
export type Trim<V extends string> = TrimLeft<TrimRight<V>>;
export {};