UNPKG

554 BTypeScriptView Raw
1import type {Whitespace} from './internal';
2
3/**
4Remove spaces from the left side.
5*/
6type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}` ? TrimLeft<R> : V;
7
8/**
9Remove spaces from the right side.
10*/
11type TrimRight<V extends string> = V extends `${infer R}${Whitespace}` ? TrimRight<R> : V;
12
13/**
14Remove leading and trailing spaces from a string.
15
16@example
17```
18import type {Trim} from 'type-fest';
19
20Trim<' foo '>
21//=> 'foo'
22```
23
24@category String
25@category Template literal
26*/
27export type Trim<V extends string> = TrimLeft<TrimRight<V>>;