Skip to content
HTML save string utilities
JavaScript HTML
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.jshintrc added jasmine env Nov 22, 2013


NPM version Build Status Dependency Status Download

HTML save string utilities for JavaScript.


  • Truncate HTML String while preserving HTML tags and whole words.
  • Split HTML String while preserving HTML tags and whole words.
  • It works with all the standard JavaScript loading systems out of the box (CommonJS, AMD, or just as a global)

Downloading htmlsave

If you're using node, you can run npm install htmlsave.

htmlsave is also available via Bower (bower install htmlsave)

Alternatively if you just want to grab the file yourself, you can download either the current stable production version or the development version directly.

Setting it up

htmlsave supports AMD (e.g. RequireJS), CommonJS (e.g. Node.js) and direct usage (e.g. loading globally with a <script> tag) loading methods. You should be able to do nearly anything, and then skip to the next section anyway and have it work. Just in case though, here's some specific examples that definitely do the right thing:

CommonsJS (e.g. Node)

var htmlsave = require('htmlsave');
htmlsave.truncate("<p>lorem ipsum html text</p>",12,{
    breakword: false

AMD (e.g. RequireJS)

define(['htmlsave'], function(htmlsave) {
   htmlsave.slice("<span>my extra long html text</span>",10);

Directly in your web page:

<script src="htmlsave.min.js"></script>
htmlsave.truncate("another too long text",5);


  • htmlsave.truncate(<string>,<maxlength>,<options>) method.
  • htmlsave.slice(<string>,<maxlength>,<options>) method.


Copyright (c) 2016 Ben Zörb Licensed under the MIT license.

Something went wrong with that request. Please try again.