-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathindex.d.ts
51 lines (39 loc) · 1.13 KB
/
index.d.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Source: https://github.com/sindresorhus/type-fest/blob/main/source/internal.d.ts#L49
type Newline =
| '\u{A}' // '\n'
| '\u{D}' // '\r'
;
// Source: https://github.com/sindresorhus/type-fest/blob/main/source/trim.d.ts
type TrimStart<S extends string> = S extends `${Newline}${infer R}` ? TrimStart<R> : S;
type TrimEnd<S extends string> = S extends `${infer R}${Newline}` ? TrimEnd<R> : S;
export type Trim<S extends string> = TrimStart<TrimEnd<S>>;
/**
Trim from the start and end of a string.
@example
```js
import {trimNewlines} from 'trim-newlines';
trimNewlines('\n🦄\n🦄\r\n');
//=> '🦄\n🦄'
```
*/
export function trimNewlines<S extends string>(string: S): Trim<S>;
/**
Trim from the start of a string.
@example
```js
import {trimNewlinesStart} from 'trim-newlines';
trimNewlinesStart('\n🦄\r\n');
//=> '🦄\r\n'
```
*/
export function trimNewlinesStart<S extends string>(string: S): TrimStart<S>;
/**
Trim from the end of a string.
@example
```js
import {trimNewlinesEnd} from 'trim-newlines';
trimNewlinesEnd('\n🦄\r\n');
//=> '\n🦄'
```
*/
export function trimNewlinesEnd<S extends string>(string: S): TrimEnd<S>;