UNPKG

@cuppachino/type-space

Version:

A collection of type utilities for TypeScript.

15 lines (14 loc) 392 B
/** * Splits a string literal into a tuple of characters, separated by the given * delimiter. * * @example * ``` * Split<'a-b-c'> // ['a', '-', 'b', '-', 'c'] * ``` * @example * ``` * Split<'a-b-c', '-'> // ['a', 'b', 'c'] * ``` */ export type Split<S extends string, D extends string = ''> = S extends `${infer L}${D}${infer R}` ? R extends '' ? [L] : [L, ...Split<R, D>] : [S];