Options
All
  • Public
  • Public/Protected
  • All
Menu

Module truncate

Index

References

Functions String

References

Renames and re-exports truncate

String Functions

  • truncate(str: ToStringAble, options?: Options): string
  • truncate(str: string, options?: Options): string
  • Truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "...".

    since

    5.6.0

    see

    replace

    example
    truncate('hi-diddly-ho there, neighborino')
    // => 'hi-diddly-ho there, neighbo...'

    truncate('hi-diddly-ho there, neighborino', {
    'length': 24,
    'separator': ' '
    })
    // => 'hi-diddly-ho there,...'

    truncate('hi-diddly-ho there, neighborino', {
    'length': 24,
    'separator': /,? +/
    })
    // => 'hi-diddly-ho there...'

    truncate('hi-diddly-ho there, neighborino', {
    'omission': ' [...]'
    })
    // => 'hi-diddly-ho there, neig [...]'

    Parameters

    • str: ToStringAble

      The string to truncate.

    • Optional options: Options

      The options object.

    Returns string

    Returns the truncated string.

  • Parameters

    • str: string
    • Optional options: Options

    Returns string