str_shorten
Shorten string by character length with word boundary supported
NPM
Install the module with:
npm install --save str_shorten
Yarn
Install the module with:
yarn add str_shorten
Usage
str_shorten(string, maxChars, options)
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. |
Example
Basic
var strShorten = var str = "We will win if we want";var shortenStr = ;
The return value will be "We will win..."
Customize end symbols
var strShorten = var str = "We will win if we want";var shortenStr = ;
The return value will be "We will win -->"
Without end symbols
var strShorten = var str = "We will win if we want";var shortenStr = ;
The return value will be "We will win"
License
Copyright (c) 2018 Binh Quan
Licensed under the MIT license.