Type alias ReplaceLast<Value, Target, Replacement, Global>

ReplaceLast

Type Parameters

  • Value extends string

    The value to replace

  • Target extends string

    The target to replace

  • Replacement extends string = ""

    [=''] - The replacement string

  • Global extends boolean = true

    [true] - Replace all occurrences

Description

Replace the last occurrence of a string with another string

Returns

The replaced string

Example

type Value = 'foofoofoo';
type Target = 'foo';
type Replacement = 'bar';
type Result = ReplaceLast<Value, Target, Replacement>; // 'barbarbar'

Example

type Value = 'foofoofoo';
type Target = 'foo';
type Replacement = 'bar';
type Result = ReplaceLast<Value, Target, Replacement, false>; // 'foofoobar'