-
-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathstring-slice.d.ts
More file actions
39 lines (30 loc) · 780 Bytes
/
string-slice.d.ts
File metadata and controls
39 lines (30 loc) · 780 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
30
31
32
33
34
35
36
37
38
39
import type {Join} from './join.d.ts';
import type {ArraySlice} from './array-slice.d.ts';
import type {StringToArray} from './internal/index.d.ts';
/**
Returns a string slice of a given range, just like `String#slice()`.
@see {ArraySlice}
@example
```
import type {StringSlice} from 'type-fest';
type A = StringSlice<'abcde', 0, 2>;
//=> 'ab'
type B = StringSlice<'abcde', 1>;
//=> 'bcde'
type C = StringSlice<'abcde', 0, -1>;
//=> 'abcd'
type D = StringSlice<'abcde', -2, -1>;
//=> 'd'
```
@category String
*/
export type StringSlice<
S extends string,
Start extends number = never,
End extends number = never,
> = string extends S
? string
: ArraySlice<StringToArray<S>, Start, End> extends infer R extends readonly string[]
? Join<R, ''>
: never;
export {};