htmlsave

HTML save string utilities

npm install htmlsave
32 downloads in the last month

htmlsave Build Status

HTML save string utilities for JavaScript.

Features

  • 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>
<script>
htmlsave.truncate("another too long text",5);
</script>

Documentation

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

License

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

npm loves you