@pengzhanbo/utils - v3.4.1
    Preparing search index...

    Function truncate

    • Truncates a string to a specified length, adding ellipsis if truncated

      截断字符串到指定长度,如果被截断则添加省略号

      Parameters

      • str: string

        The string to truncate. 要截断的字符串

      • length: number

        The maximum length of the result. 结果的最大长度

      • omission: string = '...'

        The string to use for omission. Default is '...'. 省略符号,默认为 '...'

      Returns string

      The truncated string. 截断后的字符串

      truncate('hello world', 5) // => 'hello...'
      truncate('hello world', 8, '~~') // => 'hello w~~'
      truncate('hi', 10) // => 'hi'