4.1.2 • Published 6 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
6 years ago
4.1.1
6 years ago
4.1.0
6 years ago
4.0.12
6 years ago
4.0.11
6 years ago
4.0.10
6 years ago
4.0.9
6 years ago
4.0.8
6 years ago
4.0.7
6 years ago
4.0.6
6 years ago
4.0.5
6 years ago
4.0.4
6 years ago
4.0.3
6 years ago
4.0.2
6 years ago
4.0.1
6 years ago
4.0.0
6 years ago
3.1.1
7 years ago
3.1.0
7 years ago
3.0.0
8 years ago
2.0.0
8 years ago
1.4.0
8 years ago
1.3.0
8 years ago
1.2.0
8 years ago
1.1.0
8 years ago
1.0.0
8 years ago