Skip to content
📐 truncate html by text length
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore initial commit Jan 28, 2016
.travis.yml travis ci Jan 28, 2016 imageAltText option Jul 26, 2016
index.js imageAltText option Jul 26, 2016
license initial commit Jan 28, 2016
package.json insane sanely Jul 26, 2016
test.js insane sanely Jul 26, 2016


Build Status

truncate html by text length


using npm.

npm install -S trunc-html


  • fast, lean, extensible
  • truncate by text length, not html length
  • truncate by complete words, not just by characters

trunc(html, limit, options?)

Returns the result of truncating the provided html. A plain-text version is provided as well.

var html = 'the force is <strong>with this one</strong>. some more rubbish';
trunc(html, 30);
// <-
//    { html: 'the force is <strong>with this one</strong>. …',
//      text: 'the force is with this one. …' }


Maximum amount of text characters allowed. When the limit is reached, the algorithm will trace back to the last word separator and trim the rest into a glyph.


If you'd like to supress certain HTML tags from being output you can provide an array of tags to be excluded, set ignoreTags to something like ['strong'].


If you'd like to use the alt attribute for the text portion of the result, instead of dropping images entirely in text flavor, set imageAltText to true.


Options passed to insane. Note that these options are overridden by the options provided by trunc-html, so you can't use transformText, which trunc-html reserves for itself.




You can’t perform that action at this time.