@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function truncate

    • Truncates str to maxLength characters, appending suffix when truncation occurs. The total length of the returned string never exceeds maxLength.

      Parameters

      • str: string

        The input string.

      • maxLength: number

        Maximum allowed length of the result.

      • suffix: string = "..."

        String appended when truncating. Defaults to "...".

      Returns string

      truncate("Hello, World!", 8)        // => "Hello..."
      truncate("Hello, World!", 8, "…") // => "Hello,…"
      truncate("Hi", 10) // => "Hi"