Giter Site home page Giter Site logo

str_shorten's Introduction

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.

str_shorten's People

Contributors

binhgg avatar binhqd avatar mrnav90 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mrnav90

str_shorten's Issues

Remove unused file publish npm

I see many unused file in str_shorten:

  • coverage
  • docs
  • test script, etc..

We just need index.js file(1KB) but str_shorten is big(>5.4MB).

Fix format code and add file config support editor

Need todo:

  1. Format code library
  2. Add some file config support editor
  3. Add global define for eslint config
  4. Update README: How to install package with yarn
  5. Add .nvmrc file config node stable
  6. Use let and arrow function for test script

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.