Optionalstring: stringThe string to truncate.
Optionaloptions: { The options object.
Optionallength?: numberThe maximum string length.
Optionalomission?: stringThe string to indicate text is omitted.
Optionalseparator?: string | RegExpThe separator pattern to truncate to.
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 [...]'
Truncates
stringif 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 "...".