阅读(790) (0)

Lodash _.truncate

2021-09-23 14:42:37 更新

_.truncate([string=''], [options=])

截断string字符串,如果字符串超出了限定的最大值。 被截断的字符串后面会以 omission 代替,omission 默认是 "..."。

添加版本

4.0.0

参数

  1. [string=''] (string): 要截断的字符串。
  2. [options=] (Object): 选项对象。
  3. [options.length=30] (number): 允许的最大长度。
  4. [options.omission='...'] (string): 超出后的代替字符。
  5. [options.separator] (RegExp|string): 截断点。

返回

(string): Returns the truncated string.

例子

_.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 [...]'