@nevware21/ts-utils
    Preparing search index...

    Function strTruncate

    • Truncate the provided value to the requested maximum length and optionally append a suffix.

      When the value is already within maxLength, the original string is returned unchanged. When a suffix is supplied, the result length remains capped at maxLength, so the original value is shortened further as needed to make room for the suffix.

      A surrogate pair (eg. an emoji) is not split (since 0.20.0), so the result can be one shorter than maxLength when the value (or suffix) would otherwise end with a high surrogate (the first half of a pair).

      Both value and suffix are coerced to strings via asString before processing. Passing null or undefined for value will cause this function to throw, while a null/undefined suffix is treated as an empty string (no suffix is appended).

      Parameters

      • value: string

        The value to truncate. This is coerced to a string and must not be null or undefined.

      • maxLength: number

        The maximum length of the returned value.

      • Optionalsuffix: string

        An optional suffix to append when truncation occurs. When provided, it is coerced to a string; if null or undefined, it is treated as an empty string.

      Returns string

      A truncated string that does not exceed maxLength.

      0.14.0

      TypeError If value is null or undefined.

      strTruncate("hello world", 5); // "hello"
      strTruncate("hello world", 8, "..."); // "hello..."
      strTruncate("short", 10, "..."); // "short"
      strTruncate("important", 3, "..."); // "..."