Skip to main content

truncate

_.truncate(options, string) # Ⓢ [Ⓣ][1] Ⓝ

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. options (Object): The options object.
  2. string (string): The string to truncate.

Returns​

(string): Returns the truncated string.

Example​

_.truncate({}, 'hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there, neighbo...'

_.truncate({
'length': 24,
'separator': ' '
}, 'hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there,...'

_.truncate({
'length': 24,
'separator': /,? +/
}, 'hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there...'

_.truncate({
'omission': ' [...]'
}, 'hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there, neig [...]'