codecamp

Lodash _.truncate

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


Lodash _.trimStart
Lodash _.unescape
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }