Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
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@1.0.2/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