Function truncate

  • Truncates a string to the specified maximum length

    Since

    vx.x.x

    Returns

    The truncated string.

    Example

    // Truncated to 3 lengths
    console.log(
    truncate('example', 3)
    )
    => 'exa'

    Type Parameters

    • T

    Parameters

    • str: T

      The string to truncate.

    • maxLength: number

      The maximum string length.

    Returns T | string