HTML save string utilities
npm install htmlsave[![NPM version][npm-image]][npm-url] [![Build Status][ci-image]][ci-url] [![BrowserStack Status][browserstack-image]][browserstack-url] [![Dependency Status][depstat-image]][depstat-url] [![Download][dlcounter-image]][dlcounter-url] [![Coverage Status][coveralls-image]][coveralls-url]
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)
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][min] or the [development version][max] directly.
[min]: https://raw.github.com/bezoerb/htmlsave/master/dist/htmlsave.min.js
[max]: https://raw.github.com/bezoerb/htmlsave/master/dist/htmlsave.js
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:
`` lorem ipsum html textjavascript`
var htmlsave = require('htmlsave');
htmlsave.truncate('
breakword: false,
});
`javascript`
define(['htmlsave'], function(htmlsave) {
htmlsave.slice('my extra long html text', 10);
});
`html`
- htmlsave.truncate(input, maxlength, method.htmlsave.slice(input, maxlength,
- method.
#### input
_Required_
Type: string
#### maxlength
_Required_
Type: int
Max characters allowed. Use 0 for slice to split by word.
#### options
##### breakword
Type: booleantrue
Default value:
Allow script to truncate words. Disable to only allow truncating on whitespace,
block-level elements and void elements.
##### ellipsis
Type: String....
Default value:
End truncated string with ellipsis. This option has no effect on slice`.
Copyright (c) 2016 Ben Zörb
Licensed under the MIT license.
[npm-url]: https://npmjs.org/package/htmlsave
[npm-image]: https://img.shields.io/npm/v/htmlsave.svg
[ci-url]: https://github.com/bezoerb/htmlsave/actions?workflow=Tests
[ci-image]: https://github.com/bezoerb/htmlsave/workflows/Tests/badge.svg
[depstat-url]: https://david-dm.org/bezoerb/htmlsave
[depstat-image]: https://david-dm.org/bezoerb/htmlsave.svg
[dlcounter-url]: https://www.npmjs.com/package/htmlsave
[dlcounter-image]: https://img.shields.io/npm/dm/htmlsave.svg
[coveralls-url]: https://coveralls.io/github/bezoerb/htmlsave
[coveralls-image]: https://coveralls.io/repos/github/bezoerb/htmlsave/badge.svg
[browserstack-url]: https://automate.browserstack.com/public-build/MnE3dUptNHZMUVJDQko1WWpnUVZWWEVTeDVHelJkTU5EVll1Zk45QXlYYz0tLWZMYkRjYW43bFJwb1ozZW9FZVl0Umc9PQ==--962f6f1baf7f647bbfc62d97c9a7469ef58e9072
[browserstack-image]: https://automate.browserstack.com/badge.svg?badge_key=MnE3dUptNHZMUVJDQko1WWpnUVZWWEVTeDVHelJkTU5EVll1Zk45QXlYYz0tLWZMYkRjYW43bFJwb1ozZW9FZVl0Umc9PQ==--962f6f1baf7f647bbfc62d97c9a7469ef58e9072