Shorten string by character length with word boundary supported
Install the module with:
npm install --save str_shorten
Install the module with:
yarn add str_shorten
str_shorten(string, maxChars, options)
name | default | required | type | description |
---|---|---|---|---|
wordBoundary | true | false | boolean | Indicate whether using word boundary or not. |
endSymbols | '...' | false | string | Symbols indicate there is more text. |
var strShorten = require("str_shorten")
var str = "We will win if we want";
var shortenStr = strShorten(str, 11);
The return value will be "We will win..."
var strShorten = require("str_shorten")
var str = "We will win if we want";
var shortenStr = strShorten(str, 11, {endSymbols: ' -->'});
The return value will be "We will win -->"
var strShorten = require("str_shorten")
var str = "We will win if we want";
var shortenStr = strShorten(str, 11, {endSymbols: ''});
The return value will be "We will win"
Copyright (c) 2018 Binh Quan
Licensed under the MIT license.