Tweakr
    Preparing search index...

    Function truncate

    • Truncates a string to a maximum length and appends a suffix if needed.

      Parameters

      • str: string

        The string to truncate.

      • max: number

        The maximum length of the resulting string including the suffix.

      • suffix: string = "…"

        The string to append if truncation occurs (default: "…").

      Returns string

      The truncated string with suffix if truncated.

      1.1.0

      truncate("Hello World", 5); // "He…"
      truncate("Hello", 10); // "Hello"
      truncate("Hello", 2); // "…"