truncate html text and keep tag safe
npm install html-truncate| Version | Logs |
|:--|:--|
| 1.2.2 | minor bug fixes |
| 1.2.0 | <3 browserify |
| 1.1.0 | bug fixes |
| 1.0.3 | support browser |
| 1.0.0 | deprecated: truncateLastWord. Also, exports function directly |
| 0.3.1 | features done |
``truncateinstall prerequisites and build
library
npm start
API
`javascript
/**
* @static
* @method truncate
* @param {String} string string needs to be truncated
* @param {Number} maxLength length of truncated string
* @param {Object} options (optional)
* @param {Boolean} [options.keepImageTag] flag to specify if keep image tag, false by default
* @param {Boolean|String} [options.ellipsis] omission symbol for truncated string, '...' by default
* @return {String} truncated string
*/
truncate(string, length, options);
`usage
`javascript
var truncate = require('html-truncate');
`$3
`javascript
truncate('hello world', 4)// hell...
``javascript
truncate('hello world', 6)// hello ...
`$3
`javascript
truncate('hello world', 4)//
hell...
`$3
#### non-closed
`javascript
truncate('
Do you think it is useful', 3, { keepImageTag: true })//
Do ...
``javascript
truncate('
Do you think it is useful', 10, { keepImageTag: true })//
Do you thi...
`
#### self-closed
`javascript
truncate('
Do you think it is useful', 3, { keepImageTag: true })
// Do ...
``javascript
truncate('
Do you think it is useful', 10, { keepImageTag: true })
//
Do you thi...
`$3
`javascript
truncate('hello world', 4, { ellipsis: '###' })//
hell###
``javascript
truncate('hello world', 4, { ellipsis: '' })//
hell
``