Skip to main content
Module

x/rimbu/typical/str.ts>StartsWith

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
type alias StartsWith
import { type StartsWith } from "https://deno.land/x/rimbu@0.13.1/typical/str.ts";

If the given string does not start with the given Start type, returns false. Otherwise, returns a tuple containing the matched start and the rest.

Examples

Example 1

StartsWith<'abcd', 'ab'> => ['ab', 'cd']
StartsWith<'abcd', 'd'> => false
StartsWith<'abcd', 'ab' | 'bc'> => ['ab', 'cd']
StartsWith<'abcd', 'ab' | 'a'> => ['ab', 'cd'] | ['a', 'bcd']

Type Parameters

S extends string
Start extends string & NonEmptyString<Start>
definition: S extends Append<Start, infer Rest> ? S extends Append<infer StartInstance, Rest> ? [StartInstance, Rest] : false : false