_.truncate

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

Truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "...".

Since

4.0.0

Arguments

  1. [string=''] (string): The string to truncate.
  2. [options={}] (Object): The options object.
  3. [options.length=30] (number): The maximum string length.
  4. [options.omission='...'] (string): The string to indicate text is omitted.
  5. [options.separator] (RegExp|string): The separator pattern to truncate to.

Returns

(string): Returns the truncated string.

Example

_.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 [...]'
doc_Lodash
2016-11-27 16:41:27
Comments
Leave a Comment

Please login to continue.