Skip to main content
Module

x/rimbu/typical/mod.ts>Str.ReplaceFirst

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

Replaces, in the given string, the first match with Sub with the given Repl. Returns never if there was no match.

Examples

Example 1

ReplaceFirst<'abcba', 'b', '_'> => 'a_cba'
ReplaceFirst<'abcba', 'b' | 'c', '_'> => 'a_cba'

Type Parameters

S extends string
Sub extends string & NonEmptyString<Sub>
Repl extends string
definition: S extends "" ? never : S extends Append<Sub, infer Rest> ? Append<Repl, Rest> : S extends Append<infer Start, infer Rest> ? Append<Start, ReplaceFirst<Rest, Sub, Repl>> : never