4.1.2 • Published 7 years ago

truncate-x v4.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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.

ParamTypeDefaultDescription
stringstringThe string to truncate.
optionsObjectThe options object.
options.lengthnumber30The maximum string length.
options.omissionstring"'...'"The string to indicate text is omitted.
options.separatorRegExp | stringThe 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 [...]'
4.1.2

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.12

7 years ago

4.0.11

7 years ago

4.0.10

7 years ago

4.0.9

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.0

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago