4.1.2 • Published 5 years ago

truncate-x v4.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 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

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.12

5 years ago

4.0.11

5 years ago

4.0.10

5 years ago

4.0.9

5 years ago

4.0.8

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago