str_shorten

1.0.18 • Public • Published

str_shorten

Build Status bitHound Score Coverage Status bitHound Code npm version Downloads

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 = require("str_shorten")
var str = "We will win if we want";
var shortenStr = strShorten(str, 11);

The return value will be "We will win..."

Customize end symbols

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 -->"

Without end symbols

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"

See Demo

License

Copyright (c) 2018 Binh Quan

Licensed under the MIT license.

Package Sidebar

Install

npm i str_shorten

Weekly Downloads

20

Version

1.0.18

License

MIT

Unpacked Size

5.7 MB

Total Files

35

Last publish

Collaborators

  • binhqd