0.0.2 • Published 7 years ago
node-truncate-string v0.0.2
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
fullWordshould 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&lengthforellipsis. Uselength: 0if you do not want any ellipsis.