frontend/.pnpm-store/v3/files/79/d3fa2005b2773cfab704710d089794d15401ecb3c13291601f3e35e47bf188d905309a3db2750055c8346c6703c14708f8d125a5d07dca6a62aaf250534eb9

30 lines
689 B
Plaintext

/**
Represents an array of strings split using a given character or character set.
Use-case: Defining the return type of a method like `String.prototype.split`.
@example
```
import type {Split} from 'type-fest';
declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
type Item = 'foo' | 'bar' | 'baz' | 'waldo';
const items = 'foo,bar,baz,waldo';
let array: Item[];
array = split(items, ',');
```
@category String
@category Template literal
*/
export type Split<
S extends string,
Delimiter extends string,
> = S extends `${infer Head}${Delimiter}${infer Tail}`
? [Head, ...Split<Tail, Delimiter>]
: S extends Delimiter
? []
: [S];