truncate-x

4.1.2 • Public • Published

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

truncate-x

Truncate a string to a maximum specified length.

module.exports(string, [options])string

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 "...".

Kind: Exported function
Returns: string - Returns the truncated string.

Param Type Default Description
string string The string to truncate.
[options] Object The options object.
[options.length] number 30 The maximum string length.
[options.omission] string "'...'" The string to indicate text is omitted.
[options.separator] RegExp | string The separator pattern to truncate to.

Example

import truncate from 'truncate-x';
 
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 [...]'

Package Sidebar

Install

npm i truncate-x

Weekly Downloads

3

Version

4.1.2

License

MIT

Unpacked Size

417 kB

Total Files

11

Last publish

Collaborators

  • xotic750