4.1.2 • Published 5 years ago
truncate-x v4.1.2
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 [...]'
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