Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/rimbu/typical/str.ts>EndsWith

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

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

Examples

Example 1

EndsWith<'abcd', 'cd'> => ['ab', 'cd']
EndsWith<'abcd', 'a'> => false
EndsWith<'abcd', 'cd' | 'de'> => ['ab', 'cd']
EndsWith<'abcd', 'cd' | 'd'> => ['ab', 'cd'] | ['abc', 'd']

Type Parameters

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