Member Junction
    Preparing search index...

    Function stripTrailingChars

    • Removes trailing characters from a string if they match the specified substring.

      Parameters

      • s: string

        The input string from which trailing characters should be stripped.

      • charsToStrip: string

        The substring to remove if it appears at the end of the input string.

      • skipIfExactMatch: boolean

        If true, does not strip the trailing characters when the string is exactly equal to charsToStrip.

      Returns string

      The modified string with trailing characters stripped, or the original string if no match is found.

      stripTrailingChars("example.txt", ".txt", false); // "example"
      stripTrailingChars("example.txt", ".txt", true); // "example"
      stripTrailingChars("file.txt", "txt", false); // "file.txt" (no match)
      stripTrailingChars(".txt", ".txt", true); // ".txt" (exact match, not stripped)