sheng-tool
    Preparing search index...

    Function truncate

    • 用于对字符串进行截断处理。当超过限定长度(默认是 30),默认添加 3 个点号。

      Parameters

      • target: string

        目标字符串

      • length: number = 30

        限定长度

      • truncation: string = '...'

        省略符

      Returns string

      截断后的字符串;未超过限定长度时返回原字符串。

      0.0.1

      truncate('hello world', 5)                       // 'he...'
      truncate('hello world', 300) // 'hello world'
      truncate('hello world', 8, '--__') // 'hell--__'
      truncate('hello world hello world hello world') // 'hello world hello world hel...'