insertAfter

Inserts the insertText after the specified target in the input string.

Usage Scenarios

  • Text Manipulation: In text editors, insert text after a specific position or keyword.
  • Data Generation: Generate dynamic text by inserting content at specific locations.

Example

import { insertAfter } from 'funtool';

insertAfter('hello', 'X', 1); // ✅ 'heXllo'
insertAfter('foo-bar', '_', '-'); // ✅ 'foo-_bar'
insertAfter('abc', '_', 'z'); // ❌ 'abc'

Signature

function insertAfter(input: string, insertText: string, target: string | number): string

Parameters

  • input ( string ): The input string.
  • insertText ( string ): The text to insert.
  • target ( string | number ): The index or substring after which to insert the text.

Returns

  • ( string ): A new string with the text inserted.