removeAfter

Removes the part of the input string after the specified target.

Usage Scenarios

  • Text Cleaning: In text processing, remove unnecessary content after a specific position or keyword.
  • Data Extraction: Extract a part of the string before a certain point.

Example

import { removeAfter } from 'funtool/string'

removeAfter('foo-bar', '-') // ✅ 'foo-'
removeAfter('hello', 3) // ✅ 'hel'

Signature

function removeAfter(input: string, target: string | number): string

Parameters

  • input ( string ): The input string.
  • target ( string | number ): The index or substring after which to remove the content.

Returns

  • ( string ): A new string with the content after the target removed.