Type alias Split<Value, Separator>

Split<Value, Separator>: Value extends string
    ? Value extends `${infer First}${Separator}${infer Rest}`
        ? [First, ...Split<Rest, Separator>]
        : Value extends ""
            ? []
            : [Value]
    : Value

Split

Type Parameters

  • Value extends string

    The string to split

  • Separator extends string = " "

    The separator to split by

Desc

Split a string into an array of strings by a separator

Returns

An array of strings

Example

type Value = 'i go to school by bus';
type Result = Split<Value>; // ['i', 'go', 'to', 'school', 'by', 'bus']

Example

type Value = 'i.go.to.school.by.bus';
type Separator = '.';
type Result = Split<Value, Separator>; // ['i', 'go', 'to', 'school', 'by', 'bus']