node-truncate-string
v0.0.2
Published
Truncates string with an ellipsis and preserves full word, if needed.
Downloads
3
Maintainers
Readme
node-truncate-string
Truncates string with an ellipsis and preserves full word, if needed.
Usage:
var truncate = require("node-truncate-string");
truncate(string, length, options);
- string: String that needs to be truncated.
- length: Length of the truncated string.
- options: Options to use for truncating.
Options (Default):
{
fullWord: true,
splits: [" ", ",", "."],
ellipsis: {
char: ".",
length: 3
}
}
- fullWord: Whether to preserve full word when truncating. For example:
truncate("fågel, kurre, flickvän, böna", 2)
will returnfågel
. It will returnfå...
iffalse
. - splits: Array list of characters where
fullWord
should be checked. For example:truncate("fågel, kurre, flickvän, böna", 2, {splits: " "})
will returnfågel,...
. But,truncate("fågel, kurre, flickvän, böna", 2, {splits: " ", ","})
will returnfågel...
. - ellipsis:
char
&length
forellipsis
. Uselength: 0
if you do not want any ellipsis.