insertBefore

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

Usage Scenarios

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

Example

import { insertBefore } from 'funtool';

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

Signature

function insertBefore(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 before which to insert the text.

Returns

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