Truncates a string to a specified length, adding ellipsis if truncated
截断字符串到指定长度,如果被截断则添加省略号
The string to truncate. 要截断的字符串
The maximum length of the result. 结果的最大长度
The string to use for omission. Default is '...'. 省略符号,默认为 '...'
The truncated string. 截断后的字符串
truncate('hello world', 5) // => 'hello...'truncate('hello world', 8, '~~') // => 'hello w~~'truncate('hi', 10) // => 'hi' Copy
truncate('hello world', 5) // => 'hello...'truncate('hello world', 8, '~~') // => 'hello w~~'truncate('hi', 10) // => 'hi'
Truncates a string to a specified length, adding ellipsis if truncated
截断字符串到指定长度,如果被截断则添加省略号